-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow disabling tokenizers (#119)
[<img height=20 src=https://readme.com/static/favicon.ico align=center>][demo] | RM-215 :---:|:---: ## 🧰 Changes Adds the option of disabling tokenizers. This is in service of the editor's markdown decorators. During deserialization, we can leave the inlines as plain text. Then, during the decoration step, we can parse the markdown with just the inline tokenizers. ## Usage ``` const opts = { tokenizerSet: 'blocks' }; markdown.mdast(md, opts); // won't parse inline code, emphasis, etc. ``` [demo]: https://markdown-pr-119.herokuapp.com
- Loading branch information
1 parent
3c823f1
commit 0418a05
Showing
15 changed files
with
356 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`disableTokenizers: "blocks" disabling block tokenizer 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "# heading 1", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`disableTokenizers: "inlines" disabling delete 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "~~strikethrough~~", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`disableTokenizers: "inlines" disabling emphasis 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "*emphatic **strong** emphatic*", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`disableTokenizers: "inlines" disabling inlineCode 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "\`const js = true \`", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`a bare autoLinked url 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "http://www.googl.com", | ||
}, | ||
], | ||
"title": null, | ||
"type": "link", | ||
"url": "http://www.googl.com", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`a bare autoLinked url with no protocol 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "www.google.com", | ||
}, | ||
], | ||
"title": null, | ||
"type": "link", | ||
"url": "http://www.google.com", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`a bracketed autoLinked url 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "http://www.google.com", | ||
}, | ||
], | ||
"title": null, | ||
"type": "link", | ||
"url": "http://www.google.com", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`a link ref 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "link", | ||
}, | ||
], | ||
"identifier": "link", | ||
"label": "link", | ||
"referenceType": "shortcut", | ||
"type": "linkReference", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`a link with label 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"type": "text", | ||
"value": "link", | ||
}, | ||
], | ||
"title": null, | ||
"type": "link", | ||
"url": "http://www.foo.com", | ||
}, | ||
], | ||
"type": "paragraph", | ||
}, | ||
], | ||
"type": "root", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const markdown = require('../index'); | ||
|
||
describe('disableTokenizers: "inlines"', () => { | ||
const opts = { disableTokenizers: 'inlines' }; | ||
|
||
it('disabling inlineCode', () => { | ||
const md = '`const js = true `'; | ||
expect(markdown.mdast(md, opts)).toMatchSnapshot(); | ||
}); | ||
|
||
it('disabling emphasis', () => { | ||
const md = '*emphatic **strong** emphatic*'; | ||
expect(markdown.mdast(md, opts)).toMatchSnapshot(); | ||
}); | ||
|
||
it('disabling delete', () => { | ||
const md = '~~strikethrough~~'; | ||
expect(markdown.mdast(md, opts)).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('disableTokenizers: "blocks"', () => { | ||
const opts = { disableTokenizers: 'blocks' }; | ||
|
||
it('disabling block tokenizer', () => { | ||
const md = '# heading 1'; | ||
expect(markdown.mdast(md, opts)).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const markdown = require('../index'); | ||
|
||
test('a link with label', () => { | ||
expect(markdown.mdast('[link](http://www.foo.com)')).toMatchSnapshot(); | ||
}); | ||
|
||
test('a link ref', () => { | ||
expect(markdown.mdast('[link]')).toMatchSnapshot(); | ||
}); | ||
|
||
test('a bracketed autoLinked url', () => { | ||
expect(markdown.mdast('<http://www.google.com>')).toMatchSnapshot(); | ||
}); | ||
|
||
test('a bare autoLinked url', () => { | ||
expect(markdown.mdast('http://www.googl.com')).toMatchSnapshot(); | ||
}); | ||
|
||
test.skip('a bare autoLinked url with no protocol', () => { | ||
expect(markdown.mdast('www.google.com')).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.