From 8c43bc8a44ed87e42eaff1e6514e7f276d4a3505 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 17 Jun 2021 22:35:50 -0400 Subject: [PATCH] Fix plain text responses not being visible in dark mode --- Gemini-iOS/BrowserWebViewController.swift | 17 ++++++++++++----- Gemini-iOS/Resources/browser.css | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Gemini-iOS/BrowserWebViewController.swift b/Gemini-iOS/BrowserWebViewController.swift index 6517959..6fa8dfb 100644 --- a/Gemini-iOS/BrowserWebViewController.swift +++ b/Gemini-iOS/BrowserWebViewController.swift @@ -258,11 +258,18 @@ class BrowserWebViewController: UIViewController { self.loadedFallback = true - 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 + if mimeType == "text/plain", + let bodyText = response.bodyText { + let html = BrowserWebViewController.preamble + "
" + bodyText + "
" + BrowserWebViewController.postamble + self.webView.loadHTMLString(html, baseURL: Bundle.main.bundleURL) + } 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 + } } } diff --git a/Gemini-iOS/Resources/browser.css b/Gemini-iOS/Resources/browser.css index c57fbcd..71f637a 100644 --- a/Gemini-iOS/Resources/browser.css +++ b/Gemini-iOS/Resources/browser.css @@ -14,6 +14,11 @@ pre { tab-size: 4; } +pre.plaintext { + word-wrap: break-word; + white-space: pre-wrap; +} + h1, h2, h3 { line-height: 1; font-weight: normal;