Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert(node.identifier, 'All footnote definitions should have an id');
const definitionText = nodeText(node);
footnoteTextSet.add(definitionText);
const newId = generateFootnoteId(definitionText);
footnoteIdMapping[node.identifier] = newId;
newFootnoteIds.add(newId);
console.log(`Mapping footnote id: ${node.type} ^${node.identifier} -> ^${footnoteIdMapping[node.identifier]}`);
}
);
assert(newFootnoteIds.size === footnoteTextSet.size, 'Footnote hash id collision, which should be very unlikely');
// Apply the old->new mapping on ids, also dropping duplicate definitions.
const referencesSeen = new Set();
const definitionsSeen = new Set();
visit(
mdast,
node => node.type === 'footnoteReference' || node.type === 'footnoteDefinition',
(node, index, parent) => {
const newId = footnoteIdMapping[node.identifier];
if (node.type === 'footnoteReference') {
if (newId) {
node.identifier = newId;
} else {
missingFootnoteIds.add(node.identifier)
node.identifier += ".missing";
}
footnoteRefCount++;
referencesSeen.add(node.identifier);
} else {
assert(node.type === 'footnoteDefinition');
assert(newId);
export default options => (tree, file) =>
visit(tree, 'element', (node, i, parent) => {
// TODO: walk all opening tags and match with closing
// and combine into a single `html` node for HAST
// transformation
})
export function unInlineStyles (node) {
visit(node, isStyled, (node, index, parent) => {
const style = node.properties.style;
if (/font-style:\s*italic/.test(style)) {
wrapChildren(node, hast('em'));
}
if (/font-weight:\s*(bold|700)/.test(style)) {
wrapChildren(node, hast('strong'));
}
});
}
function fixHeadingLinks(htmlAst) {
const slugger = new Slugger();
visit(htmlAst, 'element', element => {
if (HEADING_TAG_PATTERN.test(element.tagName)) {
const id = element.properties.id;
const slug = slugger.slug(id);
if (id !== slug) {
element.properties.id = slug;
element.children.forEach(child => {
if (child.type === 'element' && child.tagName === 'a') {
child.properties.href = `#${slug}`;
}
});
}
}
});
}
export default () => (ast: Node) => {
visitParents(ast, 'text', textVisitor);
visit(ast, 'raw', rawVisitor);
};
visit(parseMd(markdown), 'html', (n: any) =>
visit(parseHtml(n.value), 'comment', (c: any) => {
const trimmedLeft = c.value.replace(/^-*\s*/, '')
detectDirectives(
trimmedLeft.replace(/\s*-*$/, ''),
index +
n.position.start.offset +
c.position.start.offset +
4 +
(c.value.length - trimmedLeft.length)
)
})
)
export function renderNodeValue(node: MDASTAnyNode): ?string {
let value = null;
visit(node, (node: MDASTAnyNode) => {
if (node.value) {
value = value || '';
value = value + node.value;
}
});
return value;
}
function transformer(ast, file) {
var insertions = []
visit(ast,'code', (node, index, parent) => {
const {lang} = node
const data = node.data || {}
const cmdstr = lang.split(' ')
if(cmdstr.length >= 2 && cmdstr[1] === '<3') {
node.lang = cmdstr[0]
data.process = false
let htmlsrc = node.value
if(node.lang === 'js') {
htmlsrc = ``
}
const htmlNode = u('html', {value: htmlsrc})
insertions.push({node, index, parent, htmlNode})
}
node.data = data
})
insertions.forEach((insert, idx) => {
}
unistFlatmap(tree, node => {
if (node.lang === 'sh' && node.value.startsWith('npm ')) {
return [
html('<details><summary>npm</summary>'),
node,
html('</details>'),
html('<details><summary>Yarn</summary>'),
{ type: 'code', lang: 'sh', value: npmToYarn(node.value) },
html('</details>')
]
} else {
return [node]
}
})
unistVisit(tree, node => {
if (node.type === 'heading') {
if (node.depth === 1) {
onTitle(node.children[0].value)
}
} else if (node.type === 'link' || node.type === 'definition') {
node.url = node.url
.replace(/^..\//, '../../')
.replace(/^.\//, '../')
.replace(/\.md(#.+)?$/, '/$1')
}
})
}
}