Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getHTML(orgContentNode) {
let body = await getAST({ node: orgContentNode, cache })
if (body.type === `section`) {
body = { ...body, children: body.children.slice(1) }
}
const filesToCopy = new Map()
const highlight = pluginOptions.noHighlight !== true
const handlers = { link: handleLink }
// offset the levels
const firstHeadline = select('headline', body)
const offset = firstHeadline ? firstHeadline.level - 1 : 0
if (offset > 0) {
body = map(body, node => {
if (node.type !== `headline`) return node
return { ...node, level: node.level - offset }
})
}
const hast = toHAST(body, { highlight, handlers })
const html = hastToHTML(hast, { allowDangerousHTML: true })
await Promise.all(Array.from(filesToCopy, async ([linkPath, newFilePath]) => {
// Don't copy anything is the file already exists at the location.
if (!fsExtra.existsSync(newFilePath)) {
try {
await fsExtra.ensureDir(dirname(newFilePath))
await fsExtra.copy(linkPath, newFilePath)
} catch (err) {
console.error(`error copying file`, err)
}
function pullOutCardLinks(ast: any): { ast: any; cardLinksAst: any } {
// clone ast via `unistMap` before modifying it
// otherwise when user returns back to the current page
// the modified ast will not contain card-links
const result = { ast: unistMap(ast, (n) => n), cardLinksAst: null };
let pullCardLinks = false;
unistVisit(result.ast, (node: any, index: number, parent: any) => {
// find comment <-- card-links --> in markdown
if (node.type === 'comment' && /card\-links/.test(node.value)) {
pullCardLinks = true;
}
// pull out first <ul> from ast after <-- card-links -->
if (pullCardLinks && node.tagName === 'ul') {
pullCardLinks = false;
parent.children.splice(index, 1);
result.cardLinksAst = cleanupListNode(node);
}
});
</ul>
export function assertNode(input, children) {
const actual = map(new Elements.Document({ children }),
node => _.omit(node, ['position', 'blanklines']));
assert.deepStrictEqual(RST.parse(input), actual);
}
export function truncateHTML(content, max_length, placeholder_image_text) {
const tree = unified().use(parse, { fragment: true }).parse(content);
let counter = 0;
let images_counter = 0;
const truncated_tree = map(tree, function (node) {
if (counter >= max_length) {
return null;
}
if (node.type === "element" && node.tagName === "img") {
images_counter++;
return null;
}
if (node.type !== "text") {
return node;
}
if (counter + node.value.length < max_length) {
counter += node.value.length;
return node;
parse(s, options = {}) {
const tree = parser.parse(s);
return map(tree, node => {
const omits = [];
if (!options.position) {
omits.push('position');
}
if (!options.blanklines) {
omits.push('blanklines');
}
if (!options.indent) {
omits.push('indent');
}
return _.omit(node, omits);
});
},
};
function apply(root, options) {
const opts = { ...DEFAULTS, ...options }
return map(root, (node, _, parent) => {
if (isSeparatorRow(node)) {
return addClassNames(node, [opts.separatorClass])
}
if (isSeparatorTD(parent)) {
return { ...node, value: '' }
}
return node
})
}
export function renderLayer(layer: Layer): SvgLayer {
const svgRender = unistMap(layer.image, mapImageTreeToSvg)
if (svgRender.properties) {
const {width, height} = svgRender.properties
if (typeof width === 'number') {
svgRender.properties.width = `${width}${layer.units}`
}
if (typeof height === 'number') {
svgRender.properties.height = `${height}${layer.units}`
}
}
return {...layer, svgRender}
}
return tree => {
map(tree, node => {
if ('value' in node) {
node.value = parseTemplate(node.value, data);
}
});
return tree;
};
};