Fix plain text responses not being visible in dark mode

This commit is contained in:
Shadowfacts 2021-06-17 22:35:50 -04:00
parent de68ecbe4b
commit 8c43bc8a44
2 changed files with 17 additions and 5 deletions

View File

@ -258,11 +258,18 @@ class BrowserWebViewController: UIViewController {
self.loadedFallback = true self.loadedFallback = true
self.webView.load(body, mimeType: mimeType, characterEncodingName: response.encodingName ?? "utf-8", baseURL: self.url) if mimeType == "text/plain",
// When showing an image, the safe area insets seem to be ignored. This isn't perfect let bodyText = response.bodyText {
// (there's a little extra space between the bottom of the nav bar and the top of the image), let html = BrowserWebViewController.preamble + "<pre class='plaintext'>" + bodyText + "</pre>" + BrowserWebViewController.postamble
// but it's better than the image being obscured. self.webView.loadHTMLString(html, baseURL: Bundle.main.bundleURL)
self.webView.scrollView.contentInset = self.webView.safeAreaInsets } else {
self.webView.load(body, mimeType: mimeType, characterEncodingName: response.encodingName ?? "utf-8", baseURL: self.url)
// When showing an image, the safe area insets seem to be ignored. This isn't perfect
// (there's a little extra space between the bottom of the nav bar and the top of the image),
// but it's better than the image being obscured.
self.webView.scrollView.contentInset = self.webView.safeAreaInsets
}
} }
} }

View File

@ -14,6 +14,11 @@ pre {
tab-size: 4; tab-size: 4;
} }
pre.plaintext {
word-wrap: break-word;
white-space: pre-wrap;
}
h1, h2, h3 { h1, h2, h3 {
line-height: 1; line-height: 1;
font-weight: normal; font-weight: normal;