Skip to content

Commit bf260fc

Browse files
committed
use nim to generate html
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent 8b218d5 commit bf260fc

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/marvdown/parser.nim

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,28 +815,44 @@ proc renderNode(md: var Markdown, node: MarkdownNode): string =
815815
("<", "&lt;"), (">", "&gt;"),
816816
("\"", "&quot;"), ("&", "&amp;")
817817
)
818-
let classAttr = if node.codeLang.len > 0: " class=\"language-" & node.codeLang & "\"" else: ""
819-
result.add("<pre><code" & classAttr & ">" & codeBlock.strip() & "</code></pre>")
818+
result.add(
819+
pre(
820+
code(
821+
`class`=if node.codeLang.len > 0: "language-" & node.codeLang else: "",
822+
codeBlock.strip()
823+
)
824+
)
825+
)
820826
of mdkInlineCode:
821827
let inlineCode = node.inlineCode.multiReplace(
822828
("<", "&lt;"), (">", "&gt;"),
823829
("\"", "&quot;"), ("&", "&amp;")
824830
)
825-
result = "<code>" & inlineCode & "</code>"
831+
result = code(inlineCode)
826832
of mdkBlockquote:
827833
var bqContent = ""
828834
for child in node.children.items:
829835
bqContent.add(md.renderNode(child))
830-
result = "<blockquote>" & bqContent & "</blockquote>"
836+
result = blockquote(bqContent)
831837
of mdkFootnoteRef:
832838
# Footnote reference rendering
833-
result = "<sup class=\"footnote-ref\"><a href=\"#fn-" & node.footnoteRefId & "\">" & node.footnoteRefId & "</a></sup>"
839+
result = sup(
840+
`class`="footnote-ref",
841+
a(href="#fn-" & node.footnoteRefId, node.footnoteRefId)
842+
)
834843
of mdkFootnoteDef:
835844
# Footnote definition rendering (could be customized)
836845
var fnContent = ""
837846
for child in node.children.items:
838847
fnContent.add(md.renderNode(child))
839-
md.footnotesHtml.add("<div class=\"footnote\" id=\"fn-" & node.footnoteId & "\">" &
840-
"<sup>" & node.footnoteId & "</sup> " & fnContent & "</div>")
848+
md.footnotesHtml.add(
849+
`div`(
850+
`class`="footnote",
851+
id="fn-" & node.footnoteId,
852+
sup(node.footnoteId),
853+
" ",
854+
fnContent
855+
)
856+
)
841857
else:
842858
discard

0 commit comments

Comments
 (0)