svelte-parse-markup
v0.1.5
Published
Parse Svelte markup without parsing the script or style tags
Downloads
75,240
Readme
svelte-parse-markup
Parse Svelte markup without parsing the script or style tags.
Usage
import { parse } from 'svelte-parse-markup'
const ast = parse('some svelte code')
console.log(ast.instance.content.body)
// output:
// [
// {
// type: 'Text',
// start: <num>,
// end: <num>,
// raw: 'instance script content',
// content: 'instance script content'
// }
// ]
console.log(ast.module.content.body)
// output:
// [
// {
// type: 'Text',
// start: <num>,
// end: <num>,
// raw: 'module script content',
// content: 'module script content'
// }
// ]
console.log(ast.css.content.styles)
console.log(ast.css.children)
// output:
// 'css content'
// [
// {
// type: 'Text',
// start: <num>,
// end: <num>,
// raw: 'css content',
// content: 'css content'
// }
// ]
svelte-parse-markup
skips parsing scripts and styles, and injects a Text
node instead. Check out the Svelte REPL AST output tab to compare how the original AST would look like.
Sponsors
License
MIT