-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to disable a feature of marked? #420
Comments
If you just need to hide them, replace the heading renderer with an empty function. |
@Feder1co5oave I was able to disable headers with the following: var renderer = new marked.Renderer();
renderer.heading = function (text, level) {
return text;
} But like you said, the hash is removed. Modifying the source is not desirable. |
I think I found a way. You've got to play a bit with a Lexer object: > var marked = require('marked'),
... options = { /* ... */ },
... lexer = new marked.Lexer(options);
undefined
> lexer.rules.heading = { exec: function() {} };
{ exec: [Function] }
> marked.parser(lexer.lex('# heading?'), options)
'<p># heading?</p>\n' You create a lexer, disable the |
@Feder1co5oave This works very well! Much better than my solution of creating a regex that would never match anything. lexer.rules.heading = /(a^) (a^) (a^)/; Yours will probably perform better because it is effectively a noop. |
I would love the option to turn this off with a configuration option like Kramdown has. |
was looking to accomplish the same thing. thanks @Feder1co5oave for a solution. It'd be nice if we could disable each of the rules in the future. |
@Feder1co5oave but this only applies to block rules not to inline rules? |
Closing to consolidate. |
Have you tried that? What does not fit? var renderer = new marked.Renderer();
renderer.heading = function (text, level) {
return '#'.repeat(level) + ' ' + text;
} |
I had similar issues and I solved it like this. Basically changing all rules for non-whitelisted elements into
|
Ps. We also have it documented in our Renderer extension example on how to do it. So, yeah, #1043. |
For anyone looking at this now, you need to do this: var marked = require('marked'),
options = { /* ... */ },
lexer = new marked.Lexer(options);
console.log(lexer)
lexer.tokenizer.rules.block.heading = { exec: function() {} }
marked.parser(lexer.lex('# heading?'), options) Not sure if this is clean (I should probably use the tokeniser directly?) but it works |
this doesn't affect the result |
Yes it does, I just tested it |
You should be able to use the tokenizer for this. marked.use({
tokenizer: {
heading() {}
}
}); This tells the tokenizer to never find headings. |
Thanks yes—this seems like the correct approach, but note that you should return marked.use({
tokenizer: {
url() { return undefined },
autolink() { return undefined },
html() { return undefined },
link() { return undefined },
reflink() { return undefined },
}
}) |
I would like to disable the hash headers.
Is this possible to turn off this feature using the current API or does it requiring modifying the source?
The text was updated successfully, but these errors were encountered: