• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

History.mdD24-Sep-20231.5 KiB6743

LICENSED24-Sep-20231 KiB1916

README.mdD24-Sep-20232.2 KiB7455

index.jsD24-Sep-202340.7 KiB1,5211,099

package.jsonD24-Sep-2023589 2726

README.md

1# pug-lexer
2
3The pug lexer.  This module is responsible for taking a string and converting it into an array of tokens.
4
5[![Build Status](https://img.shields.io/travis/pugjs/pug-lexer/master.svg)](https://travis-ci.org/pugjs/pug-lexer)
6[![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-lexer)](https://david-dm.org/pugjs/pug?path=packages/pug-lexer)
7[![DevDependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-lexer)](https://david-dm.org/pugjs/pug?path=packages/pug-lexer&type=dev)
8[![NPM version](https://img.shields.io/npm/v/pug-lexer.svg)](https://www.npmjs.org/package/pug-lexer)
9[![Coverage Status](https://img.shields.io/codecov/c/github/pugjs/pug-lexer.svg)](https://codecov.io/gh/pugjs/pug-lexer)
10
11## Installation
12
13    npm install pug-lexer
14
15## Usage
16
17```js
18var lex = require('pug-lexer');
19```
20
21### `lex(str, options)`
22
23Convert Pug string to an array of tokens.
24
25`options` can contain the following properties:
26
27- `filename` (string): The name of the Pug file; it is used in error handling if provided.
28- `plugins` (array): An array of plugins, in the order they should be applied.
29
30```js
31console.log(JSON.stringify(lex('div(data-foo="bar")', {filename: 'my-file.pug'}), null, '  '))
32```
33
34```json
35[
36  {
37    "type": "tag",
38    "line": 1,
39    "val": "div",
40    "selfClosing": false
41  },
42  {
43    "type": "attrs",
44    "line": 1,
45    "attrs": [
46      {
47        "name": "data-foo",
48        "val": "\"bar\"",
49        "escaped": true
50      }
51    ]
52  },
53  {
54    "type": "eos",
55    "line": 1
56  }
57]
58```
59
60### `new lex.Lexer(str, options)`
61
62Constructor for a Lexer class. This is not meant to be used directly unless you know what you are doing.
63
64`options` may contain the following properties:
65
66- `filename` (string): The name of the Pug file; it is used in error handling if provided.
67- `interpolated` (boolean): if the Lexer is created as a child lexer for inline tag interpolation (e.g. `#[p Hello]`). Defaults to `false`.
68- `startingLine` (integer): the real line number of the first line in the input. It is also used for inline tag interpolation. Defaults to `1`.
69- `plugins` (array): An array of plugins, in the order they should be applied.
70
71## License
72
73  MIT
74