tiny-html-lexer
Version:
A tiny HTML5 lexer
36 lines (29 loc) • 954 B
JavaScript
import * as tinyhtml from '../lib/index.js'
import * as util from 'util'
const log = console.log.bind (console)
var sample = '<span>Hello, world</span>'
var sample = '<span cLass="foo" class="bar" Class=bee bar baz="a\nb">\n'
var sample = '<script>\n'
var sample = '<plaintext>\n'
var sample = '<textarea>\r'
var sample = '<textarea>Foo<script></textarea bar=bee>'
var sample = '<span f=&><🌿 Hello, world!\n🦍></span attr="<=<"> Test &abss; d'
log ('Chunks\n======\n')
var stream = tinyhtml.chunks (sample)
//log (stream.state)
for (let chunk of stream) {
log (chunk)
//log (stream.state)
}
log ('\nTags\n====\n')
var stream = tinyhtml.tags (sample, { parseNamedCharRef })
//log (stream.state)
for (let token of stream) {
log (util.inspect (token))
//log (stream.state)
}
function parseNamedCharRef (x) {
const y = tinyhtml.parseNamedCharRef (x)
if (y == x) console.log ('!! unknown char ref', x)
return y
}