How to use the unist-util-select.selectAll function in unist-util-select

To help you get started, we’ve selected a few unist-util-select examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / website / ts / utils / algolia_helpers.ts View on Github external
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);
    }
}
github azu / power-doctest / packages / @power-doctest / markdown / src / index.ts View on Github external
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
github orgapp / orgajs / packages / gatsby-transformer-orga / src / orga-util.ts View on Github external
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] }
  }, {})
}
github Alfresco / alfresco-ng2-components / tools / doc / tools / fileChecker.js View on Github external
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) {
github skypager / skypager / src / helpers / document / src / mdx / mdx.js View on Github external
select(selector, base = this.ast) {
    return selectAll(selector, base)
  }
github Alfresco / alfresco-ng2-components / tools / doc / tools / linkFixer.ts View on Github external
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) &&
github Alfresco / alfresco-ng2-components / tools / doc / tools / fileChecker.ts View on Github external
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;
            }
        });
    });
github meetalva / alva / packages / analyzer / src / typescript-react-analyzer / slot-analzyer.ts View on Github external
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;
});
github adobe / helix-pipeline / src / html / get-metadata.js View on Github external
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) : '';
}

unist-util-select

unist utility to select nodes with CSS-like selectors

MIT
Latest version published 6 months ago

Package Health Score

73 / 100
Full package analysis