mirror of
git://jb55.com/damus
synced 2024-10-06 11:43:21 +00:00
parent
39fa973a80
commit
e9380c3821
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user