Writing Custom Parser Plugins¶
A doc2dash parser plugin has three jobs:
- Detect whether it can parse a directory and extract an appropriate name for the docset.
- Parse a directory and tell doc2dash about all entries that should be indexed.
- Patch files such that Dash can generate per-file tables of contents.
For that, it must implement the Parser protocol:
Parser¶
Bases: Protocol
A doc2dash documentation parser.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of this parser. Used in user-facing output. |
detect(path)
staticmethod
¶
__init__(source)
¶
Initialize parser.
If this parser’s detect() static method indicates that source
belongs to it, doc2dash instantiates it as parser_type(path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path
|
The path to the documentation that will be parsed. |
required |
parse()
¶
Parse the path that this parser was initialized with and yield a
ParserEntry for each
entry it finds.
Returns:
| Type | Description |
|---|---|
None
|
A generator that yields |
Patcher¶
ParserEntry¶
EntryType¶
To use your custom parser, you have to invoke doc2dash with the --parser option and specify the importable path to it.
Example¶
Often, it’s the easiest to get started by looking at existing parsers. Conveniently, doc2dash ships one:
The intersphinx parser uses a machine-readable format to extract the necessary metadata.