Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const renderAnchorLink = (anchor, options, tokens, idx) => {
const attrs = [];
if (options.anchorClassName != null) {
attrs.push(["class", options.anchorClassName]);
}
attrs.push(["href", `#${anchor}`]);
const openLinkToken = {
...new Token("link_open", "a", 1),
attrs
};
const closeLinkToken = new Token("link_close", "a", -1);
if (options.wrapHeadingTextInAnchor) {
tokens[idx + 1].children.unshift(openLinkToken);
tokens[idx + 1].children.push(closeLinkToken);
} else {
const linkTokens = [
openLinkToken,
...renderAnchorLinkSymbol(options),
closeLinkToken
];
// `push` or `unshift` according to anchorLinkBefore option
// space is at the opposite side.
const actionOnArray = {
false: "push",
true: "unshift"
const renderAnchorLink = (anchor, options, tokens, idx) => {
const attrs = [];
if (options.anchorClassName != null) {
attrs.push(["class", options.anchorClassName]);
}
attrs.push(["href", `#${anchor}`]);
const openLinkToken = {
...new Token("link_open", "a", 1),
attrs
};
const closeLinkToken = new Token("link_close", "a", -1);
if (options.wrapHeadingTextInAnchor) {
tokens[idx + 1].children.unshift(openLinkToken);
tokens[idx + 1].children.push(closeLinkToken);
} else {
const linkTokens = [
openLinkToken,
...renderAnchorLinkSymbol(options),
closeLinkToken
];
// `push` or `unshift` according to anchorLinkBefore option
// space is at the opposite side.
depth,
slug,
content,
html,
text: html.replace(/<(?:.|\n)*?>/gm, '')
})
}
const children = tokens[idx + 1].children
tokens[idx + 1].children = [
{
...new Token('link_open', 'router-link', 1),
attrs: [['class', 'docute-heading-anchor'], [':to', `{hash:'${slug}'}`]]
},
...children,
new Token('link_close', 'router-link', -1)
]
return self.renderToken(...args)
}
}
const space = () => {
return { ...new Token("text", "", 0), content: " " };
};
const renderAnchorLinkSymbol = options => {
if (options.anchorLinkSymbolClassName) {
return [
{
...new Token("span_open", "span", 1),
attrs: [["class", options.anchorLinkSymbolClassName]]
},
{
...new Token("text", "", 0),
content: options.anchorLinkSymbol
},
new Token("span_close", "span", -1)
];
} else {
return [
{
...new Token("text", "", 0),
content: options.anchorLinkSymbol
}
];
}
};
const renderAnchorLinkSymbol = options => {
if (options.anchorLinkSymbolClassName) {
return [
{
...new Token("span_open", "span", 1),
attrs: [["class", options.anchorLinkSymbolClassName]]
},
{
...new Token("text", "", 0),
content: options.anchorLinkSymbol
},
new Token("span_close", "span", -1)
];
} else {
return [
{
...new Token("text", "", 0),
content: options.anchorLinkSymbol
}
];
}
if (depth >= 2 && depth <= maxDepth) {
const html = self.render(tokens[idx + 1].children, options, env)
state.headings.push({
depth,
slug,
content,
html,
text: html.replace(/<(?:.|\n)*?>/gm, '')
})
}
const children = tokens[idx + 1].children
tokens[idx + 1].children = [
{
...new Token('link_open', 'router-link', 1),
attrs: [['class', 'docute-heading-anchor'], [':to', `{hash:'${slug}'}`]]
},
...children,
new Token('link_close', 'router-link', -1)
]
return self.renderToken(...args)
}
}