All Projects → simonguo → React Code View

simonguo / React Code View

Code editor for React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Code View

Marcdown
👻 Lightweight realtime markdown viewer and editor - Simple, clean and beautiful https://liyasthomas.github.io/marcdown
Stars: ✭ 345 (+178.23%)
Mutual labels:  markdown, markdown-viewer
Markdown Viewer
Markdown Viewer / Browser Extension
Stars: ✭ 497 (+300.81%)
Mutual labels:  markdown, markdown-viewer
Markdown Viewer
Firefox add-on to view markdown files
Stars: ✭ 146 (+17.74%)
Mutual labels:  markdown, markdown-viewer
Mditor
📝 [ M ] arkdown + E [ ditor ] = Mditor
Stars: ✭ 523 (+321.77%)
Mutual labels:  markdown, markdown-viewer
Markitdown
📱 A React app to preview and edit Markdown✍. You can also export it as HTML.
Stars: ✭ 26 (-79.03%)
Mutual labels:  markdown, markdown-viewer
Macdown
Open source Markdown editor for macOS.
Stars: ✭ 8,855 (+7041.13%)
Mutual labels:  markdown, markdown-viewer
Lookatme
An interactive, terminal-based markdown presenter
Stars: ✭ 392 (+216.13%)
Mutual labels:  markdown, markdown-viewer
Bytemd
A hackable Markdown editor component built with Svelte
Stars: ✭ 656 (+429.03%)
Mutual labels:  markdown, markdown-viewer
Mdmath
LaTeX Math for Markdown inside of Visual Studio Code.
Stars: ✭ 675 (+444.35%)
Mutual labels:  markdown, markdown-viewer
Wemark
微信小程序Markdown渲染库
Stars: ✭ 1,159 (+834.68%)
Mutual labels:  markdown, markdown-viewer
Dataformsjs
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: ✭ 95 (-23.39%)
Mutual labels:  markdown, markdown-viewer
Markdownslides
MarkdownSlides is a Reveal.js and PDF slides generator from MARKDOWN files, that also generate HTML, EPUB and DOCX documents. The idea is that from a same MARKDOWN file we can get slides and books without worrying about style, just worrying about content.
Stars: ✭ 121 (-2.42%)
Mutual labels:  markdown
Pamflet
a publishing application for short texts
Stars: ✭ 117 (-5.65%)
Mutual labels:  markdown
Wp Gfm
WordPress Plugin for PHP-Markdown and GitHub Flavored Markdown
Stars: ✭ 117 (-5.65%)
Mutual labels:  markdown
Patat
Terminal-based presentations using Pandoc
Stars: ✭ 1,725 (+1291.13%)
Mutual labels:  markdown
Lessmd
A small markdown viewer/converter for unix terminal.
Stars: ✭ 122 (-1.61%)
Mutual labels:  markdown
Wwdc Recap
A collection of session summaries in markdown format, from WWDC 20, 19 & 17
Stars: ✭ 121 (-2.42%)
Mutual labels:  markdown
Mook
Markdown editor based on Electron and React
Stars: ✭ 117 (-5.65%)
Mutual labels:  markdown
React Antd Admin
后台前端管理系统,基于react、typescript、antd、dva及一些特别优秀的开源库实现
Stars: ✭ 117 (-5.65%)
Mutual labels:  markdown
Mdx Deck
♠️ React MDX-based presentation decks
Stars: ✭ 10,487 (+8357.26%)
Mutual labels:  markdown

react-code-view

English | 中文版

Why use this component?

Let the code in Markdown run in real time, why is there such a need?

In our front-end team, technical-related documents are written in Markdown. There are often a lot of sample code in the documentation. We hope that when you read the documentation, you can run the sample code to see the rendering interface.

What are the requirements?

  • Let the code in Markdown run and preview.
  • The code can be edited online.
  • Does not affect the layout of the entire document stream.
  • Support React, support code highlighting.
  • Babel can be configured.

After understanding the requirements, I wrote a React component to satisfy these functions, react-code-view , first look at the preview:

preview

Preview: https://simonguo.github.io/react-code-view/

Principle of implementation

  • Parse the Markdown document with markdown-loader and html-loader.
  • Take the code out of the regular expression and give it to codemirror
  • Compile the code in codemirror through babel and render it to the specified container via ReactDOM.render .

Install

npm install react-code-view

Configure webpack .

Support for markdown-loader needs to be added in webpack. Need to install:

npm install html-loader --save-dev
npm install [email protected] --save-dev
npm install [email protected] --save-dev

webpack.config.js

const markdownRenderer = require('react-markdown-reader').renderer;

...
{
  test: /\.md$/,
  use: [{
    loader: 'html-loader'
  }, {
    loader: 'markdown-loader',
    options: {
      renderer: markdownRenderer(/**languages:Array<string>**/)
    }
  }]
}

languages 默认值:["javascript", "bash", "xml", "css", "markdown", "less"];

Add Babel

The sample code usually uses ES2015+, React, etc., and needs to compile the code in real time, so introduce Babel in HTML:

<script
  type="text/javascript"
  src="//cdn.staticfile.org/babel-standalone/6.24.0/babel.min.js"
></script>

If cdn.staticfile.org is not well accessed in your area, you can change other CDN.

Example

import CodeView from 'react-code-view';
import 'react-code-view/lib/less/index.less';

import { Button } from 'rsuite';

<CodeView dependencies={{ Button }}>{require('./example.md')}</CodeView>;

The source code is uniformly written in markdown, reference: example.md

The important thing to note here is that the code that needs to be run must be placed in <!--start-code--> and <!--end-code--> between.

API

Name Type Default value Description
babelTransformOptions Object { presets: ['stage-0', 'react', 'es2015'] } Babel configuration parameters options
dependencies Object Dependent components.
renderToolbar Function Custom toolbar.
showCode boolean true Display code.
theme string 'light' Theme, options light and dark.

Who is using?

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