Skip to main content

Module attributes

Module attributes 

Source
Expand description

Parsing for Pandoc-style attributes: {#id .class key=value}

Attributes can appear after headings, fenced code blocks, fenced divs, etc. Syntax: {#identifier .class1 .class2 key1=val1 key2=“val2”}

Rules:

  • Surrounded by { }
  • Identifier: #id (optional, only first one counts)
  • Classes: .class (can have multiple)
  • Key-value pairs: key=value or key=“value” or key=‘value’ (can have multiple)
  • Whitespace flexible between items

Structs§

AttributeBlock

Functions§

emit_attributes
Emit attribute block as AST nodes
parse_attribute_content
Parse the content inside the attribute braces
parse_html_attribute_list
Parse a raw HTML attribute list (the bytes between a tag name and the closing >, exclusive). Accepts inputs like id="x" class="a b" data-key=v and produces an AttributeBlock. Returns None if no recognized attributes are present.
parse_html_tag_attributes
Parse HTML-style attributes from a raw HTML opening tag text such as <div id="x" class="a b" data-key="v">, returning the same AttributeBlock shape as Pandoc-style brace attributes. Whitespace- separated class="..." is split into individual classes; id="..." becomes the identifier; everything else becomes a key/value pair. Returns None if the tag has no recognized attributes.
try_parse_trailing_attributes
Try to parse an attribute block from the end of a string Returns: (attribute_block, text_before_attributes)
try_parse_trailing_attributes_with_pos
Try to parse an attribute block from the end of a string. Returns: (attribute_block, text_before_attributes, open_brace_position_in_trimmed_text)