Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/bluwy/svelte-parse-markup
- Owner: bluwy
- License: mit
- Created: 2022-10-02T12:49:35.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-04T07:50:44.000Z (5 months ago)
- Last Synced: 2024-10-24T14:28:56.473Z (15 days ago)
- Topics: parse, svelte
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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
## License
MIT