fix(markdown): preserve user-defined attributes

closes #5123
pull/5014/head
Divyansh Singh 6 days ago
parent a86e8b51e2
commit 3f4530b0e2

@ -40,7 +40,7 @@ export const imagePlugin = (
addImageDimensions(token, url, publicDir, env)
}
if (lazyLoad && !token.attrGet('loading')) {
if (lazyLoad && token.attrIndex('loading') < 0) {
token.attrSet('loading', 'lazy')
}

@ -51,7 +51,7 @@ export const linkPlugin = (
hrefAttr[1] = url
if (isExternal(url)) {
Object.entries(externalAttrs).forEach(([key, val]) => {
token.attrSet(key, val)
if (token.attrIndex(key) < 0) token.attrSet(key, val)
})
// catch localhost links as dead link
if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) {

@ -6,7 +6,7 @@ export const tablePlugin = (md: MarkdownItAsync) => {
const tableOpen = md.renderer.rules.table_open
md.renderer.rules.table_open = function (tokens, idx, options, env, self) {
const token = tokens[idx]
if (token.attrIndex('tabindex') < 0) token.attrPush(['tabindex', '0'])
if (token.attrIndex('tabindex') < 0) token.attrSet('tabindex', '0')
return tableOpen
? tableOpen(tokens, idx, options, env, self)
: self.renderToken(tokens, idx, options)

Loading…
Cancel
Save