How to use rehype - 10 common examples

To help you get started, we’ve selected a few rehype 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 callstack / component-docs / src / templates / Markdown.js View on Github external
highlight: (code, lang) => {
        try {
          const nodes = highlight(code, lang);

          return rehype()
            .stringify({ type: 'root', children: nodes })
            .toString();
        } catch (err) {
          if (/Unknown language/.test(err.message)) {
            return escape(code);
          }

          throw err;
        }
      },
    });
github pacocoursey / paco / components / Code.jsx View on Github external
export default ({ children, className }) => (
  <pre>    {className ? (
      <code>
    ) : (
      <code>{children}</code>
    )}

    <style>
      {`
        pre {
          background-color: var(--lighter-gray);
          color: var(--fg);</style></code></pre>
github netlify / netlify-cms / cypress / support / commands.js View on Github external
function toPlainTree(domString) {
  return rehype()
    .use(removeSlateArtifacts)
    .data('settings', { fragment: true })
    .processSync(domString).contents;
}
github IBM / nicedoc.io / core / build / html.js View on Github external
import remarkHtml from 'remark-html'
import remark from 'remark'

import rehypePrism from '@mapbox/rehype-prism'
import rehypeSlug from 'rehype-slug'
import rehype from 'rehype'

const htmlRehype = rehype()
  .use(rehypeSlug)
  .use(rehypePrism, { ignoreMissing: true, preLangClass: false })

export default async data => {
  const { contents: html } = await remark()
    .use(remarkHtml)
    .process(data)

  return htmlRehype.process(html)
}
github hshoff / ui-kit / packages / code / src / index.js View on Github external
export default function Code({
  className,
  children,
  language,
  style,
}) {
  const nodes = refractor.highlight(children, language);
  const html = rehype()
    .stringify({ type: 'root', children: nodes })
    .toString();
  return (
    <pre style="{style}">  );
}
</pre>
github benawad / codeponder / packages / web / utils / highlightCode.ts View on Github external
export const getHighlightedHTML = (code: string, lang: string): string => {
  const ast = getHast(code, lang);
  if (ast) {
    return rehype()
      .stringify({ type: "root", children: ast })
      .toString();
  }
  return code;
};
github rehypejs / rehype / packages / rehype-cli / cli.js View on Github external
'use strict'

var start = require('unified-args')
var processor = require('rehype')
var proc = require('rehype/package.json')
var cli = require('./package.json')

start({
  processor: processor,
  name: proc.name,
  description: cli.description,
  version: [
    proc.name + ': ' + proc.version,
    cli.name + ': ' + cli.version
  ].join(', '),
  pluginPrefix: proc.name,
  packageField: proc.name,
  rcName: '.' + proc.name + 'rc',
  ignoreName: '.' + proc.name + 'ignore',
  extensions: ['html', 'htm', 'xht', 'xhtml']
})
github rehypejs / rehype / packages / rehype-cli / cli.js View on Github external
#!/usr/bin/env node
'use strict'

var start = require('unified-args')
var processor = require('rehype')
var proc = require('rehype/package.json')
var cli = require('./package.json')

start({
  processor: processor,
  name: proc.name,
  description: cli.description,
  version: [
    proc.name + ': ' + proc.version,
    cli.name + ': ' + cli.version
  ].join(', '),
  pluginPrefix: proc.name,
  packageField: proc.name,
  rcName: '.' + proc.name + 'rc',
  ignoreName: '.' + proc.name + 'ignore',
  extensions: ['html', 'htm', 'xht', 'xhtml']
})

rehype

HTML processor powered by plugins part of the unified collective

MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis