All Projects → remarkjs → react-remark

remarkjs / react-remark

Licence: MIT License
React component and hook to use remark to render markdown

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to react-remark

React-Netflix-Clone
A Fully Responsive clone of Netflix website built using React.JS as a Front-end & Firebase as a Back-end.
Stars: ✭ 91 (+12.35%)
Mutual labels:  react-components, react-hooks
hx
A simple, easy to use library for React development in ClojureScript.
Stars: ✭ 244 (+201.23%)
Mutual labels:  react-components, react-hooks
frontend-toolbox
Frontend tools which we used in snappmarket v2
Stars: ✭ 37 (-54.32%)
Mutual labels:  react-components, react-hooks
react-use-hubspot-form
Embed HubSpot forms into your React components using hooks! Works with Create React App, Gatsby and other platforms.
Stars: ✭ 41 (-49.38%)
Mutual labels:  react-components, react-hooks
fluent-windows
🌈 React components that inspired by Microsoft's Fluent Design System.
Stars: ✭ 122 (+50.62%)
Mutual labels:  react-components, react-hooks
next-qrcode
React hooks for generating QRCode for your next React apps.
Stars: ✭ 87 (+7.41%)
Mutual labels:  react-components, react-hooks
remark-footnotes
Legacy plugin to add support for pandoc footnotes — please use `remark-gfm` instead
Stars: ✭ 38 (-53.09%)
Mutual labels:  remark, unified
Remark
remark is a popular tool that transforms markdown with plugins. These plugins can inspect and change your markup. You can use remark on the server, the client, CLIs, deno, etc.
Stars: ✭ 4,746 (+5759.26%)
Mutual labels:  remark, unified
eslint-config-typescript-unified
🛠️ A unified ESLint configuration with sensible defaults for TypeScript projects.
Stars: ✭ 15 (-81.48%)
Mutual labels:  unified, react-hooks
Nectus
A boilerplate Flask API for a Fullstack Project with some additional packages and configuration prebuilt. ⚙
Stars: ✭ 32 (-60.49%)
Mutual labels:  react-components, react-hooks
awesome-web-react
🚀 Awesome Web Based React 🚀 Develop online with React!
Stars: ✭ 31 (-61.73%)
Mutual labels:  react-components, react-hooks
remark-slate-transformer
remark plugin to transform remark syntax tree (mdast) to Slate document tree, and vice versa. Made for WYSIWYG markdown editor.
Stars: ✭ 62 (-23.46%)
Mutual labels:  remark, unified
rehype-dom
HTML processor to parse and compile with browser APIs, powered by plugins
Stars: ✭ 20 (-75.31%)
Mutual labels:  unified, rehype
furl
Functional react.js components.
Stars: ✭ 33 (-59.26%)
Mutual labels:  react-components, react-hooks
Mdx
Markdown for the component era
Stars: ✭ 11,948 (+14650.62%)
Mutual labels:  remark, unified
mint-ui
Design System | React UI components for web
Stars: ✭ 17 (-79.01%)
Mutual labels:  react-components, react-hooks
remark-rehype
plugin that turns markdown into HTML to support rehype
Stars: ✭ 118 (+45.68%)
Mutual labels:  remark, rehype
slackify-markdown
Convert markdown into Slack-specific markdown
Stars: ✭ 80 (-1.23%)
Mutual labels:  remark, unified
tiny-ui
⚛️ A friendly UI component set for React.js
Stars: ✭ 202 (+149.38%)
Mutual labels:  react-components, react-hooks
react-guidebook
📚 React 知识图谱 关于概念、技巧、生态、前沿、源码核心
Stars: ✭ 22 (-72.84%)
Mutual labels:  react-components, react-hooks

react-remark

CI Downloads Size

react-remark offers a React hook and React component based way of rendering markdown into React using remark

Installation

npm

npm install --save react-remark

yarn

yarn add react-remark

Usage

As a hook

Render static content

import React, { useEffect } from 'react';
import { useRemark } from 'react-remark';

const ExampleComponent = () => {
  const [reactContent, setMarkdownSource] = useRemark();

  useEffect(() => {
    setMarkdownSource('# markdown header');
  }, []);

  return reactContent;
};

export default ExampleComponent;

