svelte-parse-markup
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

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

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i svelte-parse-markup

    Weekly Downloads

    15,969

    Version

    0.1.5

    License

    MIT

    Unpacked Size

    8 kB

    Total Files

    5

    Last publish

    Collaborators

    • bluwy