[][src]Type Definition cmark_gfm_sys::cmark_inline_parser

type cmark_inline_parser = subject;

A syntax extension that can be attached to a cmark_parser with cmark_parser_attach_syntax_extension().

Extension writers should assign functions matching the signature of the following 'virtual methods' to implement new functionality.

Their calling order and expected behaviour match the procedure outlined at http://spec.commonmark.org/0.24/#phase-1-block-structure:

During step 1, cmark will call the function provided through 'cmark_syntax_extension_set_match_block_func' when it iterates over an open block created by this extension, to determine whether it could contain the new line. If no function was provided, cmark will close the block.

During step 2, if and only if the new line doesn't match any of the standard syntax rules, cmark will call the function provided through 'cmark_syntax_extension_set_open_block_func' to let the extension determine whether that new line matches one of its syntax rules. It is the responsibility of the parser to create and add the new block with cmark_parser_make_block and cmark_parser_add_child. If no function was provided is NULL, the extension will have no effect at all on the final block structure of the AST.

Inline parsing phase hooks

For each character provided by the extension through 'cmark_syntax_extension_set_special_inline_chars', the function provided by the extension through 'cmark_syntax_extension_set_match_inline_func' will get called, it is the responsibility of the extension to scan the characters located at the current inline parsing offset with the cmark_inline_parser API.

Depending on the type of the extension, it can either:

  • Scan forward, determine that the syntax matches and return a newly-created inline node with the appropriate type. This is the technique that would be used if inline code (with backticks) was implemented as an extension.
  • Scan only the character(s) that its syntax rules require for opening and closing nodes, push a delimiter on the delimiter stack, and return a simple text node with its contents set to the character(s) consumed. This is the technique that would be used if emphasis inlines were implemented as an extension.

When an extension has pushed delimiters on the stack, the function provided through 'cmark_syntax_extension_set_inline_from_delim_func' will get called in a latter phase, when the inline parser has matched opener and closer delimiters created by the extension together.

It is then the responsibility of the extension to modify and populate the opener inline text node, and to remove the necessary delimiters from the delimiter stack.

Finally, the extension should return NULL if its scan didn't match its syntax rules.

The extension can store whatever private data it might need with 'cmark_syntax_extension_set_private', and optionally define a free function for this data.