myst_parser.parsers.options
#
Parser for directive options.
This is a highly restricted parser for YAML, which only allows a subset of YAML to be used for directive options:
Only block mappings are allowed at the top level
Mapping keys are parsed as strings (plain or quoted)
Mapping values are parsed as strings (plain, quoted, literal |, folded >)
# Comments are allowed and blank lines
Adapted from: yaml/pyyaml
For a good description of multi-line YAML strings, see: https://stackoverflow.com/a/21699210/5033292
1. Module Contents#
1.1. Classes#
Position of a character in a stream. |
|
A buffer for a stream of characters. |
|
A parsed token from a directive option stream. |
|
1.2. Functions#
Parse a directive option block into (key, value) tuples. |
1.3. API#
- class myst_parser.parsers.options.StreamBuffer(stream: str)[源代码]#
A buffer for a stream of characters.
Initialization
- get_position() myst_parser.parsers.options.Position [源代码]#
- class myst_parser.parsers.options.Token[源代码]#
A parsed token from a directive option stream.
- start: myst_parser.parsers.options.Position = None#
- end: myst_parser.parsers.options.Position = None#
- class myst_parser.parsers.options.KeyToken[源代码]#
Bases:
myst_parser.parsers.options.Token
- style: Literal[None, ', "] = None#
The original style of the string.
- class myst_parser.parsers.options.ValueToken[源代码]#
Bases:
myst_parser.parsers.options.Token
- style: Literal[None, ', ", |, >] = None#
The original style of the string.
- exception myst_parser.parsers.options.TokenizeError(problem: str, problem_mark: myst_parser.parsers.options.Position, context: str | None = None, context_mark: myst_parser.parsers.options.Position | None = None)[源代码]#
Bases:
Exception
- clone(line_offset: int, column_offset: int) myst_parser.parsers.options.TokenizeError [源代码]#
Clone the error with the given line and column offsets.
- myst_parser.parsers.options.options_to_items(text: str, line_offset: int = 0, column_offset: int = 0) tuple[list[tuple[str, str]], myst_parser.parsers.options.State] [源代码]#
Parse a directive option block into (key, value) tuples.
- 参数:
text -- The directive option text.
line_offset -- The line offset to apply to the error positions.
column_offset -- The column offset to apply to the error positions.
- Raises:
TokenizeError