├── .babelrc
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── dist
└── markdown-react.min.js
├── package.json
├── src
└── index.js
├── test
├── elements.spec.js
├── helpers
│ └── render.js
├── mocha.opts
├── plugins-offical.js
└── react-options.spec.js
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "react", "stage-1"]
3 | }
4 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
3 | lib/
4 | coverage/
5 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser" : "babel-eslint",
3 | "extends" : [
4 | "standard",
5 | "standard-react"
6 | ],
7 | "env" : {
8 | "browser" : true,
9 | "node": true
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # node-waf configuration
20 | .lock-wscript
21 |
22 | # Compiled binary addons (http://nodejs.org/api/addons.html)
23 | build/Release
24 |
25 | # Dependency directory
26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27 | node_modules
28 | lib
29 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | sudo: false
3 | node_js:
4 | - 4
5 | - 5
6 |
7 | matrix:
8 | fast_finish: true
9 |
10 | script:
11 | - npm run lint
12 | - npm test
13 |
14 | after_success:
15 | - npm run codecov
16 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ### Under the hood
2 |
3 | - Break up tests into files
4 |
5 | # 0.1.1 - 2016-02-07
6 |
7 | - Fixed: Remove warning about void tag with children
8 | in React 0.14 with ``, `
`, `
42 | Some text with emphasis. 43 |
44 | 45 | ``` 46 | 47 | #### Using custom tags 48 | 49 | ```js 50 | const TAGS = { 51 | html: 'span', // root node, replaced by default 52 | strong: 'b', 53 | em: 'i' 54 | } 55 | 56 | ... 57 | 58 | render() { 59 | return ( 60 |70 | Some bold and italic text. 71 |
72 | 73 | 74 | ``` 75 | 76 | #### Using custom component renderer 77 | 78 | ```js 79 | function handleIterate(Tag, props, children, level) { 80 | if (level === 1) { 81 | props = { 82 | ...props, 83 | className: 'first-level-class' 84 | }; 85 | } 86 | 87 | if (Tag === 'a') { 88 | props = { 89 | ...props, 90 | className: 'link-class', 91 | href: props.href.replace('SOME_URL', 'http://example.com') 92 | }; 93 | } 94 | 95 | return112 | This link has it’s own style. 113 |
114 | 115 | 116 | ``` 117 | 118 | # Copyright 119 | 120 | Forked from 121 | - [markdown-react-js](https://github.com/alexkuz/markdown-react-js) 122 | Copyright 2015 Alexander Kuznetsov"+s(t[e].content)+"
"},a.code_block=function(t,e){return""+s(t[e].content)+"
\n"},a.fence=function(t,e,r,n,o){var a,u=t[e],c=u.info?i(u.info).trim():"",l="";return c&&(l=c.split(/\s+/g)[0],u.attrJoin("class",r.langPrefix+l)),a=r.highlight?r.highlight(u.content,l)||s(u.content):s(u.content),0===a.indexOf(""+a+"
\n"},a.image=function(t,e,r,n,o){var i=t[e];return i.attrs[i.attrIndex("alt")][1]=o.renderInlineAsText(i.children,r,n),o.renderToken(t,e,r)},a.hardbreak=function(t,e,r){return r.xhtmlOut?"some text
' 10 | ) 11 | }) 12 | 13 | it('should set root element inline style to styles provided in style property', () => { 14 | assert.equal( 15 | render('some text', { style: { color: 'red', fontSize: 20 } }), 16 | 'some text
' 17 | ) 18 | }) 19 | 20 | it('should not throw warning with void tags', () => { 21 | assert.equal( 22 | render('# Title\n---'), 23 | 'This text will be italic\nThis will also be italic
This text will be bold\nThis will also be bold
You can combine them
' 38 | ) 39 | }) 40 | 41 | it('should work with unordered lists', () => { 42 | assert.equal( 43 | render('* Item 1\n* Item 2\n * Item 2a\n * Item 2b'), 44 | '\nFormat:
Here is some link.
' 66 | ) 67 | }) 68 | 69 | it('should work with blockquotes', () => { 70 | assert.equal( 71 | render('As Kanye West said:\n\n> We\'re living the future so\n> the present is our past.'), 72 | 'As Kanye West said:
' 73 | ) 74 | }) 75 | 76 | it('should work with inline code', () => { 77 | assert.equal( 78 | render('I think you should use an `We're living the future so\nthe present is our past.
I think you should use an <addr>
element here instead.
Option | Description |
---|---|
data | path to data files to supply the data that will be passed into templates. |
engine | engine to be used for processing templates. Handlebars is the default. |
ext | extension to be used for dest files. |
Indented code
// Some comments\nline 1 of code\nline 2 of code\nline 3 of code
'
94 | )
95 | })
96 |
97 | it('should work with block code', () => {
98 | assert.equal(
99 | render('Block code "fences"\n\n```\nSample text here...\n```\n'),
100 | 'Block code "fences"
Sample text here...\n
'
101 | )
102 | })
103 |
104 | it('should work with highlighted code', () => {
105 | assert.equal(
106 | render('Syntax highlighting\n\n``` js\nvar foo = function (bar) {\n return bar++;\n};\n\nconsole.log(foo(5));\n```'),
107 | 'Syntax highlighting
var foo = function (bar) {\n return bar++;\n};\n\nconsole.log(foo(5));\n
'
108 | )
109 | })
110 |
111 | it('should work with enabled typographer', () => {
112 | assert.equal(
113 | render('## Typographic replacements\n\nEnable typographer option to see result.\n\n(c) (C) (r) (R) (tm) (TM) (p) (P) +-\n\ntest.. test... test..... test?..... test!....\n\n!!!!!! ???? ,, -- ---\n\n"Smartypants, double quotes" and \'single quotes\'',
114 | {markdownOptions: {typographer: true}}),
115 | 'Enable typographer option to see result.
© © ® ® ™ ™ § § ±
test… test… test… test?.. test!..
!!! ??? , – —
“Smartypants, double quotes” and ‘single quotes’
' 116 | ) 117 | }) 118 | 119 | it('should work with disabled typographer', () => { 120 | assert.equal( 121 | render('## Typographic replacements\n\nEnable typographer option to see result.\n\n(c) (C) (r) (R) (tm) (TM) (p) (P) +-\n\ntest.. test... test..... test?..... test!....\n\n!!!!!! ???? ,, -- ---\n\n"Smartypants, double quotes" and \'single quotes\'', 122 | {markdownOptions: {typographer: false}}), 123 | 'Enable typographer option to see result.
(c) (C) (r) (R) (tm) (TM) (p) (P) +-
test.. test... test..... test?..... test!....
!!!!!! ???? ,, -- ---
"Smartypants, double quotes" and 'single quotes'
' 124 | ) 125 | }) 126 | }) 127 | -------------------------------------------------------------------------------- /test/helpers/render.js: -------------------------------------------------------------------------------- 1 | import { mdReact } from '../../src/index' 2 | import { renderToStaticMarkup } from 'react-dom/server' 3 | 4 | const render = (text, options) => { 5 | return renderToStaticMarkup(mdReact(options)(text)) 6 | } 7 | 8 | export default render 9 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --recursive 3 | --timeout 3000 4 | -------------------------------------------------------------------------------- /test/plugins-offical.js: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import { describe, it } from 'mocha' 3 | import render from './helpers/render' 4 | 5 | const plugins = { 6 | abbr: require('markdown-it-abbr'), 7 | container: require('markdown-it-container'), 8 | deflist: require('markdown-it-deflist'), 9 | emoji: require('markdown-it-emoji'), 10 | footnote: require('markdown-it-footnote'), 11 | ins: require('markdown-it-ins'), 12 | mark: require('markdown-it-mark'), 13 | sub: require('markdown-it-sub'), 14 | sup: require('markdown-it-sup') 15 | } 16 | 17 | describe('Markdown plugins official', () => { 18 | it('should work with emoji', () => { 19 | assert.equal( 20 | render(':) 8-)', 21 | {plugins: [plugins.emoji]}), 22 | '😃 😎
' 23 | ) 24 | }) 25 | 26 | it('should work with container', () => { 27 | assert.equal( 28 | render('::: warning\n*here be dragons*\n:::', 29 | {plugins: [{plugin: plugins.container, args: ['warning']}]}), 30 | 'here be dragons
Here is some link with class.
' 34 | ) 35 | }) 36 | 37 | it('should distinct tags depending on level', () => { 38 | assert.equal( 39 | render('This node has custom class, **but not this node**.', { onIterate: firstLevelCallback }), 40 | 'This node has custom class, but not this node.
' 41 | ) 42 | }) 43 | 44 | it('should replace tags', () => { 45 | assert.equal( 46 | render('This text uses **“i” and “b” tags** instead of *“em” and “strong” tags*.', {tags: { 'html': 'span', 'em': 'i', 'strong': 'b' }}), 47 | 'This text uses “i” and “b” tags instead of “em” and “strong” tags.
' 48 | ) 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack') 2 | 3 | module.exports = { 4 | entry: './src/index', 5 | module: { 6 | loaders: [ 7 | { test: /\.json$/, loader: 'json' }, 8 | { test: /\.js$/, loader: 'babel', exclude: /node_modules/ } 9 | ] 10 | }, 11 | output: { 12 | filename: 'dist/markdown-react.min.js', 13 | libraryTarget: 'umd', 14 | library: 'MarkdownReact' 15 | }, 16 | plugins: [ 17 | new webpack.optimize.OccurenceOrderPlugin(), 18 | new webpack.DefinePlugin({ 19 | 'process.env': { 20 | 'NODE_ENV': JSON.stringify('production') 21 | } 22 | }), 23 | new webpack.optimize.UglifyJsPlugin({ 24 | compressor: { 25 | warnings: false 26 | } 27 | }) 28 | ], 29 | externals: { 30 | react: 'React' 31 | } 32 | } 33 | --------------------------------------------------------------------------------