0.5.1 • Published 4 months ago

@syntastica/core v0.5.1

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
4 months ago

syntastica-js

Modern and easy syntax highlighting using tree-sitter; use syntastica from JavaScript/TypeScript.

The full JavaScript/TypeScript API docs can be found here.

Basic Usage

import syntastica from '@syntastica/core'

// initialize the module
await syntastica.init()

// load some languages
await syntastica.loadLanguage('node_modules/@syntastica/lang-rust/rust.wasm')
await syntastica.loadLanguage(
    'node_modules/@syntastica/lang-javascript/javascript.wasm',
)

// highlight a piece of code once
const rustInput = `fn main() {\n    println!("Hello, World!");\n}`
const rustOutput = syntastica.highlight(rustInput, 'rust', 'one::dark')
document.getElementById('rust-code').innerHTML = rustOutput

// highlight a piece of code multiple times
const jsInput = `console.log('Hello, World!')`
const highlights = syntastica.process(jsInput, 'javascript')

// - first to HTML again
const jsOutput1 = syntastica.render(highlights, 'gruvbox::dark')
document.getElementById('js-code').innerHTML = jsOutput1

// - then for terminals (e.g. for usage in nodejs CLIs)
const jsOutput2 = syntastica.render(highlights, 'one::deep', 'terminal')
console.log(jsOutput2)
0.5.1

4 months ago

0.5.0

5 months ago

0.4.7

5 months ago

0.4.6

5 months ago

0.4.5

5 months ago

0.4.4

5 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.4.1

5 months ago

0.4.0

5 months ago