commonmark-java
commonmark-java copied to clipboard
Allow setting a custom `LinkReferenceDefinitions` in `Parser.Builder`
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.
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();