Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function processContentTree(tree: Node[], file: File, indexName: string): void {
const modify = modifyChildren(modifier);
// We first modify the tree to get slugified ids from headings to all text nodes
// This is done to be able to link to a certain section in a doc after clicking a search suggestion
modify(tree);
// Get all text nodes. I.e. 'heading', 'paragraph', 'list' all can have (nested) child text nodes
const textNodes = selectAll('text', tree);
if (textNodes) {
// Combines text nodes that exist on the same line. I.e. if a paragraph contains 7 text nodes it combines them into 1. This makes text snippets in algolia more descriptive.
const formattedTextNodes = formatTextNodes(textNodes);
// Adds meta and formats information on all formatted text nodes
const content = getContent(file, formattedTextNodes);
const algoliaIndex = adminClient.initIndex(searchIndices[indexName]);
const algoliaSettings = settings[indexName];
setIndexSettings(algoliaIndex, algoliaSettings);
void pushObjectsToAlgoliaAsync(algoliaIndex, content);
}
}
export const parse = ({ content, filePath }: ParserArgs): ParsedResults => {
const markdownAST = attachParents(remark.parse(content));
const codeBlocks = [].concat(
select.selectAll(`code[lang="js"]`, markdownAST),
select.selectAll(`code[lang="javascript"]`, markdownAST)
);
return codeBlocks.map((codeBlock: UnistNode) => {
const codeValue: string = (codeBlock.value as string | undefined) || "";
const comments = getComments(codeBlock.parent, codeBlock);
const docTestController = new DocTestController(comments);
const state = docTestController.state;
const doctestOptions = docTestController.doctestOptions;
const expectedError = docTestController.expectedErrorName;
const metadata = docTestController.doctestMetadata;
return {
code: codeValue,
location: codeBlock.position ? {
start: {
line: codeBlock.position.start.line,
column: codeBlock.position.start.column
export const getProperties = headline => {
const drawer = selectAll(`drawer`, headline).find(d => d.name === `PROPERTIES`)
if (!drawer) return {}
const regex = /\s*:(.+):\s*(.+)\s*$/
return drawer.value.split(`\n`).reduce((accu, current) => {
const m = current.match(regex)
return { ...accu, [m[1].toLowerCase()]: m[2] }
}, {})
}
pathnames.forEach(function (pathname) {
var fileBaseName = path.basename(pathname, '.md');
var tree = mdCache[pathname].mdOutTree;
var className = ngHelpers.ngNameToClassName(fileBaseName, aggData.config.typeNameExceptions);
var classInfo = aggData.classInfo[className];
if (!classInfo) {
if (!filterFilepath(filters, pathname)) {
classlessDocs.push(pathname);
}
}
else {
var linkElems = unist_util_select_1.selectAll('link', tree);
linkElems.forEach(function (linkElem) {
var normUrl = normaliseLinkPath(pathname, linkElem.url);
multiSetAdd(linkRefs, normUrl, pathname);
});
}
var imageElems = unist_util_select_1.selectAll('image', tree);
imageElems.forEach(function (imageElem) {
var normUrl = normaliseLinkPath(pathname, imageElem.url);
multiSetAdd(imageRefs, normUrl, pathname);
if (!fs.existsSync(normUrl)) {
brokenImageRefs[normUrl] = pathname;
}
});
});
classlessDocs.forEach(function (docPath) {
select(selector, base = this.ast) {
return selectAll(selector, base)
}
function fixUrls(tree: MDAST.Root, docFilePath: string, linkSet: LinkSet, selector: string) {
const linksInDoc = selectAll(selector, tree);
const errors: string[] = [];
linksInDoc.forEach(linkElem => {
let origFullUrlPath = path.resolve(path.dirname(docFilePath), linkElem.url);
const hashPos = origFullUrlPath.indexOf('#');
let anchor = '';
if (hashPos !== -1) {
anchor = origFullUrlPath.substring(hashPos);
origFullUrlPath = origFullUrlPath.substring(0, hashPos);
}
if (!linkElem.url.match(/http:|https:|ftp:|mailto:/) &&
!path.extname(origFullUrlPath).match(suffixesNotToCheck) &&
const classInfo = aggData.classInfo[className];
if (!classInfo) {
if (!filterFilepath(filters, pathname)) {
classlessDocs.push(pathname);
}
} else {
const linkElems = selectAll('link', tree);
linkElems.forEach(linkElem => {
const normUrl = normaliseLinkPath(pathname, linkElem.url);
multiSetAdd(linkRefs, normUrl, pathname);
});
}
const imageElems = selectAll('image', tree);
imageElems.forEach(imageElem => {
const normUrl = normaliseLinkPath(pathname, imageElem.url);
multiSetAdd(imageRefs, normUrl, pathname);
if (!fs.existsSync(normUrl)) {
brokenImageRefs[normUrl] = pathname;
}
});
});
const mdProcessor = remark().use(() => (tree: any, file: any) => {
const blocks = select.selectAll('paragraph:has(text[value="@default"]) + code', tree);
const block = blocks[blocks.length - 1] || { value: undefined };
file.data.defaultCode = block.value;
return tree;
});
function intro(section) {
const para = selectAll('paragraph', section).filter((p) => {
if ((!p.children || p.children.length === 0)
|| (p.children.length === 1 && p.children[0].type === 'image')) {
return false;
}
return true;
})[0];
section.intro = para ? plain(para) : '';
}