Custom Parsers

Source   Edit  

Custom Parsers

Extending the Parser

ndgBook uses the Nim compiler's RST/Markdown parser, which can be extended with custom directives. To add a custom directive:

  1. Define the directive handler in a Nim module
  2. Register it with the RST parser's directive table
  3. Compile your extension into the Nim compiler

Example custom directive handler:

import packages/docutils/rst

proc dirMyCustom(p: var RstParser): PRstNode =
  result = parseDirective(p, rnDirective, {hasArg},
                          parseSectionWrapper)

# Register during initialization
rst.customDirectives["my-custom"] = dirMyCustom

Warning: Custom parsers modify the compiler's behavior globally. Test thoroughly before deploying to production documentation.