What is pug-linker?
The pug-linker npm package is a part of the Pug templating engine ecosystem. It is used internally by Pug to link together the abstract syntax tree (AST) nodes generated by the Pug parser. This linking process is essential for transforming the parsed Pug code into a format that can be compiled into HTML.
What are pug-linker's main functionalities?
Linking AST Nodes
This feature allows you to link the AST nodes generated by the Pug parser. The `pugLinker` function takes an AST as input and returns a linked AST, which is ready for further compilation into HTML.
const pugLinker = require('pug-linker');
const ast = /* some AST generated by pug-parser */;
const linkedAst = pugLinker(ast);
Other packages similar to pug-linker
pug-parser
The pug-parser package is responsible for parsing Pug templates into an abstract syntax tree (AST). While pug-linker focuses on linking these AST nodes, pug-parser is the initial step in the process, converting raw Pug code into a structured format.
pug-lexer
The pug-lexer package is used to tokenize Pug templates, breaking them down into a series of tokens that can be parsed into an AST. It works in conjunction with pug-parser and pug-linker to transform Pug code into HTML.
pug-code-gen
The pug-code-gen package takes a linked AST and generates JavaScript code that can render HTML. It is the final step in the Pug compilation process, following the linking of AST nodes by pug-linker.
pug-linker
Link multiple pug ASTs together using include/extends
Installation
npm install pug-linker
Usage
var link = require('pug-linker');
link(ast)
Flatten the Pug AST of inclusion and inheritance.
This function merely links the AST together; it doesn't read the file system to resolve and parse included and extended files. Thus, the main AST must already have the ASTs of the included and extended files embedded in the FileReference
nodes. pug-load
is designed to do that.
License
MIT