How to use unified - 10 common examples

To help you get started, we’ve selected a few unified 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 zestedesavoir / zmarkdown / packages / rehype-html-blocks / __tests__ / index.js View on Github external
const render = (use, text) => unified()
  .use(reParse, {
    gfm: true,
    commonmark: false,
    footnotes: true,
    /* sets list of known blocks to nothing, otherwise <h3>hey</h3> would become
    &lt;h3&gt;hey&lt;/h3&gt; instead of <p>&lt;h3&gt;hey&lt;/h3&gt;</p> */
    blocks: [],
  })
  .use(remark2rehype, {allowDangerousHTML: true})
  .use(use ? htmlBlocks : () =&gt; {})
  .use(rehypeStringify)
  .processSync(text)
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / serializers / __tests__ / remarkAllowHtmlEntities.spec.js View on Github external
const process = markdown => {
  const mdast = unified()
    .use(markdownToRemark)
    .use(remarkAllowHtmlEntities)
    .parse(markdown);

  /**
   * The MDAST will look like:
   *
   * { type: 'root', children: [
   *   { type: 'paragraph', children: [
   *     // results here
   *   ]}
   * ]}
   */
  return mdast.children[0].children[0].value;
};
github zestedesavoir / zmarkdown / packages / remark-disable-tokenizers / __tests__ / index.js View on Github external
test('block + inline', () => {
  const {contents} = unified()
    .use(reParse)
    .use(plugin, {
      block: [
        'blockquote',
      ],
      inline: [
        'emphasis',
      ],
    })
    .use(remark2rehype)
    .use(stringify)
    .processSync(dedent`
      *a*

      > *a*
github zestedesavoir / zmarkdown / packages / remark-images-download / __tests__ / index.js View on Github external
  (text) => unified()
    .use(reParse)
    .use(plugin, Object.assign(clone(opts), {downloadDestination}))
    .use(remark2rehype)
    .use(stringify)
    .process(text)
github zestedesavoir / zmarkdown / packages / remark-escape-escaped / __tests__ / index.js View on Github external
const render = (text, config) => unified()
  .use(reParse)
  .use(remark2rehype)
  .use(plugin, config)
  .use(stringify)
  .processSync(text)
github Symbitic / markbook / src / book / summary.js View on Github external
.then(file => {
      const tree = unified()
        .use(markdown)
        .parse(file)

      const { headers, prefixes, lists, suffixes } = split(tree)

      const header = extractHeader(headers)
      const prefix = extractPrefix(prefixes)
      const chapters = extractChapters(lists)
      const suffix = extractSuffix(suffixes)

      return {
        header,
        prefix,
        chapters,
        suffix
      }
github storybookjs / SBNext / server / src / components / doc.js View on Github external
const toReact = ({ content, excerpt, renderers, prefix = 'entry-' }) =>
  unified()
    .use(markdown)
    .use(extractExcerpt(excerpt))
    .use(remark2rehype, { allowDangerousHTML: true })
    .use(raw)
    .use(reactRenderer, {
      createElement: React.createElement,
      prefix,
      components: renderers,
    })
    .processSync(content).contents;
github logux / logux.io / scripts / steps / read-docs.js View on Github external
let guides = await Promise.all(files.map(async file => {
    let title = ''
    let md = await fs.readFile(join(ROOT, file))
    let tree = await unified().use(remarkParse).parse(md)
    tree = await unified()
      .use(convertor, {
        file,
        onTitle (value) {
          title = value
        }
      })
      .use(iniandBashHighlight)
      .use(remarkHighlight, {
        exclude: ['bash', 'sh', 'ini', 'diff'],
        prefix: 'code-block_'
      })
      .use(remarkRehype, { allowDangerousHTML: true })
      .use(rehypeRaw)
      .use(articler, file)
      .use(videoInserter)
      .run(tree)
github keplergl / kepler.gl / scripts / documentation.js View on Github external
function _appendListToDescription(node, mdContent) {
  const tree = unified()
  .use(markdown)
  .parse(mdContent);

  if (typeof node.description === 'object') {
    node.description.children = (node.description.children || []).concat(tree.children);
  } else {
    logError(`Missing Description for ${node.name}`);
    node.description = tree;
  }

  return node;
}
github logux / logux.io / scripts / steps / update-html.js View on Github external
return [
          tag('link', { rel: 'manifest', href: manifest.url }),
          tag('meta', { name: 'theme-color', content: manifest.theme })
        ].concat(preloadFiles.map(([media, url]) => {
          let as = PRELOAD_TYPES[extname(url)]
          if (!as) throw new Error('Unknown type ' + extname(url))
          return tag('link', {
            rel: 'preload', href: url, as, media, crossorigin: as === 'font'
          })
        }))
      } else {
        return [node]
      }
    })
  }
  let fixed = await unified()
    .use(rehypeParse)
    .use(optimizer)
    .use(rehypeStringify)
    .process(html)
  let oldFile = join(DIST, 'uikit.html')
  let newFile = join(DIST, 'uikit', 'index.html')
  await Promise.all([
    fs.writeFile(newFile, fixed.contents),
    fs.unlink(oldFile)
  ])
  assets.remove(oldFile)
  assets.add(newFile)
  return fixed.contents
}

unified

parse, inspect, transform, and serialize content through syntax trees

MIT
Latest version published 6 months ago

Package Health Score

84 / 100
Full package analysis

Popular unified functions