-
- Downloads
Relativize links when emitting html from md in pulse/subscriptions (#18428)
* Relativize links when emitting html from md in pulse/subscriptions Helpful links: - https://awesomeopensource.com/project/vsch/flexmark-java - https://github.com/vsch/flexmark-java/blob/master/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/PegdownCustomLinkResolverOptions.java - https://github.com/vsch/flexmark-java/blob/8a881b73109a287b5f202e2e1fc9f9c497d5eecf/flexmark/src/main/java/com/vladsch/flexmark/html/HtmlRenderer.java#L433 - https://github.com/vsch/flexmark-java/blob/8a881b73109a287b5f202e2e1fc9f9c497d5eecf/flexmark/src/main/java/com/vladsch/flexmark/html/renderer/ResolvedLink.java#L10 This was a pain in the ass. I had been looking for a way to just easily traverse the ast, but this might cause problems since there are spans and text positions everywhere. So i looked at how to change the parser. Everything is so difficult to change. Luckily there was a built-in way to do this with link resolvers, found in a github issue https://github.com/vsch/flexmark-java/issues/308 . And ideally this would be done in the parser but it seems to be done in the html emitter. https://github.com/vsch/flexmark-java/blob/master/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/CustomLinkResolverSample.java And then I got turned around on what is relative or not. What happens if you do something seemingly sane like: ```markdown [a link to google](www.google.com) ``` This is apparently a relative link since it lacks a protocol. And our `resolve-uri` code treats it as such: ```clojure markdown=> (resolve-uri "www.google.com") "http://localhost:3000www.google.com" markdown=> ``` This seems strange to me but is also the behavior on gist.github.com: https://gist.github.com/dpsutton/412502ffa89186487e41885855dfa781 has a link to https://gist.github.com/dpsutton/www.google.com In all, trying to figure out this object oriented factory mess i had 24 tabs open to the source of NodeVisitor, NodeVisitorBase, AstActionHandler, VisitHandler, ParserExtension, NodePostProcessorFactory, etc. It was truly unpleasant. * Remove errant require of mb.util.urls * Ensure the site setting always has a slash when resolving relative The URI class will do some wonky things. Sometimes it feels structural, but it can also just feel like it is combining strings willy nilly. ```clojure (.. (URI. "http://example.com") (resolve "www.google.com") toString) "http://example.comwww.google.com" ``` So ensure that there is a final trailing slash
Please register or sign in to comment