-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTextParser.js
More file actions
30 lines (25 loc) · 1.01 KB
/
TextParser.js
File metadata and controls
30 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* A simple parser that emulates the style of remark-parse, but will only
* parse plain text, not markdown.
*
* Can be used to implement redaction and restoration in a non-markdown context
*
* Is currently implemented by taking remark-parse and removing unwanted
* functionality; be aware that could have unexpected side effects, and we may
* at some point in the future want to reimplement this by starting from
* scratch.
*/
const RemarkParser = require("remark-parse").Parser;
const unherit = require("unherit");
const xtend = require("xtend");
module.exports = function textParse(options) {
const settings = this.data("settings");
const Local = unherit(RemarkParser);
Local.prototype.options = xtend(Local.prototype.options, settings, options);
// Limit tokenizers to only those that parse plain text, not any markdown
// syntax
Local.prototype.blockMethods = ["newline", "paragraph"];
Local.prototype.inlineMethods = ["text"];
Local.prototype.interruptParagraph = [];
this.Parser = Local;
};