Skip to content

Disable all parsers and processors by default #286

@markkolich

Description

@markkolich

I 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions