Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function openElement(token, fileName, lineNumber) {
// destructure the attributes from matches, omitting `matches[0]` since
// we're only interested in the captures
const [, type, id, attr] = token
log.debug(`open directive [${id}]`)
const comment = Html.comment(
`START: section:${type}#${htmlId(id)}; ${fileName}:${lineNumber}`
)
const attrs = attributes(attr, type, { fileName, lineNumber })
return `${comment}<section id="${htmlId(id)}">`
}
</section>
function handleExitDirective(token) {
const [, type, id] = token
log.debug(`exit directive [${id}]`)
const comment = Html.comment(`END: section:${type}#${htmlId(id)}`)
const directive = find(state.cursor, { id })
state.remove('cursor', { id })
if (isGallery(directive)) {
// prettier-ignore
return `
${comment}`
}
if (isSpread(directive)) {
log.error(
`Missing [id] for [${exports.default.name}:start] at ${context.fileName}.md:${line}`
)
// let the parser know that this wasn't a match
return false
}
// we add the `id` to the global state so that we can verify that the
// container is being properly closed in our `validateClose` method
const index = state.indexOf('cursor', { id })
const isOpening = type && type !== 'exit'
const isClosing = type && type === 'exit'
const inStore = index > -1
log.debug(
`id: ${id}; isOpening: ${isOpening}; isClosing: ${isClosing}; type: ${type}, inStore: ${inStore}`
)
const location = `${context.fileName}.md:${line}`
if (isOpening && inStore) {
// it's a duplicate `id`, throw
log.error(`Duplicate [id] [${id}]. [id] must be unique at [${location}]`)
} else if (isClosing && !inStore) {
// trying to close an un-opened directive, but it might belong to a
// different directive type
return false
} else if (isOpening && !inStore) {
// it's a brand new directive
state.add('cursor', { id, type })
return true
} else if (isClosing && inStore) {