5.4 Parse
| (require punct/parse) | package: punct-lib |
procedure
(parse-markup-elements metas elements #:extract-inline? extract? #:parse-footnotes? parse-fn?) → (or/c document? (listof xexpr?)) metas : hash-eq? elements : list extract? : #t parse-fn? : #f
Parses elements into a Punct AST by serializing everything as strings, sending the string
through the commonmark parser, and then converting the result into a Punct
document, reconstituting any custom elements in the process.
If #:extract-inline? is #true, and if the parsed document contains only a single paragraph element at the root level, then the elements inside the paragraph are returned as a list (the paragraph is "shucked"). Otherwise, the entire result is returned as a document.
The #:parse-footnotes? argument determines whether the commonmark parser will parse Markdown-style footnote references and definitions in elements.
Examples:
> (define elems '("# Title\n\nA paragraph with *italic* text, and " 1 (custom "custom element"))) > (parse-markup-elements (hasheq) elems)
(document
'#hasheq()
'((heading ((level "1")) "Title")
(paragraph
"A paragraph with "
(italic "italic")
" text, and 1"
(custom "custom element")))
'())