Skip to content
This repository was archived by the owner on Mar 15, 2023. It is now read-only.
/ marked Public archive
forked from markedjs/marked

Commit dd3a42b

Browse files
committed
Adding inline only parsing as a configuration option
1 parent 88ce4df commit dd3a42b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/marked.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ block.paragraph = replace(block.paragraph)
6464
('def', block.def)
6565
();
6666

67+
/**
68+
* No Block Grammar
69+
*/
70+
71+
block.none = Object.keys(block).reduce(function (obj, key) {
72+
if (key === 'text' || key === '_tag') {
73+
obj[key] = block[key];
74+
} else {
75+
obj[key] = noop;
76+
}
77+
return obj;
78+
}, {});
79+
6780
/**
6881
* Normal Block Grammar
6982
*/
@@ -105,7 +118,9 @@ function Lexer(options) {
105118
this.options = options || marked.defaults;
106119
this.rules = block.normal;
107120

108-
if (this.options.gfm) {
121+
if (this.options.inline) {
122+
this.rules = block.none;
123+
} else if (this.options.gfm) {
109124
if (this.options.tables) {
110125
this.rules = block.tables;
111126
} else {
@@ -1075,7 +1090,7 @@ Parser.prototype.tok = function() {
10751090
return this.renderer.paragraph(this.inline.output(this.token.text));
10761091
}
10771092
case 'text': {
1078-
return this.renderer.paragraph(this.parseText());
1093+
return this.options.inline ? this.parseText() : this.renderer.paragraph(this.parseText());
10791094
}
10801095
}
10811096
};
@@ -1240,6 +1255,7 @@ marked.setOptions = function(opt) {
12401255
marked.defaults = {
12411256
gfm: true,
12421257
tables: true,
1258+
inline: false,
12431259
breaks: false,
12441260
pedantic: false,
12451261
sanitize: false,

0 commit comments

Comments
 (0)