mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-08 07:57:39 +00:00
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:
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: "<", options: .literal)
|
||||
}
|
||||
|
||||
private func withinMarkdownLimits(_ lines: [String]) -> Bool {
|
||||
var tableRows = 0
|
||||
var linkNesting = 0
|
||||
|
||||
Reference in new issue
Block a user