Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return node;
}
const nb_addable = max_length - counter;
counter = max_length;
return Object.assign({}, node, {
value: node.value.substr(0, nb_addable) + "…",
});
});
remove(truncated_tree, (node) => {
return typeof node.type === "undefined";
});
if (images_counter > 0 && toString(truncated_tree).trim().length === 0) {
return "<p><i>" + placeholder_image_text + "</i></p>";
}
return toHtml(truncated_tree);
}
}
const lang = getLanguage(node);
if (lang === null) {
return;
}
let result = node;
try {
parent.properties.className = (parent.properties.className || []).concat(
`language-${lang}`
);
result = highlight(nodeToString(node), lang);
} catch (err) {
if (/Unknown language/.test(err.message)) {
return;
}
throw err;
}
node.children = [];
node.properties.dangerouslySetInnerHTML = {
__html: nodeToHTML({
type: 'root',
children: result,
}),
};
}
visit(ast, 'element', node => {
if (is(node, headings) && has(node, 'id')) {
vFile.data.slugs.push({
depth: parseInt(node.tagName[1], 10) - 1,
value: toString(node),
heading: (node.properties as any)?.id,
});
}
});
} else {
if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') {
return
}
const lang = getLanguage(node, options.aliases || aliases)
if (lang === null) {
return
}
let result = node
try {
parent.properties.className = (parent.properties.className || []).concat(
'language-' + lang,
)
result = refractor.highlight(nodeToString(node), lang)
} catch (err) {
if (/Unknown language/.test(err.message)) {
return
}
throw err
}
node.children = []
node.properties.dangerouslySetInnerHTML = {
__html: nodeToHTML({
type: 'root',
children: result,
}),
}
}
}
const addComponentsProps = (scopes: string[]) => async (
node: any,
idx: number
) => {
const name = componentName(node.value)
const tagOpen = new RegExp(`^\\<${name}`)
if (isPlayground(name)) {
const formatted = await format(nodeToString(node))
const code = formatted.slice(1, Infinity)
const scope = `{props,${scopes.join(',')}}`
const child = sanitizeCode(removeTags(code))
node.value = node.value.replace(
tagOpen,
`<${name} __position={${idx}} __code={'${child}'} __scope={${scope}}`
)
}
}