Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 2 KB

README.md

File metadata and controls

26 lines (19 loc) · 2 KB

Post-Parser

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.

Compare

  1. Pre-parser - transforms plain text to plain text ready to be parsed.
  2. Parser enhancements - transforms data with enhancements from attributes and document path.
  3. HTML Parser - for HTML manipulations that are too complex for string manipulation or the front-end.
  4. Component mapping - maps { data, type } objects to React components based on type.
  5. React components - standardise the behaviour, presentation, layout and markup semantics of data from { data, type } objects.

Usage

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.