From faeabef688289a76dc68466e6ab732972bbccfc4 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Tue, 3 Nov 2026 12:33:44 +0000 Subject: [PATCH] ios: show markdown files with HTML tags formatted to the end (#8008) * ios: show markdown files with HTML tags formatted to the end * ios: show every < in a markdown file as text --------- Co-authored-by: spacedandy-agents-simplex <342056592+spacedandy-agents-simplex@users.noreply.github.com> --- .../Views/Chat/ChatItem/MarkdownFileView.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift b/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift index 8c180c31e6..555ff9d429 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift @@ -22,9 +22,7 @@ func showMarkdownFile(_ file: CIFile) { let data = try getFileData(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs) let text = decodedText(data) let lines = text.components(separatedBy: "\n") - let html = withinMarkdownLimits(lines) - ? MarkdownParser(modifiers: [Modifier(target: .html) { escapedHTML($0.markdown) }, imagesWithinBudget()]).html(from: text) - : nil + let html = withinMarkdownLimits(lines) ? htmlShowingTagsAsText(text) : nil let shownLines = lines.flatMap(chunkedLine) let hasBidiControls = text.unicodeScalars.contains(where: isBidiControl) await MainActor.run { @@ -57,6 +55,15 @@ private func replacingControlChar(_ s: Unicode.Scalar) -> Unicode.Scalar { s.value < 0x20 && s != "\t" && s != "\n" && s != "\r" ? "?" : s } +// decodedText replaces control characters, so the text has no U+0001 of its own +private let lessThanStandIn = "\u{1}" + +private func htmlShowingTagsAsText(_ text: String) -> String { + MarkdownParser(modifiers: [imagesWithinBudget()]) + .html(from: text.replacingOccurrences(of: "<", with: lessThanStandIn, options: .literal)) + .replacingOccurrences(of: lessThanStandIn, with: "<", options: .literal) +} + private func withinMarkdownLimits(_ lines: [String]) -> Bool { var tableRows = 0 var linkNesting = 0