How to use hast-util-to-string - 5 common examples

To help you get started, we’ve selected a few hast-util-to-string 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 Enalean / tuleap / plugins / testmanagement / scripts / testmanagement / src / execution / truncate.js View on Github external
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);
}
github callstack / component-docs / src / utils / rehypePrism.js View on Github external
}

    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,
      }),
    };
  }
github umijs / father-doc / packages / umi-plugin-father-doc / src / transformer / remark / header.ts View on Github external
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 {
github frontarm / demoboard / packages / demoboard-worker / src / transforms / mdx / rehype-prism.ts View on Github external
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,
      }),
    }
  }
}
github doczjs / docz / core / rehype-docz / src / index.ts View on Github external
const addComponentsProps = (scopes: string[]) =&gt; async (
  node: any,
  idx: number
) =&gt; {
  const name = componentName(node.value)
  const tagOpen = new RegExp(`^\\&lt;${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,
      `&lt;${name} __position={${idx}} __code={'${child}'} __scope={${scope}}`
    )
  }
}

hast-util-to-string

hast utility to get the plain-text value of a node

MIT
Latest version published 1 month ago

Package Health Score

78 / 100
Full package analysis

Popular hast-util-to-string functions