Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat/allow-disabling-tokenizers
  • Loading branch information
kellyjosephprice committed Jan 30, 2021
commit a5ab811e4cec65b08fc68b07ac2e72e9b8d8b4a5
35 changes: 35 additions & 0 deletions __tests__/__snapshots__/disabling-tokenizers.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`disabling emphasis 1`] = `
Object {
"children": Array [
Object {
"children": Array [
Object {
"type": "text",
"value": "*emphatic **strong** emphatic*",
},
],
"type": "paragraph",
},
],
"type": "root",
}
`;

exports[`disabling inlineCode 1`] = `
Object {
"children": Array [
Object {
"children": Array [
Object {
"type": "text",
"value": "\`const js = true \`",
},
],
"type": "paragraph",
},
],
"type": "root",
}
`;
15 changes: 15 additions & 0 deletions __tests__/disabling-tokenizers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const markdown = require('../index');

test('disabling inlineCode', () => {
const md = '`const js = true `';
const opts = { disableTokenizers: { inline: ['code'] } };

expect(markdown.mdast(md, opts)).toMatchSnapshot();
});

test('disabling emphasis', () => {
const md = '*emphatic **strong** emphatic*';
const opts = { disableTokenizers: { inline: ['emphasis', 'strong'] } };

expect(markdown.mdast(md, opts)).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const remarkStringify = require('remark-stringify');
const remarkBreaks = require('remark-breaks');
const remarkSlug = require('remark-slug');
const remarkFrontmatter = require('remark-frontmatter');
const remarkDisableTokenizers = require('remark-disable-tokenizers');

// rehype plugins
const rehypeSanitize = require('rehype-sanitize');
Expand Down Expand Up @@ -110,6 +111,7 @@ export function processor(opts = {}) {
* - sanitize and remove any disallowed attributes
* - output the hast to a React vdom with our custom components
*/

return unified()
.use(remarkParse, opts.markdownOptions)
.use(remarkFrontmatter, ['yaml', 'toml'])
Expand All @@ -118,6 +120,7 @@ export function processor(opts = {}) {
.use(!opts.correctnewlines ? remarkBreaks : () => {})
.use(customParsers)
.use(remarkSlug)
.use(remarkDisableTokenizers, opts.disableTokenizers)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeSanitize, sanitize);
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"rehype-sanitize": "^3.0.1",
"rehype-stringify": "^6.0.0",
"remark-breaks": "^1.0.0",
"remark-disable-tokenizers": "^1.0.24",
"remark-frontmatter": "^2.0.0",
"remark-parse": "^7.0.2",
"remark-rehype": "^7.0.0",
Expand Down