Parsing posts and markdown plugin with auto-linking
-
Inappropriate result, not link
In both cases, low or high priority, replacement will be a href of the anchor tag or links in replacement will be anchor tags. (My code snippet in first post - first case). -
Hmm... if your plugin sees unformatted urls (that is, no HTML), then your plugin hook is firing before Markdown, and you can modify the url as you see fit. Otherwise, it's after, and you'll need to send back the appropriate HTML.
However If you're seeing an unformatted URL and replace it with HTML, then markdown will sanitise the HTML for security purposes. Perhaps this is what is happening to you?
-
@julian Yes, Plugin sanitizes HTML, if I use higher priority than markdown plugin.
Actually It's sanitizes HTML and changes http urls on anchor tags, - double punch
If I use lower priority, I have my replacement as href property of anchor tag
I would like to find friendly way, so my plugin will work well with
markdown
plugin...
And I don't like idea to extend my regular expressions to comply with anchor tags -
@Nicolas What I mean to say is... don't send HTML into Markdown plugin, it'll sanitise it, which is likely not intended.
If you need to do more than replace the url, then unfortunately, you will have to alter the HTML after-the-fact
However, I recently had to mess around with it, so... here's a handy dandy regex for you to re-appropriate
/<a.+?href="(.+?)".*?>(.*?)<\/a>/g
(matches all links) -
@julian I don't like this idea, and situation in overall. Basically, It creates dependency in mine plugin to check if URLs were already changed, handle optional anchor tags, etc...
So, I will go with this:
- Disable Autoconvert for urls (Plugin's users will have to do the same)
- Use low priority
-
@BDHarrington7 - https://github.com/NicolasSiver/nodebb-plugin-ns-embed
-
Ah, um, you might already know, but there are already at least 2 other plugins that do this that I remember, although I can't say for sure if they still work. I am pretty sure that the YouTube-lite plugin still works, and the author @a_5mith is still active
-
I'm working with different URLs to change them on HTML, most complex replacements will be iframes.
I have plans to release this plugin with:
youtube
,twitch
,vimeo
,coub
andvine
embeds. -
@BDHarrington7 yes, I have checked them before I have started development