Documentation

MD4Lean

md4lean #

a Lean wrapper for the MD4C Markdown parser

Parser flags #

The default behavior is to recognize only Markdown syntax defined by the CommonMark specification.

However, with appropriate flags, the behavior can be tuned to enable some extensions.

With the flag MD_FLAG_COLLAPSEWHITESPACE, a non-trivial whitespace is collapsed into a single space.

Equations
Instances For

    Do not require space in ATX headers ( ###header )

    Equations
    Instances For

      Disable indented code blocks. (Only fenced code works.)

      Equations
      Instances For

        Disable raw HTML blocks.

        Equations
        Instances For

          Disable raw HTML (inline).

          Equations
          Instances For

            With the flag MD_FLAG_TABLES, GitHub-style tables are supported.

            Equations
            Instances For

              With the flag MD_FLAG_STRIKETHROUGH, strike-through spans are enabled (text enclosed in tilde marks, e.g. ~foo bar~).

              Equations
              Instances For

                With the flag MD_FLAG_TASKLISTS, GitHub-style task lists are supported.

                Equations
                Instances For

                  With the flag MD_FLAG_LATEXMATHSPANS LaTeX math spans ($...$) and LaTeX display math spans ($$...$$) are supported. (Note though that the HTML renderer outputs them verbatim in a custom tag <x-equation>.)

                  Equations
                  Instances For

                    With the flag MD_FLAG_UNDERLINE, underscore (_) denotes an underline instead of an ordinary emphasis or strong emphasis.

                    Equations
                    Instances For

                      Force all soft breaks to act as hard breaks.

                      Equations
                      Instances For

                        Convenient sets of flags corresponding to well-known Markdown dialects.

                        Note we may only support subset of features of the referred dialect. The constant just enables those extensions which bring us as close as possible given what features we implement.

                        ABI compatibility note: Meaning of these can change in time as new extensions, bringing the dialect closer to the original, are implemented.

                        The CommonMark dialect.

                        Equations
                        Instances For

                          HTML renderer flags #

                          If set, debug output is sent to stderr.

                          Equations
                          Instances For

                            If set, output the entity verbatim, otherwise translate entity to its UTF-8 equivalent.

                            Equations
                            Instances For

                              Skip UTF-8 byte order mark (BOM) in the input string.

                              Equations
                              Instances For

                                Output XHTML (e.g. <br />) instead of HTML (e.g. <br>).

                                Equations
                                Instances For

                                  Output \( and \) (which are accepted by MathJax) instead of <x-equation> for LaTeX math spans.

                                  Equations
                                  Instances For

                                    Output $ (which are accepted by MathJax) instead of <x-equation> for LaTeX math spans. Must be used with MD_HTML_FLAG_MATHJAX, otherwise it is ignored.

                                    Equations
                                    Instances For

                                      AST #

                                      The text that can occur in attributes such as link destinations, image sources, and titles

                                      • normal : StringAttrText

                                        Normal text

                                      • entity : StringAttrText

                                        An HTML entity as a complete string, e.g. "&nbsp;".

                                        No validation is performed, anything that's syntactically an entity uses this constructor.

                                      • nullchar : AttrText

                                        A null character

                                      Instances For
                                        Equations
                                        Instances For
                                          inductive MD4Lean.Text :

                                          Inline elements (sometimes called spans or inlines)

                                          Instances For
                                            structure MD4Lean.Li (α : Type u_1) :
                                            Type u_1

                                            A list item

                                            Instances For
                                              def MD4Lean.instInhabitedLi.default {a✝ : Type u_1} :
                                              Li a✝
                                              Equations
                                              Instances For
                                                def MD4Lean.instReprLi.repr {α✝ : Type u_1} [Repr α✝] :
                                                Li α✝NatStd.Format
                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  instance MD4Lean.instReprLi {α✝ : Type u_1} [Repr α✝] :
                                                  Repr (Li α✝)
                                                  Equations
                                                  def MD4Lean.instBEqLi.beq {α✝ : Type u_1} [BEq α✝] :
                                                  Li α✝Li α✝Bool
                                                  Equations
                                                  Instances For
                                                    instance MD4Lean.instBEqLi {α✝ : Type u_1} [BEq α✝] :
                                                    BEq (Li α✝)
                                                    Equations
                                                    inductive MD4Lean.Block :

                                                    A block-level element

                                                    Instances For

                                                      A document

                                                      • blocks : Array Block

                                                        The block-level elements of the document

                                                      Instances For
                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For
                                                          Equations
                                                          Instances For

                                                            Functions #

                                                            @[extern lean_md4c_markdown_to_html]

                                                            Render Markdown into HTML.

                                                            Note only contents of <body> tag is generated. Caller must generate HTML header/footer manually before/after calling this function.

                                                            • input is the input markdown string.
                                                            • parserFlags is bitmask of MD_FLAG_xxxx.
                                                            • rendererFlags is bitmask of MD_HTML_FLAG_xxxx.

                                                            Return Option.some s if render is successful, otherwise return Option.none.

                                                            @[extern lean_md4c_markdown_parse]
                                                            opaque MD4Lean.parse (input : String) (parserFlags : UInt32 := MD_DIALECT_COMMONMARK) :

                                                            Parses Markdown into an AST.

                                                            • input is the input markdown string.
                                                            • parserFlags is bitmask of MD_FLAG_xxxx.

                                                            Returns some if the underlying md4c parser succeeds, or none if it fails.