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>
This commit is contained in:
spaced4ndyandspacedandy-agents-simplex authored and GitHub committed 2026-11-03 12:33:44 +00:00
1 parent a384d3703b
commit faeabef688
1 file changed
+10 -3
@@ -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: "&lt;", options: .literal)
}
private func withinMarkdownLimits(_ lines: [String]) -> Bool {
var tableRows = 0
var linkNesting = 0