Skip to content

Commit

Permalink
Add MarkdownContent HTML rendering (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
srna authored Sep 10, 2023
1 parent 595a488 commit 559dd00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/MarkdownUI/DSL/Blocks/MarkdownContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ public struct MarkdownContent: Equatable, MarkdownContentProtocol {
let result = self.blocks.renderPlainText()
return result.hasSuffix("\n") ? String(result.dropLast()) : result
}

/// Renders this Markdown content value as HTML code.
public func renderHTML() -> String {
self.blocks.renderHTML()
}
}
6 changes: 6 additions & 0 deletions Sources/MarkdownUI/Parser/MarkdownParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ extension Array where Element == BlockNode {
String(cString: cmark_render_plaintext(document, CMARK_OPT_DEFAULT, 0))
} ?? ""
}

func renderHTML() -> String {
UnsafeNode.makeDocument(self) { document in
String(cString: cmark_render_html(document, CMARK_OPT_DEFAULT, nil))
} ?? ""
}
}

extension BlockNode {
Expand Down

0 comments on commit 559dd00

Please sign in to comment.