Community links double nested <a>
Help welcome on this. But it's not a trivial bug (at least, for me). I've spent too much time in mdast/unist/unified land and a set of new eyes would be appreciated, especially if you have experience with syntax tree parsing.
https://wefwef.app/search/lemmy.world/c/[email protected]/comments/614681
Basically you get nested anchor tags because of the custom built plugin (buildCommunityPlugin.tsx).
This code for markdown parsing of Lemmy community links is super hacky. Basically I hack the gfm autolinker to NOT parse "email-like" strings that start with !, otherwise because it always runs first, it will parse before the custom plugin can run.
Then the custom plugin runs, and it's hacky and needs refactor because it creates nested anchor elements.
see:
Removing the plugin from remark still renders the /c/futurama link for me, but the top level links are gone. I'd like to look at mdast-util-gfm-autolink-literal-lemmy package but it doesn't seem to be on GitHub. Is it?
Hi @denkristoffer, thanks for taking a look at it!
The -lemmy fork is here: https://github.com/aeharding/mdast-util-gfm-autolink-literal-lemmy/commit/39953aed8d2461c3f7d1ee57dfaf823dab518af5
You're totally on to something. It looks like the user of that comment manually linked it with markdown, but the custom community plugin is relinking it, causing the nested anchors.
I don't have experience syntax tree parsing, but would a potential solution be one that only creates a new link node when the parent isn't a link? Or maybe creates a new link node as long as the parent isn't a link with the same URL/link/href?
Yeah - It's probably something like that @rideron89.
@denkristoffer are you working on this? If not, I can create a PR for this. But I don't want to step on your toes.
@rideron89 No go right ahead 😄