The post-parser directory is intended for use transforming HTML with plain text tokens embedded in it to HTML.
It is the third stage of the transformation from a document type (e.g. Textile) to a documentation page.
- Pre-parser - transforms plain text to plain text ready to be parsed.
- Parser enhancements - transforms data with enhancements from
attributes
and documentpath
. - HTML Parser - for HTML manipulations that are too complex for string manipulation or the front-end.
- Component mapping - maps
{ data, type }
objects to React components based ontype
. - React components - standardise the behaviour, presentation, layout and markup semantics of
data
from{ data, type }
objects.
It is a good place to put:
- Operations that cannot take place before the parser runs, for example:
- Operations that rely on text that would be interpreted by the parser as meaningful syntax
- Operations that depend on the specific operations in the pre-parsing stage, such as regex operations on whitespace
- Operations that depend on some HTML to already be present, but cannot be processed through the htmlParser/Cheerio, such as operations on plain text that is not wrapped in HTML but contains some HTML markup.
It is not the best place to put:
- Operations that remove information for developers only - consider putting these in pre-parser, so there's less text to process later on, and parsing the more complex HTML structure is a little easier.
- Transformations based on frontmatter variables; the frontmatter is extracted after the pre-parser phase, as are partials; partials should inherit frontmatter variables (such as published_date) from their 'parent' page. Consider putting these in parser-enhancements, so that the variables we use are consistently applied & easier to access.
- Final transformations before rendering; consider putting these actions in React components.