marktext/src/editor/parser/render/renderInlines/aLink.js
Felix Häusler b3cd4661ba fix: #277 inline math and typo (#278)
* fix: #277 inline math

* fix typo
2018-05-18 23:59:28 +08:00

26 lines
1.0 KiB
JavaScript

import { CLASS_OR_ID } from '../../../config'
import { snakeToCamel } from '../../../utils'
// `a_link`: `<a href="url">anchor</a>`
export default function aLink (h, cursor, block, token, outerClass) {
const className = this.getClassName(outerClass, block, token, cursor)
const tagClassName = className === CLASS_OR_ID['AG_HIDE'] ? className : CLASS_OR_ID['AG_HTML_TAG']
const { start, end } = token.range
const openTag = this.highlight(h, block, start, start + token.openTag.length, token)
const anchor = token.children.reduce((acc, to) => {
const chunk = this[snakeToCamel(to.type)](h, cursor, block, to, className)
return Array.isArray(chunk) ? [...acc, ...chunk] : [...acc, chunk]
}, [])
const closeTag = this.highlight(h, block, end - token.closeTag.length, end, token)
return [
h(`span.${tagClassName}.${CLASS_OR_ID['AG_OUTPUT_REMOVE']}`, openTag),
h(`a.${CLASS_OR_ID['AG_A_LINK']}`, {
dataset: {
href: token.href
}
}, anchor),
h(`span.${tagClassName}.${CLASS_OR_ID['AG_OUTPUT_REMOVE']}`, closeTag)
]
}