• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Markdown to React Component converter

Markdown React

Markdown to React Component converter.

This project uses Markdown parser from Markdown It library, but loosely supports its plugins.

DEMO: http://alexkuz.github.io/markdown-react-js/

Install

npm i markdown-react-js

Examples

Basic example

import MDReactComponent from 'markdown-react-js';

render() {
  return (
    <MDReactComponent text='Some text **with emphasis**.' />   
  );
}

or, using function instead of component:

import { mdReact } from 'markdown-react-js';

render() {
  return mdReact()('Some text **with emphasis**.');
}

Result:

<span>
  <p>
    Some text with <strong>emphasis</strong>.
  </p>
</span>

Using custom tags

const TAGS = {
  html: 'span', // root node, replaced by default
  strong: 'b',
  em: 'i'
}

render() {
  return (
    <MDReactComponent text='Some **bold** and *italic* text.' tags={TAGS} />   
  );
}

Result:

<span>
  <p>
    Some <b>bold</b> and <i>italic</i> text.
  </p>
</span>

Using custom component renderer

function handleIterate(Tag, props, children, level) {
  if (level === 1) {
    props = {
      ...props,
      className: 'first-level-class'
    };
  }
  
  if (Tag === 'a') {
    props = {
      ...props,
      className: 'link-class',
      href: props.href.replace('SOME_URL', 'http://example.com')
    };
  }
  
  return <Tag {...props}>{children}</Tag>;
}

render() {
  return (
    <MDReactComponent text='[This link](SOME_URL) has it’s own style.' onIterate={handleIterate} />   
  );
}

Result:

<span>
  <p class="first-level-class">
    <a href="http://example.com" class="link-class">This link</a> has it’s own style.
  </p>
</span>

Copyright

Copyright 2015, Alexander Kuznetsov <[email protected]>

Markdown-It:

Copyright (c) 2014 Vitaly Puzrin <[email protected]>, Alex Kocharin <[email protected]>

More Repositories

1

react-input-enhancements

Set of enhancements for input control
JavaScript
1,376
star
2

react-json-tree

React JSON Viewer Component, Extracted from redux-devtools
JavaScript
992
star
3

react-dock

Resizable dockable react component
JavaScript
544
star
4

webpack-chart

Webpack Chart
JavaScript
437
star
5

cake-chart

Interactive multi-layer pie chart
JavaScript
426
star
6

flask-react-boilerplate

JavaScript
368
star
7

redux-devtools-inspector

Another Redux DevTools Monitor
JavaScript
240
star
8

script-progress

Estimate script execution time
JavaScript
177
star
9

nyan-progress-webpack-plugin

Meow
JavaScript
172
star
10

stellar-webpack

A little experiment
JavaScript
92
star
11

redux-pagan

managing internationalization via redux
JavaScript
78
star
12

restore-source-tree

Restores file structure from source map
JavaScript
62
star
13

additive-animation

Additive animation npm module
JavaScript
46
star
14

react-transform-debug-inspector

React inspector tranformation function for babel-plugin-wrap-react-components
JavaScript
29
star
15

react-base16-styling

React styling with base16 color scheme support
JavaScript
21
star
16

export-files-webpack-plugin

Exports files to FS (even in devserver mode)
JavaScript
17
star
17

SublimeLinter-inline-errors

Shows linting errors inline with Phantom API
Python
15
star
18

react-bootstrap-breadcrumbs

Breadcrumbs for React-Router and Bootstrap
JavaScript
15
star
19

react-pagan

JavaScript
14
star
20

jss-css

JavaScript
14
star
21

Tomato

Pebble pomodoro app
C
7
star
22

pg_unidecode

Postgres Unidecode extension
C
7
star
23

git-swap

Interactive, pure-shell menu for switching between git branches
Shell
5
star
24

sublime-bun

Bun binary files viewer and other Bun-related stuff
Python
5
star
25

sublime-yarn-lock

Syntax highlighting for yarn.lock and bun.lockb files
4
star
26

shittify-js

So you can honestly say your code is full of shit
JavaScript
4
star
27

babel-plugin-jss-css

JavaScript
4
star
28

svg-flag-editor

Online tool for editing flag svg image source
JavaScript
2
star
29

react-component-boilerplate

React component template
JavaScript
2
star
30

tslint-no-commented-code-rule

TSLint rule that bans commented code
TypeScript
2
star
31

sqlalchemy-flux-serializer

Serialize sqlalchemy models into flux-friendly json
Python
2
star
32

nodejs-dashboard-layout-progress

Layout for nodejs-dashboard with progress and status
JavaScript
2
star
33

alexkuz

HTML
2
star
34

eslint-plugin-jinja

This plugin treats Jinja template expressions as Javascript literals and ignores template statements and comments
JavaScript
2
star
35

mono-coffeescript-addin

CoffeeScript language addin for MonoDevelop
C#
1
star
36

custom-stickers

Python
1
star
37

SublimeLinter-contrib-zig-check

SublimeLinter plugin for Zig built-in linter (zig ast-check)
Python
1
star
38

alexkuz.github.io

HTML
1
star
39

bun-playground

Test repo to reproduce bun errors
TypeScript
1
star
40

python-rust-dprint

JavaScript
1
star
41

wds-ws-proxy-example

JavaScript
1
star
42

next-netlify-starter

JavaScript
1
star
43

nextjs-netlify-blog-template

TypeScript
1
star
44

shell-menu

Shell function for interactive menu
Shell
1
star
45

promisegate

Limits promise concurrency
JavaScript
1
star
46

micro-flag-icons

Collection of minimal country flag svg images
HTML
1
star