Skip to content

Commit

Permalink
add md support to webview dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
puutaro committed Nov 8, 2023
1 parent 1e35c85 commit 51e0970
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class WebViewJsDialog(
|| urlStrSrc.startsWith(WebUrlVariables.filePrefix)
|| urlStrSrc.startsWith(WebUrlVariables.httpPrefix)
|| urlStrSrc.startsWith(WebUrlVariables.httpsPrefix)
|| urlStrSrc.startsWith(UriPrefix.TEXT_CON.str)
|| urlStrSrc.startsWith(UriPrefix.TEXT_CON.prefix)
) urlStrSrc
else "${WebUrlVariables.queryUrl}${urlStrSrc}"
CoroutineScope(Dispatchers.Main).launch{
Expand Down Expand Up @@ -695,11 +695,12 @@ class WebViewJsDialog(
webView: WebView,
urlCon: String,
){
val textConUriPrefix = UriPrefix.TEXT_CON.str
val textConUriPrefix = UriPrefix.TEXT_CON.prefix
val mdConUriPrefix = UriPrefix.MD_CON.prefix
val trimUrlCon = urlCon.trim()
when(true){
trimUrlCon.startsWith(textConUriPrefix) -> {
val textUrl = "${WebUrlVariables.filePrefix}///textCon.txt"
val textUrl = UriPrefix.TEXT_CON.url
val removePrefixCon = trimUrlCon.removePrefix(textConUriPrefix)
webView.loadDataWithBaseURL(
textUrl,
Expand All @@ -709,6 +710,17 @@ class WebViewJsDialog(
textUrl
)
}
trimUrlCon.startsWith(mdConUriPrefix) -> {
val mdUrl = UriPrefix.MD_CON.url
val removePrefixCon = trimUrlCon.removePrefix(mdConUriPrefix)
webView.loadDataWithBaseURL(
mdUrl,
removePrefixCon,
"text/html",
"utf-8",
mdUrl
)
}
else -> webView.loadUrl(trimUrlCon)
}
}
Expand Down Expand Up @@ -754,7 +766,9 @@ enum class JsMacroType(val str: String,) {
}

private enum class UriPrefix(
val str: String
val prefix: String,
val url: String,
) {
TEXT_CON("textCon://")
TEXT_CON("textCon://", "${WebUrlVariables.filePrefix}///textCon.txt"),
MD_CON("mdCon://", "${WebUrlVariables.filePrefix}///descMd.txt"),
}

0 comments on commit 51e0970

Please sign in to comment.