question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable all parsers and processors by default

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
vschcommented, Dec 14, 2018

@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.

0reactions
vschcommented, Dec 15, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable XXE processing? - SonarSource Blog
In this post, we will see how to completely disable external entities declaration and expansion, offering a quick and safe solution.
Read more >
XML External Entity Prevention - OWASP Cheat Sheet Series
If the parser is not secure by default, look for flags supported by the parser to disable all possible external resource inclusions like...
Read more >
Java API for XML Processing (JAXP) Security Guide
The JDK XML parsers observe processing limits by default. Both DOM and SAX parsers ... FEATURE_SECURE_PROCESSING, true) , disables all external connections.
Read more >
Features - Apache Xerces
Disable identity constraint checking. Default: true. Access: (parsing) read-only; (not parsing) read-write;. Since: ...
Read more >
CommonParserSettings (univocity-parsers 2.9.1 API)
By default, all parsers work with, at least, the following configuration options ... When disabled, each parsed record will contain values for all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found