How to use rehype-react - 10 common examples

To help you get started, we’ve selected a few rehype-react 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 rstacruz / devhints-engine / src / web-post-content / lib / transform.tsx View on Github external
console.log(htmlAst)
  // Perform transformations
  htmlAst = decorate(htmlAst)
  htmlAst = wrapify(htmlAst)
  htmlAst = separatify(htmlAst)

  // Convert to React
  const element = renderAst(htmlAst)
  return element
}

/**
 * Renders HAST into React using `rehype-react`.
 */

export const renderAst = new RehypeReact({
  createElement: React.createElement
}).Compiler
github bcgov / devhub-app-web / app-web / src / templates / SourceGithub_default.js View on Github external
render() {
    const {
      data: { githubRaw, nav, topic },
      location,
    } = this.props;
    // bind the devhub siphon data to the preview node
    const previewWithNode = withNode(githubRaw)(ComponentPreview);

    const renderAst = new rehypeReact({
      createElement: React.createElement,
      components: { 'component-preview': previewWithNode },
    }).Compiler;
    let navigationItems = nav.items;

    const navigation = ;

    const [owner, repo] = githubRaw.html_url.replace('https://github.com/', '').split('/');
    const { title } = githubRaw.fields;
    const originalSource = githubRaw.html_url;
    const { href } = location;

    return (
      
        <div>
          </div>
github rstacruz / devhints-engine / src / web-post-content / transform.tsx View on Github external
export default function transform(htmlAst: HastNode): React.ReactNode {
  // Perform transformations
  htmlAst = decorate(htmlAst)
  htmlAst = wrapify(htmlAst)
  htmlAst = separatify(htmlAst)

  // Convert to React
  const element = renderAst(htmlAst)
  return element
}

/**
 * Renders HAST into React using `rehype-react`.
 */

export const renderAst = new RehypeReact({
  createElement: React.createElement
}).Compiler
github baobabKoodaa / blog / src / components / Article / Bodytext.js View on Github external
import React from "react";
import PropTypes from "prop-types";
import rehypeReact from "rehype-react";
import Icons from "../../components/About/WebPresenceIcons";
import ReImg from "./ReImg";
import ReTracedSVGGallery from "./ReTracedSVGGallery";
import { Link } from "gatsby";

const renderAst = new rehypeReact({
  createElement: React.createElement,
  components: { "re-icons": Icons , "re-img": ReImg , "re-link": Link, "re-tracedsvg-gallery": ReTracedSVGGallery }
}).Compiler

const Bodytext = props =&gt; {
  const { content, theme } = props;
  const html = props.content.html;

  return (
    

      {/* Render markdown with Custom Components */}
      <div>
        {renderAst(content.htmlAst)}
      </div>
github Bitcoin-com / developer.bitcoin.com / src / templates / tutorialPage.js View on Github external
import rehypeReact from 'rehype-react'
import { graphql } from 'gatsby'
import { FaAngleLeft } from 'react-icons/fa'

import DefaultLayout from 'components/layouts/DefaultLayout.js'
import Container from 'components/Container'
import HelmetPlus from 'components/HelmetPlus'

import StyledLink from 'atoms/StyledLink'
import H2 from 'atoms/H2'
import H3 from 'atoms/H3'

import spacing from 'styles/spacing'
import { standardTransforms } from 'utils/markdown-helpers'

const renderAst = new rehypeReact({
  createElement: React.createElement,
  components: {
    ...standardTransforms,
  },
}).Compiler

const PageLayout = styled.div`
  display: grid;
  margin-top: ${spacing.medium};
  grid-gap: ${spacing.medium};
`

// too wide is hard to read, limit to some amount;
const TutorialHolder = styled.div`
  max-width: 820px;
  display: grid;
github Bitcoin-com / developer.bitcoin.com / src / templates / insightPage.js View on Github external
import rehypeReact from 'rehype-react'
import { graphql } from 'gatsby'
import { FaAngleLeft } from 'react-icons/fa'

import HelmetPlus from 'components/HelmetPlus'
import DefaultLayout from 'components/layouts/DefaultLayout.js'
import Container from 'components/Container'

import StyledLink from 'atoms/StyledLink'
import H2 from 'atoms/H2'
import H3 from 'atoms/H3'

import spacing from 'styles/spacing'
import { standardTransforms } from 'utils/markdown-helpers'

const renderAst = new rehypeReact({
  createElement: React.createElement,
  components: {
    ...standardTransforms,
  },
}).Compiler

const PageLayout = styled.div`
  display: grid;
  margin-top: ${spacing.medium};
  grid-gap: ${spacing.medium};
`

// too wide is hard to read, limit to some amount;
const InsightHolder = styled.div`
  max-width: 820px;
  display: grid;
github rstacruz / devhints-engine / src / rehype-wrapify / lib / helpers / hast_to_react.js View on Github external
import React from 'react'
import RehypeReact from 'rehype-react'

/*
 * We serialize the test markup as React elements, not hast.
 * Just for practicality... Jest has better test output for
 * React elements.
 */

const render = new RehypeReact({
  createElement: React.createElement
}).Compiler

export default render
github breatheco-de / content / src / templates / lesson.js View on Github external
import React from "react";
import { graphql } from 'gatsby';
import rehypeReact from "rehype-react";
import { Cover } from "../components/cover/cover.js";
import { Layout } from "../components/layout/layout.jsx";
import { BeforeAfter } from "../components/beforeafter/beforeafter.jsx";
import { EditOnGithub } from "../components/editongithub/EditOnGithub.jsx";
import { LanguageSwitcher } from "../components/languageswitcher/LanguageSwitcher.jsx";

const renderAst = new rehypeReact({
  createElement: React.createElement,
  components: { "cover": Cover, "before-after": BeforeAfter }
}).Compiler;

const Lesson = (props) => {
  const { data, pageContext, t, i18n } = props;
  const post = data.markdownRemark;
  const { translations, urlSlug, type } = pageContext;
  const seo = {
    title: post.frontmatter.title,
    description: post.frontmatter.subtitle,
    url: post.frontmatter.original_url,
    image: post.frontmatter.thumb,
    canonical: (post.fields.lang === 'en') ? "/es/" : "/en/"
  };
  return (
github ines / spacy-course / src / markdown.js View on Github external
import React from 'react'
import rehypeReact from 'rehype-react'

import Exercise from './components/exercise'
import CodeBlock from './components/code'
import { Link } from './components/link'
import Slides from './components/slides'
import Choice, { Option } from './components/choice'
import { H3, Hr, Ol, Ul, Li, InlineCode } from './components/typography'

export const renderAst = new rehypeReact({
    createElement: React.createElement,
    components: {
        exercise: Exercise,
        slides: Slides,
        codeblock: CodeBlock,
        choice: Choice,
        opt: Option,
        a: Link,
        hr: Hr,
        h3: H3,
        ol: Ol,
        ul: Ul,
        li: Li,
        code: InlineCode,
    },
}).Compiler
github andrewbranch / gatsby-remark-vscode / examples / example-site / src / templates / react-blog-post.js View on Github external
style={{
                  cursor: 'pointer',
                  animationDuration: `${text.length * 80}ms`,
                }}
              &gt;
                {text}
              
            ))}
          
        ))}
      
    
  ) : null;
}

const renderAst = new RehypeReact({
  createElement: React.createElement,
  components: { pre: CoolCodeBlock },
}).Compiler;

class BlogPostTemplate extends React.Component {
  render() {
    const post = this.props.data.markdownRemark
    const siteTitle = this.props.data.site.siteMetadata.title
    const { previous, next } = this.props.pageContext

    return (

rehype-react

rehype plugin to transform to React

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Popular rehype-react functions