Ampersand character in markdown links?

$ hugo env
Hugo Static Site Generator v0.69.0/extended windows/amd64 BuildDate: unknown
GOOS=“windows”
GOARCH=“amd64”
GOVERSION=“go1.14.1”

I’m sorry to post here over something potentially so trivial but I’ve been searching for quite a while now and can’t find the answer, so was hoping somebody might be able to answer this easily here?

I’m using the “mainroad” theme and I simply need to include a normal ampersand character inside anchor text, not the url or title, just the text itself i.e. A & B Example 1

The problem is, it always displays the link text as A & B. If tried escaping with various prefix characters including backslash single or multiple backticks and also replacing the & with the text & but nothing seems to allow simply A & B as link text to be displayed?

If I change the defaultMarkdownHandler back to BlackFriday the formatting is correct but then I lose table support and presumably other features I’m not totally aware of?

I can’t believe no one else is having this problem?

Can anyone help or point me in the right direction please?

Hey aukdev,

I’ve just set up a quick test site with the mainroad theme (same Hugo version as for you, but on macOS), and I have no problems with setting up links like this:

[A & B](https://gohugo.io)

Is this what you’ve been referring to?

This may not make sense as our forum is formatting the text. You ought to take a screenshot in this case, or share a link to a live example. Do you mean it render something like &? :slight_smile:

Thanks very much to both of you and you pointed me in the right direction.

Since hugo changed from blackFriday to the goldmark renderer the
hrefTargetBlank is no longer supported and a render hook now needs to be used instead.

I was using this great article here to enable all my links to opened in an external tab but thanks to your clues, the problem was traced to this i.e.

<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank"{{ end }}>{{ .Text }}</a>

The problem was actually the ((.Text}} at the end, which needed to be .PlainText instead.

Hope this might help someone else having the same or similar problem.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.