Disable all parsers and processors by default
See original GitHub issueI have a need to disable all parsers and processors by default, while selectively enabling only a fixed subset of supported features. The use-case I need to address is “only support **
and _
” , while disabling all other Markdown syntax features.
For instance:
final MutableDataSet options = new MutableDataSet();
// Disable everything I don't need; not sure this is "everything"...
options.set(Parser.BLOCK_QUOTE_PARSER, false);
options.set(Parser.FENCED_CODE_BLOCK_PARSER, false);
options.set(Parser.HEADING_PARSER, false);
options.set(Parser.HTML_BLOCK_DEEP_PARSER, false);
options.set(Parser.HTML_BLOCK_PARSER, false);
options.set(Parser.INDENTED_CODE_BLOCK_PARSER, false);
options.set(Parser.LIST_BLOCK_PARSER, false);
options.set(Parser.THEMATIC_BREAK_PARSER, false);
options.set(Parser.REFERENCE_PARAGRAPH_PRE_PROCESSOR, false);
// Then, only enable a tiny subset of processors I need.
options.set(Parser.ASTERISK_DELIMITER_PROCESSOR, true);
options.set(Parser.UNDERSCORE_DELIMITER_PROCESSOR, true);
This works fine, afaict, but I’m left to enumerate all of the parsers and processors I can find and disable them.
The documentation at https://github.com/vsch/flexmark-java/wiki/Extensions#parser says:
Unified options handling added which are also used to selectively disable loading of core parsers and processors.
Is there a convenient way for me to “go the other way” and disable everything by default while only selectively enabling the features I need?
It would be great if the “feature enablement” configuration DataKey
’s were split into their own class so it’s at least obvious what needs to be disabled if one intends to turn off a “feature”.
((I’ve considered implementing my own DataHolder
and the corresponding getOrCompute
method therein to blindly return “false” on any DataKey
I don’t recognize. That of course, only works for boolean keys.))
CC // @larrysteinke
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
@markkolich, disabling the block parsers is stable and will work.
Disabling delimiters and reference paragraph pre-processor will also work. The latter will also disable rendering of all ref links and ref images which is what you want.
Wiki links are disabled by default so this is not an issue.
The real issues are with disabling link
[text](url)
, image link![text](url)
, inline code (text in back ticks). These can be easily handled by a node post processor to replace the specific nodes with just text. I will add a code sample to the flexmark-java-samples module to show how to do that.There are also hard line breaks (two or more spaces before an EOL in paragraphs) but these can be addressed by setting the desired rendering string for these. Default is
<br>
but you can put an empty string so they don’t render.Other than that you should be good to go.
@markkolich, I am glad you decided to kick the tires instead of waiting on me. I will add your sample when you make it available.
This can even be enhanced into a generic post-processor extension with extension options selecting which inline nodes to replace with their text content or some other part of their element’s text, like you did for links. It can then be used by others to disable individual inline elements which cannot be disabled at parse time.
Thank you for persisting in the discussion to help arrive at a clean, re-usable solution which does not require chewing up the inline parser. Previous requests for a similar feature ended shortly after asking/expecting me to do the work. These tend to discourage my interest and participation. I am swamped with OSS projects, supported after work hours. I have to prioritize where I invest my effort.