flexmark-java icon indicating copy to clipboard operation
flexmark-java copied to clipboard

PegdownExtensions is missing at least one extension

Open hmf opened this issue 3 years ago • 1 comments

This is not a bug in the sense that it prevents Markdown from working correctly. However it prevents JBake from using its configuration file to add the Flexmark extensions properly:

  • [ ] Parser
  • [ ] HtmlRenderer
  • [ ] Formatter
  • [ ] FlexmarkHtmlParser
  • [ ] DocxRenderer
  • [ ] PdfConverterExtension
  • [x] extension(s)

To Reproduce

In order to configure JBake to add extensions we can add the following line to its configuration file:

# comma delimited default markdown extensions
markdown.extensions=HARDWRAPS,AUTOLINKS,FENCED_CODE_BLOCKS,DEFINITIONS

The line above works correctly. However this won't work:

# comma delimited default markdown extensions
markdown.extensions=FOOTNOTES,FENCED_CODE_BLOCKS,ATTRIBUTES

In particular the attributes extension is not activated. In fact it is not activate event when I set:

# comma delimited default markdown extensions
markdown.extensions=ALL

I say it is not activated because the following markdown examples:

Cond 1.1 text node{.blue}
Cond 1.1 text node {.red}
`Mill{.span}`

are simply not processed.

Expected behavior

I would assume that, using the ALL, the Markdown above would be parsed correctly. So the issue is why does it fail?

Additional context

JBake uses reflection to "parse" and identify the extensions as follows:

       List<String> mdExts = context.getConfig().getMarkdownExtensions();

        int extensions = PegdownExtensions.NONE;

        for (String ext : mdExts) {
            if (ext.startsWith("-")) {
                ext = ext.substring(1);
                extensions = removeExtension(extensions, extensionFor(ext));
            } else {
                if (ext.startsWith("+")) {
                    ext = ext.substring(1);
                }
                extensions = addExtension(extensions, extensionFor(ext));
            }
        }

where ext originates from the configuration file. It sets the flag (mask) extensions with the values and then collects the options based on this flag as follows:

        DataHolder options = PegdownOptionsAdapter.flexmarkOptions(extensions);

        Parser parser = Parser.builder(options).build();

And if we look a the com.vladsch.flexmark.parser.PegdownExtensions we do have an ALL member, however we have no ATTRIBUTES member.

So it is not possible to add this extension either explicitly or using the ALL flag because PegdownOptionsAdapter does not have access to such an option.

I think it is a question of keeping the set of extensions updates in the com.vladsch.flexmark.parser.PegdownExtensions file.

TIA

hmf avatar Jun 11 '22 19:06 hmf

Hi a Pull Request is created to support enable FlexMaks plugin and configure most flexmak options : #788

jderuette avatar Jun 16 '25 09:06 jderuette