remark-react
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -0,1 +1,11 @@ | ||
<a name="3.1.1"></a> | ||
## [3.1.1](https://github.com/mapbox/remark-react/compare/v3.1.0...v3.1.1) (2017-03-07) | ||
### Bug Fixes | ||
* **output:** Remove unknown prop 'align' ([e0462f1](https://github.com/mapbox/remark-react/commit/e0462f1)) | ||
<!--lint disable no-multiple-toplevel-headings--> | ||
@@ -5,9 +15,9 @@ | ||
* Adds `toHast` option that allows customization at the [mdast-util-to-hast](https://github.com/wooorm/mdast-util-to-hast#api) | ||
level. | ||
* Adds `toHast` option that allows customization at the [mdast-util-to-hast](https://github.com/wooorm/mdast-util-to-hast#api) | ||
level. | ||
# 3.0.2 | ||
* Fixes interpretation of the `sanitize` option, allowing users to pass | ||
`false` to disable sanitization. | ||
* Fixes interpretation of the `sanitize` option, allowing users to pass | ||
`false` to disable sanitization. | ||
@@ -14,0 +24,0 @@ # 2.1.0 |
137
index.js
'use strict'; | ||
/* | ||
* Dependencies. | ||
*/ | ||
module.exports = remarkReact; | ||
@@ -10,6 +8,9 @@ var toHAST = require('mdast-util-to-hast'); | ||
var toH = require('hast-to-hyperscript'); | ||
var xtend = require('xtend'); | ||
var globalCreateElement; | ||
try { | ||
var globalCreateElement = require('react').createElement; | ||
} catch (e) { } | ||
globalCreateElement = require('react').createElement; | ||
} catch (err) {} | ||
@@ -34,71 +35,79 @@ var own = {}.hasOwnProperty; | ||
*/ | ||
function plugin(processor, options) { | ||
var settings = options || {}; | ||
var createElement = settings.createElement || globalCreateElement; | ||
var components = settings.remarkReactComponents || {}; | ||
var clean = settings.sanitize !== false; | ||
var scheme = clean && (typeof settings.sanitize !== 'boolean') ? settings.sanitize : null; | ||
var toHastOptions = settings.toHast || {}; | ||
function remarkReact(options) { | ||
var settings = options || {}; | ||
var createElement = settings.createElement || globalCreateElement; | ||
var clean = settings.sanitize !== false; | ||
var scheme = clean && (typeof settings.sanitize !== 'boolean') ? settings.sanitize : null; | ||
var toHastOptions = settings.toHast || {}; | ||
var components = xtend({ | ||
td: createTableCellComponent('td'), | ||
th: createTableCellComponent('th') | ||
}, settings.remarkReactComponents); | ||
/** | ||
* Wrapper around `createElement` to pass | ||
* components in. | ||
* | ||
* @param {string} name - Element name. | ||
* @param {Object} props - Attributes. | ||
* @return {ReactElement} - React element. | ||
*/ | ||
function h(name, props, children) { | ||
var component = own.call(components, name) ? components[name] : name; | ||
this.Compiler = compile; | ||
/* | ||
* 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(component) !== -1) { | ||
children = children.filter(function (child) { | ||
return child !== '\n'; | ||
}); | ||
} | ||
/** | ||
* Wrapper around `createElement` to pass | ||
* components in. | ||
* | ||
* @param {string} name - Element name. | ||
* @param {Object} props - Attributes. | ||
* @return {ReactElement} - React element. | ||
*/ | ||
function h(name, props, children) { | ||
var component = own.call(components, name) ? components[name] : name; | ||
return createElement(component, props, children); | ||
/* | ||
* 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(component) !== -1) { | ||
children = children.filter(function (child) { | ||
return child !== '\n'; | ||
}); | ||
} | ||
/** | ||
* Extensible constructor. | ||
*/ | ||
function Compiler() {} | ||
return createElement(component, props, children); | ||
} | ||
/** | ||
* Compile MDAST to React. | ||
* | ||
* @param {Node} node - MDAST node. | ||
* @return {ReactElement} - React element. | ||
*/ | ||
function compile(node) { | ||
var hast = { | ||
type: 'element', | ||
tagName: 'div', | ||
properties: {}, | ||
children: toHAST(node, toHastOptions).children | ||
}; | ||
/** | ||
* Compile MDAST to React. | ||
* | ||
* @param {Node} node - MDAST node. | ||
* @return {ReactElement} - React element. | ||
*/ | ||
function compile(node) { | ||
var hast = { | ||
type: 'element', | ||
tagName: 'div', | ||
properties: {}, | ||
children: toHAST(node, toHastOptions).children | ||
}; | ||
if (clean) { | ||
hast = sanitize(hast, scheme); | ||
} | ||
return toH(h, hast, settings.prefix); | ||
if (clean) { | ||
hast = sanitize(hast, scheme); | ||
} | ||
Compiler.prototype.compile = compile; | ||
return toH(h, hast, settings.prefix); | ||
} | ||
processor.Compiler = Compiler; | ||
/** | ||
* Create a functional React component for a cell. | ||
* We need this because GFM uses `align`, whereas React | ||
* forbids that and wants `style.textAlign` instead. | ||
*/ | ||
function createTableCellComponent(tagName) { | ||
return TableCell; | ||
function TableCell(props) { | ||
const fixedProps = xtend(props, { | ||
children: undefined, | ||
style: {textAlign: props.align} | ||
}); | ||
delete fixedProps.align; | ||
return createElement(tagName, fixedProps, props.children); | ||
} | ||
} | ||
} | ||
/* | ||
* Expose `plugin`. | ||
*/ | ||
module.exports = plugin; |
{ | ||
"name": "remark-react", | ||
"description": "Compile Markdown to React with remark", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"author": { | ||
@@ -21,17 +21,18 @@ "name": "Titus Wormer", | ||
"hast-util-sanitize": "^1.0.0", | ||
"mdast-util-to-hast": "^1.0.0" | ||
"mdast-util-to-hast": "^2.0.0", | ||
"standard-changelog": "^0.0.1", | ||
"xtend": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"commonmark.json": "^0.23.0", | ||
"eslint": "^2.2.0", | ||
"istanbul": "^0.4.2", | ||
"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", | ||
"mocha": "^2.4.5", | ||
"vfile": "^1.3.1" | ||
"cz-conventional-changelog": "^2.0.0", | ||
"mocha": "^3.1.0", | ||
"nyc": "^10.1.2", | ||
"remark": "^7.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-github": "^7.0.0", | ||
"remark-preset-lint-consistent": "^2.0.0", | ||
"remark-preset-lint-recommended": "^2.0.0", | ||
"remark-toc": "^4.0.0", | ||
"vfile": "^2.0.0", | ||
"xo": "^0.17.1" | ||
}, | ||
@@ -56,12 +57,49 @@ "files": [ | ||
"scripts": { | ||
"build-md": "remark . --output --quiet", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"make": "npm run lint && npm run test-coverage", | ||
"sub-install": "cd test/react/v0.14 && npm install && cd ../..", | ||
"test": "npm run sub-install && npm run test-api", | ||
"build": "remark *.md --output --quiet --frail", | ||
"changelog": "standard-changelog -i history.md --overwrite", | ||
"lint": "xo", | ||
"test-api": "mocha --check-leaks test/index.js", | ||
"test-coverage": "istanbul cover _mocha -- --check-leaks test/index.js" | ||
"test-coverage": "nyc --reporter lcov mocha test/index.js", | ||
"test": "npm run build && npm run lint && npm run sub-install && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"xo": { | ||
"space": true, | ||
"rules": { | ||
"import/no-extraneous-dependencies": "off", | ||
"import/no-unresolved": "off", | ||
"import/no-dynamic-require": "off", | ||
"max-nested-callbacks": "off", | ||
"no-eq-null": "off", | ||
"eqeqeq": [ | ||
"error", | ||
"always", | ||
{ | ||
"null": "ignore" | ||
} | ||
] | ||
} | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-lint-recommended", | ||
"preset-lint-consistent", | ||
"github", | ||
"toc" | ||
], | ||
"settings": { | ||
"bullet": "*" | ||
} | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
@@ -65,3 +65,3 @@ # remark-react | ||
<div id='preview'> | ||
{remark().use(reactRenderer).process(this.state.text).contents} | ||
{remark().use(reactRenderer).processSync(this.state.text).contents} | ||
</div> | ||
@@ -104,2 +104,8 @@ </div>); | ||
Note: as GFM uses `align` on `td` and `th`, and React doesn’t like that, | ||
we [overwrite](https://github.com/mapbox/remark-react/blob/master/index.js#L94) | ||
them through `remarkReactComponents` to use `style.textAlign` instead. | ||
This means that if you set `td` or `td`, you’ll need to handle `align` | ||
yourself. | ||
* `toHast` (`object`, default: `{}`) | ||
@@ -129,4 +135,7 @@ — Provides options for transforming MDAST document to HAST. | ||
Additionally, syntax highlighting can be included (completely virtual) with | ||
[`remark-react-lowlight`](https://github.com/bebraw/remark-react-lowlight). | ||
## License | ||
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com), modified by [Tom MacWright](http://www.macwright.org/) and [Mapbox](https://www.mapbox.com/) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12360
11
95
139
5
1
+ Addedstandard-changelog@^0.0.1
+ Addedxtend@^4.0.1
+ AddedJSONStream@1.3.5(transitive)
+ Addedadd-stream@1.0.0(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedarray-ify@1.0.0(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedcamelcase@2.1.14.1.0(transitive)
+ Addedcamelcase-keys@2.1.04.2.0(transitive)
+ Addedcompare-func@1.3.4(transitive)
+ Addedconventional-changelog-angular@0.1.0(transitive)
+ Addedconventional-changelog-core@0.0.2(transitive)
+ Addedconventional-changelog-writer@0.4.2(transitive)
+ Addedconventional-commits-filter@0.1.1(transitive)
+ Addedconventional-commits-parser@0.1.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddargs@4.1.0(transitive)
+ Addeddateformat@1.0.12(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addeddetab@2.0.4(transitive)
+ Addeddot-prop@3.0.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.22.1.0(transitive)
+ Addedget-pkg-repo@0.1.0(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedgit-raw-commits@0.1.2(transitive)
+ Addedgit-semver-tags@1.3.6(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhandlebars@4.7.8(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.03.2.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-obj@1.0.1(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedis-subset@0.1.1(transitive)
+ Addedis-text-path@1.0.1(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjson-parse-better-errors@1.0.2(transitive)
+ Addedjsonparse@1.3.1(transitive)
+ Addedload-json-file@1.1.04.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedlodash@3.10.14.17.21(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basetostring@3.0.1(transitive)
+ Addedlodash._basevalues@3.0.0(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash._reinterpolate@3.0.0(transitive)
+ Addedlodash._root@3.0.1(transitive)
+ Addedlodash.escape@3.2.0(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addedlodash.template@3.6.2(transitive)
+ Addedlodash.templatesettings@3.1.1(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.12.0.0(transitive)
+ Addedmdast-util-to-hast@2.5.0(transitive)
+ Addedmdurl@1.0.1(transitive)
+ Addedmeow@3.7.04.0.1(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedminimist-options@3.0.2(transitive)
+ Addedmodify-values@1.0.1(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedparse-json@2.2.04.0.0(transitive)
+ Addedpath-exists@2.1.03.0.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.03.0.0(transitive)
+ Addedpify@2.3.03.0.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedq@1.5.1(transitive)
+ Addedquick-lru@1.1.0(transitive)
+ Addedread-pkg@1.1.03.0.0(transitive)
+ Addedread-pkg-up@1.0.13.0.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedredent@1.0.02.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedsplit@1.0.1(transitive)
+ Addedsplit2@1.1.1(transitive)
+ Addedstandard-changelog@0.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-bom@2.0.03.0.0(transitive)
+ Addedstrip-indent@1.0.12.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtempfile@1.1.1(transitive)
+ Addedtext-extensions@1.9.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtrim-newlines@1.0.02.0.0(transitive)
+ Addedtrim-off-newlines@1.0.3(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedunist-util-generated@1.1.6(transitive)
+ Addedunist-util-position@3.1.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addeduuid@2.0.3(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwordwrap@1.0.0(transitive)
- Removeddetab@1.0.2(transitive)
- Removedmdast-util-to-hast@1.0.0(transitive)
- Removednormalize-uri@1.1.3(transitive)
- Removedunist-util-position@2.0.1(transitive)
Updatedmdast-util-to-hast@^2.0.0