Skip to content

Allow setting a custom LinkReferenceDefinitions in Parser.Builder #285

Closed

Description

@pron

An application employing Markdown may want to resolve "naked links" ([foo]) -- i.e. links with no inline destination -- based on contextual knowledge rather than definitions in the text. A custom LinkReferenceDefinition would allow for that.

Activity

  1. robinst commented on Feb 11, 2024

    @robinst
    Collaborator

    Hmm that's an interesting idea. So you would set all the known LinkReferenceDefinition in the parser builder beforehand? I wonder if it would be even more useful to provide a callback instead, then you'd have more flexibility and e.g. be able to only look up a definition for which there were actual references in the document.

    Something like:

    ReferenceLinkResolver resolver = (label) -> {
        if (label.equals("foo")) {
            return new LinkReferenceDefinition("Foo", "https://example.org", "Title");
        } else {
            return null;
        }
    };
    var parser = Parser.builder().referenceLinkResolver(resolver).build();
  2. robinst commented on Sep 18, 2024

    @robinst
    Collaborator

    This is now possible with the new linkProcessor API that can be set in Parser.Builder, with version 0.23.0! See full release notes here: https://github.com/commonmark/commonmark-java/blob/main/CHANGELOG.md#0230---2024-09-16

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions