All Projects → remarkjs → Remark React

remarkjs / Remark React

Licence: mit
plugin to transform to React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Remark React

Remark Vdom
plugin to compile Markdown to Virtual DOM
Stars: ✭ 44 (-90.91%)
Mutual labels:  markdown, virtual-dom
Redpen
RedPen is an open source proofreading tool to check if your technical documents meet the writing standard. RedPen supports various markup text formats (Markdown, Textile, AsciiDoc, Re:VIEW, reStructuredText and LaTeX).
Stars: ✭ 466 (-3.72%)
Mutual labels:  markdown
Verb
HEADS UP! Verb is going though a major transition, we've completely refactored everything from the ground up. If you're interested, please see the dev branch.
Stars: ✭ 442 (-8.68%)
Mutual labels:  markdown
Awesome Markdown
📝 Delightful Markdown stuff.
Stars: ✭ 451 (-6.82%)
Mutual labels:  markdown
Pandoc Starter
📄 My pandoc markdown templates and makefiles
Stars: ✭ 443 (-8.47%)
Mutual labels:  markdown
Kite
🌴 Kite 前台页面是vue ssr服务端渲染、后台页面是react spa、服务层nodejs express、mysql编写的一套多权限文章、动态管理系统
Stars: ✭ 455 (-5.99%)
Mutual labels:  markdown
Vim Markdown Toc
A vim 7.4+ plugin to generate table of contents for Markdown files.
Stars: ✭ 427 (-11.78%)
Mutual labels:  markdown
Beibq
基于flask开发类似gitbook的知识管理网站。 http://demo.beibq.cn
Stars: ✭ 480 (-0.83%)
Mutual labels:  markdown
React Simplemde Editor
React wrapper for simplemde markdown editor
Stars: ✭ 463 (-4.34%)
Mutual labels:  markdown
Markdown Resume Js
Turn a simple markdown document into a resume in HTML and PDF
Stars: ✭ 449 (-7.23%)
Mutual labels:  markdown
Vscode Markdownlint
Markdown linting and style checking for Visual Studio Code
Stars: ✭ 444 (-8.26%)
Mutual labels:  markdown
Comrak
CommonMark + GFM compatible Markdown parser and renderer
Stars: ✭ 444 (-8.26%)
Mutual labels:  markdown
Nuxt Markdown Blog Starter
Nuxt + Markdown blog starter
Stars: ✭ 456 (-5.79%)
Mutual labels:  markdown
Marp Vscode
Marp for VS Code: Create slide deck written in Marp Markdown on VS Code
Stars: ✭ 442 (-8.68%)
Mutual labels:  markdown
Innersourcepatterns
Proven approaches that can guide you through applying open source best practices within your organization
Stars: ✭ 473 (-2.27%)
Mutual labels:  markdown
Notepads
A modern, lightweight text editor with a minimalist design.
Stars: ✭ 5,596 (+1056.2%)
Mutual labels:  markdown
Ivi
🔥 Javascript (TypeScript) library for building web user interfaces
Stars: ✭ 445 (-8.06%)
Mutual labels:  virtual-dom
Markdown
markdown parser and HTML renderer for Go
Stars: ✭ 454 (-6.2%)
Mutual labels:  markdown
Blog
🍁 What you don't know is what you haven't learned
Stars: ✭ 484 (+0%)
Mutual labels:  markdown
Jupytext
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
Stars: ✭ 4,969 (+926.65%)
Mutual labels:  markdown

remark-react

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to transform Markdown to React.

Why? Using innerHTML and dangerouslySetInnerHTML in React is a common cause of XSS attacks: user input can include script tags and other kinds of active content that reaches across domains and harms security. remark-react builds a DOM in React, using React.createElement: this means that you can display parsed and formatted Markdown content in an application without using dangerouslySetInnerHTML.

⚠️ This package essentially packs remark-rehype and rehype-react, and although it does support some customization, it isn’t very pluggable. It’s probably better to use remark-rehype and rehype-react directly to benefit from the rehype ecosystem.

Note!

This plugin is ready for the new parser in remark (remarkjs/remark#536). No change is needed: it works exactly the same now as it did before!

Install

npm:

npm install remark-react

Use

import React from 'react'
import ReactDom from 'react-dom'
import unified from 'unified'
import parse from 'remark-parse'
import remark2react from 'remark-react'

class App extends React.Component {
  constructor() {
    super()
    this.state = { text: '# hello world' }
    this.onChange = this.onChange.bind(this)
  }
  onChange(e) {
    this.setState({ text: e.target.value })
  }
  render() {
    return (
      <div>
        <textarea value={this.state.text} onChange={this.onChange} />
        <div id="preview">
          {
            unified()
              .use(parse)
              .use(remark2react)
              .processSync(this.state.text).result
          }
        </div>
      </div>
    )
  }
}

ReactDom.render(<App />, document.getElementById('root'))

API

remark().use(react[, options])

Transform Markdown to React.

Typically, unified compilers return string. This compiler returns a ReactElement. When using .process or .processSync, the value at file.result (or when using .stringify, the return value), is a ReactElement. When using TypeScript, cast the type on your side.

ℹ️ In [email protected], the result of .process changed from file.contents to file.result.

options
options.toHast

Configure how to transform mdast to hast (object, default: {}). Passed to mdast-util-to-hast. Note that toHast.allowDangerousHTML does not work: it’s not possible to inject raw HTML with this plugin (as it’s mean to prevent having to use dangerouslySetInnerHTML).

options.sanitize

Sanitation schema to use (object or boolean, default: undefined). Passed to hast-util-sanitize. The default schema, if none or true is passed, adheres to GitHub’s sanitation rules. Setting this to false is just as bad as using dangerouslySetInnerHTML.

options.prefix

React key (default: h-).

options.createElement

How to create elements or components (Function). Default: require('react').createElement

options.fragment

Create fragments instead of an outer <div> if available (Function, default: require('react').Fragment).

options.remarkReactComponents

Override default elements (such as <a>, <p>, etc) by defining an object comprised of element: Component key-value pairs (Object, default: undefined). For example, to output <MyLink> components instead of <a>, and <MyParagraph> instead of <p>:

remarkReactComponents: {
  a: MyLink,
  p: MyParagraph
}

Integrations

remark-react is similar in configuration to its alternative remark-html. You’ll want to use one or the other but setting up plugins for either is done in the same way. As such, you can see how to integrate with other remark plugins in the Integrations section of remark-html’s documentation.

Security

Use of remark-react is safe by default, but changing the sanitize option can open you up to a cross-site scripting (XSS) attack if the tree is unsafe.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer, modified by Tom MacWright and Mapbox.

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].