remark-react
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -0,21 +1,23 @@ | ||
<!--lint disable no-multiple-toplevel-headings--> | ||
# 2.1.0 | ||
* Only allows `http`, `mailto`, and `https` schemes for links. | ||
* Only allows `http`, `mailto`, and `https` schemes for links. | ||
# 2.0.0 | ||
* Update to Remark 4 | ||
* Update to Remark 4 | ||
# 0.3.0 | ||
* Added `mdastReactComponents` option #[9](https://github.com/mapbox/mdast-react/pull/9) | ||
* React 0.14 support #[8](https://github.com/mapbox/mdast-react/pull/8) | ||
* Added `mdastReactComponents` option #[9](https://github.com/mapbox/mdast-react/pull/9) | ||
* React 0.14 support #[8](https://github.com/mapbox/mdast-react/pull/8) | ||
# 0.2.0 | ||
* Support for Markdown footnotes | ||
* Support for Markdown footnotes | ||
# 0.1.2 | ||
* Fix sequential key ordering so that server-side renders | ||
of Markdown will match client-side binding | ||
* Fix sequential key ordering so that server-side renders | ||
of Markdown will match client-side binding |
92
index.js
@@ -7,56 +7,84 @@ 'use strict'; | ||
var compilers = require('./lib/compilers.js'); | ||
var toHAST = require('mdast-util-to-hast'); | ||
var sanitize = require('hast-util-sanitize'); | ||
var toH = require('hast-to-hyperscript'); | ||
try { | ||
var createElement = require('react').createElement; | ||
var globalCreateElement = require('react').createElement; | ||
} catch (e) { } | ||
var own = {}.hasOwnProperty; | ||
var TABLE_ELEMENTS = ['table', 'thead', 'tbody', 'tfoot', 'tr']; | ||
/** | ||
* Attach an HTML compiler. | ||
* Attach a react compiler. | ||
* | ||
* @param {MDAST} remark | ||
* @param {Unified} processor - Instance. | ||
* @param {Object?} [options] | ||
* @param {Object?} [options.sanitize] | ||
* - Sanitation schema. | ||
* @param {Object?} [options.remarkReactComponents] | ||
* - Components. | ||
* @param {string?} [options.prefix] | ||
* - Key prefix. | ||
* @param {Function?} [options.createElement] | ||
* - `h()`. | ||
*/ | ||
function plugin(remark, options) { | ||
var MarkdownCompiler = remark.Compiler; | ||
var ancestor = MarkdownCompiler.prototype; | ||
var proto; | ||
var key; | ||
function plugin(processor, options) { | ||
var settings = options || {}; | ||
var createElement = settings.createElement || globalCreateElement; | ||
var components = settings.remarkReactComponents || {}; | ||
/** | ||
* Extensible prototype. | ||
* Wrapper around `createElement` to pass | ||
* components in. | ||
* | ||
* @param {string} name - Element name. | ||
* @param {Object} props - Attributes. | ||
* @return {ReactElement} - React element. | ||
*/ | ||
function ReactCompilerPrototype() {} | ||
function h(name, props, children) { | ||
var component = own.call(components, name) ? components[name] : name; | ||
ReactCompilerPrototype.prototype = ancestor; | ||
/* | ||
* Currently, a warning is triggered by react for | ||
* *any* white-space in tables. So we remove the | ||
* pretty lines for now: | ||
* https://github.com/facebook/react/pull/7081 | ||
*/ | ||
if (children && TABLE_ELEMENTS.indexOf(name) !== -1) { | ||
children = children.filter(function (child) { | ||
return child !== '\n'; | ||
}); | ||
} | ||
proto = new ReactCompilerPrototype(); | ||
return createElement(name, props, children); | ||
} | ||
proto.options.xhtml = false; | ||
proto.options.sanitize = false; | ||
proto.options.entities = 'true'; | ||
/** | ||
* Extensible constructor. | ||
*/ | ||
function ReactCompiler(file) { | ||
file.extension = 'html'; | ||
function Compiler() {} | ||
MarkdownCompiler.apply(this, [file, options]); | ||
/** | ||
* Compile MDAST to React. | ||
* | ||
* @param {Node} node - MDAST node. | ||
* @return {ReactElement} - React element. | ||
*/ | ||
function compile(node) { | ||
var clean = sanitize({ | ||
type: 'element', | ||
tagName: 'div', | ||
properties: {}, | ||
children: toHAST(node).children | ||
}, settings.sanitize); | ||
this.reactKeyCounter = 0; | ||
return toH(h, clean, settings.prefix); | ||
} | ||
ReactCompiler.prototype = proto; | ||
Compiler.prototype.compile = compile; | ||
/* | ||
* Expose compilers. | ||
*/ | ||
for (key in compilers) { | ||
proto[key] = compilers[key]; | ||
} | ||
proto.createElement = options && options.createElement || createElement; | ||
remark.Compiler = ReactCompiler; | ||
processor.Compiler = Compiler; | ||
} | ||
@@ -63,0 +91,0 @@ |
{ | ||
"name": "remark-react", | ||
"description": "Compile Markdown to React with remark", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"author": { | ||
@@ -9,19 +9,27 @@ "name": "Titus Wormer", | ||
}, | ||
"contributors": [ | ||
"Tom MacWright <tom@macwright.org>", | ||
"Titus Wormer <tituswormer@gmail.com>", | ||
"Ciaran Wood <cyrzinsomnia@gmail.com>", | ||
"Juho Vepsalainen <bebraw@gmail.com>", | ||
"Jason Trill <jason@jasontrill.com>", | ||
"Tsuyusato Kitsune <make.just.on@gmail.com>", | ||
"Jeremy Stucki <jeremy@interactivethings.com>" | ||
], | ||
"dependencies": { | ||
"repeat-string": "^1.5.2" | ||
"hast-to-hyperscript": "^2.0.1", | ||
"hast-util-sanitize": "^1.0.0", | ||
"mdast-util-to-hast": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^13.0.0", | ||
"commonmark.json": "^0.23.0", | ||
"eslint": "^2.2.0", | ||
"esmangle": "^1.0.1", | ||
"istanbul": "^0.4.2", | ||
"jscs": "^2.10.1", | ||
"jscs-jsdoc": "^1.3.1", | ||
"remark": "^4.1.1", | ||
"remark-comment-config": "^3.0.0", | ||
"remark-github": "^4.0.1", | ||
"remark-lint": "^3.0.0", | ||
"jscs": "^3.0.0", | ||
"jscs-jsdoc": "^2.0.0", | ||
"remark": "^5.0.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-toc": "^3.0.0", | ||
"remark-yaml-config": "^3.0.0", | ||
"mocha": "^2.4.5", | ||
@@ -32,3 +40,2 @@ "vfile": "^1.3.1" | ||
"index.js", | ||
"lib/", | ||
"LICENSE" | ||
@@ -44,5 +51,2 @@ ], | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"remark": ">=0.25.0" | ||
}, | ||
"repository": { | ||
@@ -52,2 +56,3 @@ "type": "git", | ||
}, | ||
"bugs": "https://github.com/mapbox/remark-react/issues", | ||
"scripts": { | ||
@@ -62,6 +67,4 @@ "build-md": "remark . --output --quiet", | ||
"test-api": "mocha --check-leaks test/index.js", | ||
"test-coverage": "istanbul cover _mocha -- --check-leaks test/index.js", | ||
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test/index.js", | ||
"test-travis": "npm run sub-install && npm run test-coveralls" | ||
"test-coverage": "istanbul cover _mocha -- --check-leaks test/index.js" | ||
} | ||
} |
@@ -26,4 +26,2 @@ # remark-react | ||
* [Command line](#command-line) | ||
* [Programmatic](#programmatic) | ||
@@ -35,4 +33,2 @@ | ||
* [CommonMark](#commonmark) | ||
* [Integrations](#integrations) | ||
@@ -84,12 +80,14 @@ | ||
* `entities` (`true`, `'numbers'`, or `'escape'`, default: `true`) | ||
— How to encode non-ASCII and HTML-escape characters: the default | ||
generates named entities (`&` > `&`); `'numbers'` generates | ||
numbered entities (`&` > `&`), and `'escape'` only encodes | ||
characters which are required by HTML to be escaped: `&`, `<`, `>`, | ||
`"`, `'`, and `` ` ``, leaving non-ASCII characters untouched. | ||
* `sanitize` (`object`, default: `undefined`) | ||
— Sanitation schema to use. Passed to | ||
[hast-util-sanitize](https://github.com/wooorm/hast-util-sanitize). | ||
The default schema, if none is passed, adheres to GitHub’s sanitation | ||
rules. | ||
* `sanitize` (`boolean`, default: `false`) | ||
— Whether or not to allow the use of HTML inside markdown. | ||
* `prefix` (`string`, default: `h-`) | ||
— React key. | ||
* `createElement` (`Function`, default: `require('react').createElement`) | ||
— Function to use to create elements. | ||
* `remarkReactComponents` (`object`, default: `undefined`) | ||
@@ -100,2 +98,3 @@ — Provides a way to override default elements (`<a>`, `<p>`, etc) | ||
`<a>`, and `<MyParagraph>` instead of `<p>`: | ||
```js | ||
@@ -110,37 +109,2 @@ remarkReactComponents: { | ||
You can define these in `.remarkrc` or `package.json` [files](https://github.com/wooorm/remark/blob/master/doc/remarkrc.5.md) | ||
too. An example `.remarkrc` file could look as follows: | ||
```json | ||
{ | ||
"plugins": { | ||
"react": { | ||
"sanitize": false, | ||
"xhtml": false, | ||
"entities": "numbers" | ||
} | ||
}, | ||
"settings": { | ||
"commonmark": true | ||
} | ||
} | ||
``` | ||
Where the object at `plugins.react` are the options for **remark-react**. | ||
The object at `settings` determines how **remark** parses markdown code. | ||
Read more about the latter on [**remark**’s readme](https://github.com/wooorm/remark#remarkprocessvalue-options-done). | ||
## CommonMark | ||
> You still need to set `commonmark: true` in | ||
> [**remark**’s options](https://github.com/wooorm/remark#remarkprocessvalue-options-done) | ||
[CommonMark](http://commonmark.org) support is a goal but not (yet) a | ||
necessity. There are some (roughly 115 of 550, relating to inline | ||
precedence, lists, emphasis and strongness) issues which I’d like | ||
to cover in the future. Note that this sounds like a lot, but they | ||
have to do with obscure differences which do not often occur in the | ||
real world. Read more on some of the reasoning in | ||
[`doc/commonmark.md`](doc/commonmark.md). | ||
## Integrations | ||
@@ -153,12 +117,8 @@ | ||
* [**remark-github**](https://github.com/wooorm/remark-github), which generates | ||
references to GitHub issues, PRs, users, and more; | ||
* [**remark-github**](https://github.com/wooorm/remark-github), which | ||
generates references to GitHub issues, PRs, users, and more; | ||
* [**remark-comment-config**](https://github.com/wooorm/remark-comment-config) | ||
and [**remark-yaml-config**](https://github.com/wooorm/remark-yaml-config), | ||
which specify how HTML is compiled in the document itself; | ||
* ...and [more](https://github.com/wooorm/remark/blob/master/doc/plugins.md#list-of-plugins). | ||
All [**remark** nodes](https://github.com/wooorm/remark/blob/master/doc/nodes.md) | ||
All [**remark** nodes](https://github.com/wooorm/mdast) | ||
can be compiled to HTML. In addition, **remark-react** looks for an | ||
@@ -165,0 +125,0 @@ `attributes` object on each node it compiles and adds the found properties |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
12
9757
3
5
79
125
1
+ Addedhast-to-hyperscript@^2.0.1
+ Addedhast-util-sanitize@^1.0.0
+ Addedmdast-util-to-hast@^1.0.0
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcollapse-white-space@1.0.6(transitive)
+ Addedcomma-separated-tokens@1.0.8(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddetab@1.0.2(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.3.0(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhast-to-hyperscript@2.1.0(transitive)
+ Addedhast-util-sanitize@1.3.1(transitive)
+ Addedis-nan@1.3.2(transitive)
+ Addedkebab-case@1.0.2(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmdast-util-definitions@1.2.5(transitive)
+ Addedmdast-util-to-hast@1.0.0(transitive)
+ Addednormalize-uri@1.1.3(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedproperty-information@3.2.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedspace-separated-tokens@1.1.5(transitive)
+ Addedtrim@0.0.1(transitive)
+ Addedtrim-lines@1.1.3(transitive)
+ Addedunist-builder@1.0.4(transitive)
+ Addedunist-util-is@2.1.33.0.0(transitive)
+ Addedunist-util-position@2.0.1(transitive)
+ Addedunist-util-visit@1.4.1(transitive)
+ Addedunist-util-visit-parents@2.1.2(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedrepeat-string@^1.5.2
- Removed@types/debug@4.1.12(transitive)
- Removed@types/mdast@4.0.4(transitive)
- Removed@types/ms@2.1.0(transitive)
- Removed@types/unist@3.0.3(transitive)
- Removedbail@2.0.2(transitive)
- Removedcharacter-entities@2.0.2(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddecode-named-character-reference@1.0.2(transitive)
- Removeddequal@2.0.3(transitive)
- Removeddevlop@1.1.0(transitive)
- Removedextend@3.0.2(transitive)
- Removedis-plain-obj@4.1.0(transitive)
- Removedlongest-streak@3.1.0(transitive)
- Removedmdast-util-from-markdown@2.0.2(transitive)
- Removedmdast-util-phrasing@4.1.0(transitive)
- Removedmdast-util-to-markdown@2.1.2(transitive)
- Removedmdast-util-to-string@4.0.0(transitive)
- Removedmicromark@4.0.1(transitive)
- Removedmicromark-core-commonmark@2.0.2(transitive)
- Removedmicromark-factory-destination@2.0.1(transitive)
- Removedmicromark-factory-label@2.0.1(transitive)
- Removedmicromark-factory-space@2.0.1(transitive)
- Removedmicromark-factory-title@2.0.1(transitive)
- Removedmicromark-factory-whitespace@2.0.1(transitive)
- Removedmicromark-util-character@2.1.1(transitive)
- Removedmicromark-util-chunked@2.0.1(transitive)
- Removedmicromark-util-classify-character@2.0.1(transitive)
- Removedmicromark-util-combine-extensions@2.0.1(transitive)
- Removedmicromark-util-decode-numeric-character-reference@2.0.2(transitive)
- Removedmicromark-util-decode-string@2.0.1(transitive)
- Removedmicromark-util-encode@2.0.1(transitive)
- Removedmicromark-util-html-tag-name@2.0.1(transitive)
- Removedmicromark-util-normalize-identifier@2.0.1(transitive)
- Removedmicromark-util-resolve-all@2.0.1(transitive)
- Removedmicromark-util-sanitize-uri@2.0.1(transitive)
- Removedmicromark-util-subtokenize@2.0.4(transitive)
- Removedmicromark-util-symbol@2.0.1(transitive)
- Removedmicromark-util-types@2.0.1(transitive)
- Removedms@2.1.3(transitive)
- Removedremark@15.0.1(transitive)
- Removedremark-parse@11.0.0(transitive)
- Removedremark-stringify@11.0.0(transitive)
- Removedtrough@2.2.0(transitive)
- Removedunified@11.0.5(transitive)
- Removedunist-util-is@6.0.0(transitive)
- Removedunist-util-stringify-position@4.0.0(transitive)
- Removedunist-util-visit@5.0.0(transitive)
- Removedunist-util-visit-parents@6.0.1(transitive)
- Removedvfile@6.0.3(transitive)
- Removedvfile-message@4.0.2(transitive)
- Removedzwitch@2.0.4(transitive)