Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bluwy/svelte-parse-markup

Parse Svelte markup without parsing the script or style tags
https://github.com/bluwy/svelte-parse-markup

parse svelte

Last synced: 6 days ago
JSON representation

Parse Svelte markup without parsing the script or style tags

Awesome Lists containing this project

README

        

# svelte-parse-markup

Parse Svelte markup without parsing the script or style tags.

## Usage

```js
import { parse } from 'svelte-parse-markup'

const ast = parse('some svelte code')

console.log(ast.instance.content.body)
// output:
// [
// {
// type: 'Text',
// start: ,
// end: ,
// raw: 'instance script content',
// content: 'instance script content'
// }
// ]

console.log(ast.module.content.body)
// output:
// [
// {
// type: 'Text',
// start: ,
// end: ,
// 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: ,
// end: ,
// 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](https://svelte.dev/repl) AST output tab to compare how the original AST would look like.

## Sponsors



Sponsors

## License

MIT