How to use the mdast-util-to-hast/lib/handlers/code function in mdast-util-to-hast

To help you get started, we’ve selected a few mdast-util-to-hast 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 umijs / father-doc / packages / umi-plugin-father-doc / src / transformer / remark / rehype.ts View on Github external
function demoHandler(h, { type, lang, value, position, ...props }) {
  // split source codes & raw code for previewer
  const clonedNode = { lang, value };
  const sources = [];

  // push original source code node
  sources.push(codeHandler(h, clonedNode));

  // push transformed source code node for tsx demo (use unshift to keep jsx first)
  if (lang === 'tsx') {
    clonedNode.lang = 'jsx';
    clonedNode.value = parseText(clonedNode.value);
    sources.unshift(codeHandler(h, clonedNode));
  }

  return h(
    position,
    'div',
    {
      type: 'previewer',
      lang,
      ...props,
    },
github umijs / father-doc / packages / umi-plugin-father-doc / src / transformer / remark / rehype.ts View on Github external
function demoHandler(h, { type, lang, value, position, ...props }) {
  // split source codes & raw code for previewer
  const clonedNode = { lang, value };
  const sources = [];

  // push original source code node
  sources.push(codeHandler(h, clonedNode));

  // push transformed source code node for tsx demo (use unshift to keep jsx first)
  if (lang === 'tsx') {
    clonedNode.lang = 'jsx';
    clonedNode.value = parseText(clonedNode.value);
    sources.unshift(codeHandler(h, clonedNode));
  }

  return h(
    position,
    'div',
    {
      type: 'previewer',
      lang,
      ...props,
    },
    [
      // append raw code node
      unist('raw', value),
      // append source code nodes
      ...sources,
    ],

mdast-util-to-hast

mdast utility to transform to hast

MIT
Latest version published 4 months ago

Package Health Score

84 / 100
Full package analysis