$ cnpm install remark-react-lowlight
remark-react-lowlight
remark-react
through lowlight
Usage:
...
import remark from 'remark';
import reactRenderer from 'remark-react';
import RemarkLowlight from 'remark-react-lowlight';
import js from 'highlight.js/lib/languages/javascript';
import githubSchema from 'hast-util-sanitize/lib/github.json';
const schema = Object.assign({}, githubSchema, {
attributes: Object.assign({}, githubSchema.attributes, {
code: [
...(githubSchema.attributes.code || []),
'className'
]
})
});
...
{remark().use(reactRenderer, {
sanitize: schema,
remarkReactComponents: {
code: RemarkLowlight({
js
})
}
}).processSync(readme).contents}
...
Notes
className
, but we want those hljs-*
classes for our highlighting! Hence the custom object passed to santization
.props
for the lowlight component.MIT.
Copyright 2014 - 2017 © taobao.org |