24 lines
498 B
JavaScript
24 lines
498 B
JavaScript
const { contentAsText } = require('../helpers.js')
|
|
|
|
module.exports = async function (doc, rootLevel) {
|
|
const { next, line, match, tail, level, head } = doc
|
|
|
|
const node = {
|
|
type: head(),
|
|
variant: tail() || 'neutral',
|
|
class: '',
|
|
href: '',
|
|
text: ''
|
|
}
|
|
|
|
while (await next(rootLevel)) {
|
|
if (match('class')) node.class = tail()
|
|
else if (match('href')) node.href = tail()
|
|
else {
|
|
node.text = await contentAsText(doc, rootLevel, true)
|
|
}
|
|
}
|
|
|
|
return node
|
|
}
|