Skip to content

Parse Svelte markup without parsing the script or style tags

License

Notifications You must be signed in to change notification settings

bluwy/svelte-parse-markup

Repository files navigation

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

Sponsors

License

MIT

About

Parse Svelte markup without parsing the script or style tags

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published