Using input and events to update

import React from 'react';
import { useRemark } from 'react-remark';

const ExampleComponent = () => {
  const [reactContent, setMarkdownSource] = useRemark();

  return (
    <>
      <input
        type="text"
        onChange={({ currentTarget }) => setMarkdownSource(currentTarget.value)}
      />
      {reactContent}
    </>
  );
};

export default ExampleComponent;

Server side rendering

import React from 'react';
import { useRemarkSync } from 'react-remark';

const ExampleComponent = () => {
  const reactContent = useRemarkSync('# markdown header');

  return reactContent;
};

export default ExampleComponent;

📓 Note that some remark plugins are async, these plugins will error if used with useRemarkSync.

More examples of usage as hook in storybook.

As a component

Render static content

import React, { useState } from 'react';
import { Remark } from 'react-remark';

const ExampleComponent = () => (
  <Remark>{`
# header

1. ordered
2. list
`}</Remark>
);

export default ExampleComponent;

Using input and events to update

import React, { useState } from 'react';
import { Remark } from 'react-remark';

const ExampleComponent = () => {
  const [markdownSource, setMarkdownSource] = useState('');

  return (
    <>
      <input
        type="text"
        onChange={({ currentTarget }) => setMarkdownSource(currentTarget.value)}
      />
      <Remark>{markdownSource}</Remark>
    </>
  );
};

export default ExampleComponent;

More examples of usage as component in storybook.

Examples

A set of runnable examples are provided through storybook at https://remarkjs.github.io/react-remark. The source for the story files can be found in /stories.

Architecture

                                                             react-remark
+---------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                             |
|            +----------+        +----------------+        +---------------+       +----------------+       +--------------+                  |
|            |          |        |                |        |               |       |                |       |              |                  |
| -markdown->+  remark  +-mdast->+ remark plugins +-mdast->+ remark-rehype +-hast->+ rehype plugins +-hast->+ rehype-react +-react elements-> |
|            |          |        |                |        |               |       |                |       |              |                  |
|            +----------+        +----------------+        +---------------+       +----------------+       +--------------+                  |
|                                                                                                                                             |
+---------------------------------------------------------------------------------------------------------------------------------------------+

relevant links: markdown, remark, mdast, remark plugins, remark-rehype, hast, rehype plugins, rehype-react

Options

  • remarkParseOptions (Object) - configure how Markdown is parsed, same as remark-parse options
  • remarkPlugins (Array) - remark plugins or custom plugins to transform markdown content before it is translated to HTML (hast)
  • remarkToRehypeOptions (Object) - configure how Markdown (mdast) is translated into HTML (hast), same as remark-rehype options
  • rehypePlugins (Array) - rehype plugins or custom plugins to transform HTML (hast) before it is translated to React elements.
  • rehypeReactOptions (Object) - configure how HTML (hast) is translated into React elements, same as rehype-react options

Pass options to hook

import React, { Fragment } from 'react';
import { useRemark } from 'react-remark';
import remarkGemoji from 'remark-gemoji';
import rehypeSlug from 'rehype-slug';
import rehypeAutoLinkHeadings from 'rehype-autolink-headings';

// ...

const [reactContent, setMarkdownSource] = useRemark({
  remarkPlugins: [remarkGemoji],
  remarkToRehypeOptions: { allowDangerousHtml: true },
  rehypePlugins: [rehypeSlug, rehypeAutoLinkHeadings],
  rehypeReactOptions: {
    components: {
      p: (props) => <p className="custom-paragraph" {...props} />,
    },
  },
});

Pass options to component

import React, { Fragment } from 'react';
import { Remark } from 'react-remark';
import remarkGemoji from 'remark-gemoji';
import rehypeSlug from 'rehype-slug';
import rehypeAutoLinkHeadings from 'rehype-autolink-headings';

// ...

<Remark
  remarkPlugins={[remarkGemoji]}
  remarkToRehypeOptions={{ allowDangerousHtml: true }}
  rehypePlugins={[rehypeSlug, rehypeAutoLinkHeadings]}
  rehypeReactOptions={{
    components: {
      p: (props) => <p className="custom-paragraph" {...props} />,
    },
  }}
>
  {markdownSource}
</Remark>;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].