Skip to content

Does TextContentRender support Extensions? #170

Description

@jemmy512

Steps to reproduce the problem (provide example Markdown if applicable):

I want to strip markdown to plain text.

This is my code:

String markdownFilter(String markdown) {
    Renderer textRender = TextContentRenderer.builder()
                .extensions(Arrays.asList(
                    StrikethroughExtension.create(),
                    AutolinkExtension.create(),
                    InsExtension.create(),
                    HeadingAnchorExtension.create())
                ).build();
    
    Parser parser = Parser.builder().build();
    
    String plainText = markdown;
    try {
        plainText = textRender.render(parser.parse(markdown));
    } catch (Exception e) {
        log.error("markdown to plain text failed: " + markdown, e);
    }
    return plainText;
}

I tested ~makdown~, ++markdown++, # markdown.

Expected behavior:

return markdown, markdown, markdown, separately.

Actual behavior:

return~markdown~, ++markdown++, markdown, separately.

~markdown~, ++markdown++ don't change.
# markdown stripped to markdown.

I noticed these words in README.md:

Extensions need to extend the parser, or the HTML renderer, or both.

So do extensions support text render? If not, how can I strip strike through and other extensions?

(Also see what the reference implementation does: https://spec.commonmark.org/dingus/)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions