Skip to content

Commit

Permalink
🎨 Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed May 26, 2024
1 parent 21c75a6 commit 3123feb
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions Mac/Business/Markdown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ func renderMarkdownHTML(markdown: String) -> String? {
guard let parser = cmark_parser_new(CMARK_OPT_FOOTNOTES) else { return nil }
defer { cmark_parser_free(parser) }

if let ext = cmark_find_syntax_extension("table") {
cmark_parser_attach_syntax_extension(parser, ext)
}

if let ext = cmark_find_syntax_extension("autolink") {
cmark_parser_attach_syntax_extension(parser, ext)
}

if let ext = cmark_find_syntax_extension("strikethrough") {
cmark_parser_attach_syntax_extension(parser, ext)
}

if let ext = cmark_find_syntax_extension("tasklist") {
cmark_parser_attach_syntax_extension(parser, ext)
// 附加常见的 GFM 扩展
let extensions = ["table", "autolink", "emoji", "footnotes", "strikethrough", "tasklist"]
for extName in extensions {
if let ext = cmark_find_syntax_extension(extName) {
cmark_parser_attach_syntax_extension(parser, ext)
}
}

cmark_parser_feed(parser, markdown, markdown.utf8.count)
Expand All @@ -29,5 +21,6 @@ func renderMarkdownHTML(markdown: String) -> String? {
if UserDefaultsManagement.editorLineBreak == "Github" {
res = String(cString: cmark_render_html(node, CMARK_OPT_UNSAFE | CMARK_OPT_NOBREAKS, nil))
}

return res
}

0 comments on commit 3123feb

Please sign in to comment.