Skip to content

Commit 559dd00

Browse files
authored
Add MarkdownContent HTML rendering (#253)
1 parent 595a488 commit 559dd00

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Sources/MarkdownUI/DSL/Blocks/MarkdownContent.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,9 @@ public struct MarkdownContent: Equatable, MarkdownContentProtocol {
108108
let result = self.blocks.renderPlainText()
109109
return result.hasSuffix("\n") ? String(result.dropLast()) : result
110110
}
111+
112+
/// Renders this Markdown content value as HTML code.
113+
public func renderHTML() -> String {
114+
self.blocks.renderHTML()
115+
}
111116
}

Sources/MarkdownUI/Parser/MarkdownParser.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ extension Array where Element == BlockNode {
2020
String(cString: cmark_render_plaintext(document, CMARK_OPT_DEFAULT, 0))
2121
} ?? ""
2222
}
23+
24+
func renderHTML() -> String {
25+
UnsafeNode.makeDocument(self) { document in
26+
String(cString: cmark_render_html(document, CMARK_OPT_DEFAULT, nil))
27+
} ?? ""
28+
}
2329
}
2430

2531
extension BlockNode {

0 commit comments

Comments
 (0)