Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Replace all link targets in markdown ast #6

#1

Hello,

first thank you for this library! I never used pegdown or flexmark before, so this is probably a stupid question…. I'd like to parse a markdown document and then change all links to some other url. I tried using a NodeVisitorBase and doing for example ((InlineLinkNode) n).setUrl("...") (I probably need to check for other node types, too), but when I then use the formatter to convert the ast back to markdown it is not changed. I want it being changed in the resulting html and markdown source. Unfortunately I can not figure out how to do this. Do I have to use some other component?

Thank you and kind regards
Eike

  • solved #3
  • replies 5
  • views 6.5K
  • likes 0

@eikek, it is a bit convoluted because each node keeps track of the source position and each node text part. I am making a new release that cleaned up the link related nodes to make your use case implementation easier.

The new release is coming shortly which includes a FormatterWithMods.java sample that modifies URLs with a node visitor and a formatter for output.

#3
#4

@vsch thank you very much! I see the example is exactly what I want. Going to try it soon :) Thanks again!

#5

You are welcome.

Your use case was not addressed by the library and was a good reason for some cleanup.

eikek accepted post #3 as the answer
#6