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

How to pass a parameter in MyLinkResolver Extention?

Open DL-EthanSun opened this issue 5 years ago • 4 comments

Is your feature request related to a problem? Please describe. I am trying to pass a parameter to resolveLink method in MyType implementd by LinkResolver, in order to obtain the url address of the filtered url relative to the markdownfile being processed.I don't find any sample do this.I hope you can give me some samples like this,thanks a lot.

DL-EthanSun avatar May 28 '20 08:05 DL-EthanSun

@DL-EthanSun, define a new DataKey<> or NullableDataKey<> and pass the value for this key in the options you pass to parser/renderer builder. In the link resolver constructor use passed link resolver context to get the options which will contain all options used to create the parser/renderer.

See: CustomLinkResolverSample.java

vsch avatar May 31 '20 15:05 vsch

@DL-EthanSun, note that Document node is also a DataHolder which contains all options used in parser with addition to any values added by the parsing process.

In the link resolver, getOptions() contains options used in the renderer builder while getDocument() contains options used in the parser and any values added during parsing.

vsch avatar May 31 '20 15:05 vsch

Thanks, if I want to loop pass value to LinkResolverType during parsing, what should I do. So far,I can but do it like this.The HtmlConvertRenderExtension is my extention relative to link resolver. pass value

DL-EthanSun avatar Jun 02 '20 06:06 DL-EthanSun

@DL-EthanSun, I would use the same style for your custom extension as for the other extensions. create should take to arguments since the extension factory is stateless. All state and options are passed in a DataHolder

You should set your options in init() by calling _option.set(YOUR_OPTION_KEY, optionValue)

This way your extension will not break in the future if some optimization is used for caching extension factory instances. Which is allowed because extension factory is assumed stateless, allowing a single instance to be used.

vsch avatar Jun 03 '20 20:06 vsch