Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Nov 19, 2024
1 parent e46253b commit b82cb1c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/template-parser/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# @html-eslint/template-parser

A parser that parses the html written inside a template literal.

## Usage

```js
const { parse } = require("@html-eslint/template-parser");
const espree = require("espree");
const { SourceCode } = require("eslint");

const code = `html\`<div
id="\${ id }">
\${text}
</div>\`;`;

const ast = espree.parse(code, {
range: true,
loc: true,
ecmaVersion: "latest",
});
const sourceCode = new SourceCode({
text: code,
ast: {
...ast,
tokens: [],
comments: ast.comments ?? [],
loc: ast.loc,
range: ast.range,
},
});

const exp = ast.body[0].expression.quasi;
parse(exp, sourcecode, {
Tag(node) {
// ...
},
AttributeValue(node) {
// ...
},
});
```

## License

Distributed under the MIT License.

0 comments on commit b82cb1c

Please sign in to comment.