commit e9380c3821fe9d3c5b05df2fb02e577b4f5cc9ab
parent 39fa973a8026e896e2cd904ffc73a2a0849409c3
Author: Lionello Lunesu <lio+git@lunesu.com>
Date: Tue, 3 Jan 2023 23:05:41 -0800
Fix ascii shrug guy
Changelog-Fixed: Fix ascii shrug guy
Closes: #238
Diffstat:
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/damus/Util/Markdown.swift b/damus/Util/Markdown.swift
@@ -20,7 +20,9 @@ public struct Markdown {
let md_opts: AttributedString.MarkdownParsingOptions =
.init(interpretedSyntax: .inlineOnlyPreservingWhitespace)
- if let txt = try? AttributedString(markdown: content, options: md_opts) {
+ // TODO: escape unintentional markdown
+ let escaped = content.replacingOccurrences(of: "\\_", with: "\\\\\\_")
+ if let txt = try? AttributedString(markdown: escaped, options: md_opts) {
return txt
} else {
return AttributedString(stringLiteral: content)
@@ -40,7 +42,6 @@ public struct Markdown {
let uri = url.scheme == "http" ? Markdown.withScheme(text) : url.absoluteString
output.replaceSubrange(range, with: "[\(text)](\(uri))")
}
- // TODO: escape unintentional markdown
return Markdown.parse(content: output)
}
}
diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift
@@ -183,7 +183,7 @@ func mention_str(_ m: Mention, profiles: Profiles) -> String {
struct NoteContentView_Previews: PreviewProvider {
static var previews: some View {
let state = test_damus_state()
- let content = "hi there https://jb55.com/s/Oct12-150217.png 5739a762ef6124dd.jpg"
+ let content = "hi there ¯\\_(ツ)_/¯ https://jb55.com/s/Oct12-150217.png 5739a762ef6124dd.jpg"
let artifacts = NoteArtifacts(content: content, images: [], invoices: [], links: [])
NoteContentView(privkey: "", event: NostrEvent(content: content, pubkey: "pk"), profiles: state.profiles, previews: PreviewCache(), show_images: true, artifacts: artifacts, size: .normal)
}
diff --git a/damusTests/MarkdownTests.swift b/damusTests/MarkdownTests.swift
@@ -62,4 +62,14 @@ class MarkdownTests: XCTestCase {
XCTAssertEqual(md, expected)
}
+ func test_parse_shrug() throws {
+ let md = Markdown.parse(content: "¯\\_(ツ)_/¯")
+ XCTAssertEqual(NSMutableAttributedString(md).string, "¯\\_(ツ)_/¯")
+ }
+
+ func test_parse_backslash() throws {
+ let md = Markdown.parse(content: "\\a")
+ XCTAssertEqual(NSMutableAttributedString(md).string, "\\a")
+ }
+
}