Browse Source

Fix ascii shrug guy

Changelog-Fixed: Fix ascii shrug guy
Closes: #238
post-button-style
Lionello Lunesu 2 years ago
committed by William Casarin
parent
commit
e9380c3821
  1. 5
      damus/Util/Markdown.swift
  2. 2
      damus/Views/NoteContentView.swift
  3. 10
      damusTests/MarkdownTests.swift

5
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)
}
}

2
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)
}

10
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")
}
}

Loading…
Cancel
Save