Custom markdown links

After migrating a wiki to hugo, I had to make a lot of conversions from

[[See there|Another wiki page]]


[See there]({{< relref "Another wiki page" >}})

I did this with an external script, but I was wondering… It would be much more user friendly to maintain these (and future!) links in the form

[See there](Another wiki page)

In other words, use the target page title or id as link.

Hugo (as of 0.60) with Goldmark provides for markdown render hooks, and these seem to be the right place to attack this. But I get all kinds of markdown links so I need to distinguish the title/id links from the others.

So the question is: Can I find out whether a destination is a valid title or id? I can call relref but this will bail out and abort the build if the target can not be found. And I’d rather not play tricks with refLinksErrorLevel.

Your valuable suggestions are appreciated.

1 Like

I’m afraid this may be a stillborn idea… When I specify a link as

[See there](Another wiki page)

it is not even taken into consideration by Goldmark, i.e. the render-link.html is not even invoked. When I specify (Another-wiki-page) instead, the hook is called.

Nevertheless I would still be interested in the original question: Can I find out whether a destination is a valid title or id?

Hi … what about using HTMLtest and running it on your public folder - this gives you all the info and can follow the internal links

obviously this isn’t real time checking of [some text](some link)

Obviously is isn’t :smirk:

so realtime feedback is called Hugo server -D and browse the page

static .md files couldn’t do a quality check - you need a CMS for that

The point is that I want to know within a partial, so I can take different actions depending on the target being valid or not.

What I currently do, in the partial, is process the list of pages to find a matching title. Works more or less, but is ugly and not foolproof.

I suspect you are reluctant to to this because it will affect all calls to ref and relfef, not just the calls you would make from this render hook.

If the ref and relref functions took an optional second parameter, either “WARN” or “ERROR”, would that work for you? It would essentially allow you to try/catch within your template, but error everyplace else.

Might be worth a PR…

You would still need to quote-encapsulate the title destination in your markdown, as markdown links and images take an optional third parameter, title.


Yes, I think this would work. Or two alternative functions ref_safe and relref_safe.

I browsed a bit in the relevant code but it is currently above my level of (hu)go knowledge.

Hey, you’ve got an entire weekend ahead of you…