Core inline rules

Inline rules for links, media, code spans, HTML, escapes, and emphasis.


InlineCode

InlineCode parses inline code spans.

`code`

Output node is InlineCode, and its AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "inlineCode",
          "value": "code"
        }
      ]
    }
  ]
}

Emphasis

Emphasis parses emphasis and strong emphasis delimiters.

*em* and **strong**

Output nodes are Emphasis and Strong, and their AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "emphasis",
          "children": [
            {
              "type": "text",
              "value": "em"
            }
          ]
        },
        {
          "type": "text",
          "value": " and "
        },
        {
          "type": "strong",
          "children": [
            {
              "type": "text",
              "value": "strong"
            }
          ]
        }
      ]
    }
  ]
}

Image

Image parses inline images and, by default, reference-style images.

![*alt*](/img.png "Title")

Output node is Image, and its AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "image",
          "url": "/img.png",
          "alt": "alt",
          "title": "Title"
        }
      ]
    }
  ]
}

Option example: use Image(references=False) when only inline images should be resolved.

![alt][id]

[id]: /img.png
{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "![alt][id]"
        }
      ]
    },
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "[id]: /img.png"
        }
      ]
    }
  ]
}

RawHtml

RawHtml parses inline HTML tags and comments.

<span>hi</span>

Output node is Html, and its AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "html",
          "value": "<span>"
        },
        {
          "type": "text",
          "value": "hi"
        },
        {
          "type": "html",
          "value": "</span>"
        }
      ]
    }
  ]
}

Option example: use RawHtml(disallowed_tags=["span"]) to escape selected inline tags during parsing.

Use RawHtml(comment_style="gfm") when a custom rule list needs the stricter GFM 0.29 inline HTML comment grammar. The default comment_style="commonmark" matches the CommonMark preset.

<span>hi</span>
{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "html",
          "data": {
            "escaped": true
          },
          "value": "&lt;span>"
        },
        {
          "type": "text",
          "value": "hi"
        },
        {
          "type": "html",
          "data": {
            "escaped": true
          },
          "value": "&lt;/span>"
        }
      ]
    }
  ]
}

BackslashEscape

BackslashEscape parses backslash escapes for escapable punctuation.

\*

Output node is Text, and its AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "*"
        }
      ]
    }
  ]
}

CharacterReference

CharacterReference parses named and numeric character references.

&copy;

Output node is Text, and its AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "©"
        }
      ]
    }
  ]
}

HardBreak

HardBreak parses hard line breaks created with a trailing backslash or two trailing spaces.

line\
break

Output node is Break, and its AST is:

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "line"
        },
        {
          "type": "break"
        },
        {
          "type": "text",
          "value": "break"
        }
      ]
    }
  ]
}