Isolation of links and footnotes inside codeblocks

I can not refer to links defined beyond the block, just like I can’t make footnotes inside either. I have to define those footnotes or link references inside the blockquote block.
However when I use the > inline quotation method, footnotes are created outside the blockquote, like any other footnote. But I can never reference to links defined elsewhere in the document, no matter what.

Why ? It is very irritating when you need to annotate technical documents with definitions laid out elsewhere in the text, medical terms for instance.
Here’s my render-codeblock-quote.html:

{{ $author := .Attributes.author  }}
{{ $cite   := .Attributes.cite    }}
{{ $class   := .Attributes.class }}
<figure {{with .Attributes.id}}id={{.}} {{end}}class="non-picture {{with $class}}{{.}}{{end}}">
<blockquote {{with $cite}}{{ print `cite="` . `"` | safeHTMLAttr }}{{end}}>{{ .Inner|$.Page.RenderString }}</blockquote>
{{ if or $author $cite }}<figcaption class=cite_class>{{with $author}}{{.|$.Page.RenderString }}{{end}}{{with $cite }}<cite> in {{.|$.Page.RenderString}}</cite>{{end}}</figcaption>{{end}}
</figure>
1 Like

It’s complicated to explain what I mean, and even more to the code here.
So look here:

By any chance, are you talking about something like this?

https://pasteboard.co/0KKOKWULRHGA.png

https://pasteboard.co/q8JX4rnaHnfF.png

In my case, I’m using shortcodes, and I haven’t figured out a way to use footnotes inside a shortcode yet make the footnote appear outside of it. I also can not reference to links outside of it. I also tried making shortcode read as a markdown, but that failed, too.

In any case, might be related or not.

(PS. Upload is not working so I used a third-party image paste board.)

Exactly this.
I knew the issue for shortcodes, but didn’t know it also applied to fenced codeblocks. But only them: the inline quotation syntax (>) allows externally defined references.
And I checked, it doesn’t matter if I use a renderhook or not.
Footnotes seem like yet another matter though, even the official reference mentions it:

But what’s even the point of this limitation in their own design !?

This is false.

The markdown renderer, Goldmark, includes a built-in extension for footnotes. This extension follows the spec/behavior of PHP Markdown Extra: Footnotes.

The information in markdownguide.org is not canonical. The canonical references for Goldmark are the CommonMark Spec, and the extension reference for each built-in extension.

1 Like

Good to know. But exterior footnotes in fenced or inline blockquotes really do not work in both of our cases. So is this a bug ? Or a limitation of Hugo in particular ? Or is there a way to parameterize it?

1) Footnotes within inline code will never work. It is… code.

This is `inline code[^1]`.

2) Footnotes within indented code blocks will never work. It is… code.

    This is an indented code block.[^2]

3) Footnotes within fenced code blocks (those without a render hook) will never work. It is… code.

```go
This is a fenced code block.[^3]
```

4) Footnotes in a blockquote are rendered as expected.

> This is a blockquote.[^4]

5) Footnotes within a shortcode called using the {{% foo %}} notation are rendered as expected.

{{% foo %}}
This is **bold** text.[^4]
{{% /foo %}}

6) Footnotes within a shortcode called using the {{< foo >}} are rendered if both parts are passed through .Page.RenderString in the same call. Shortcodes called with this notation are rendered separately from the .RawContent, outside of the normal page flow, resulting in duplicate id attributes and positioned immediately after the shortcode call. This is expected.

{{< foo >}}
This is **bold** text.[^5]
[^5]: Footnote 5
{{< /foo >}}

7) Footnotes within a markdown render hook are rendered if both parts are passed through .Page.RenderString in the same call. The content is rendered separately from the .RawContent, outside of the normal page flow, resulting in duplicate id attributes and positioned immediately after the fenced code block. This is expected.

```blockquote
This is rendered by a code block render hook.[^6]
[^6]: Footnote 6
```

No.

Sort of.

No.

1 Like

Understood. It would be better to let users just do whatever the hell they want. I know completely separating semantics and the rendering process isn’t always possible nor even desirable, but in that case, the problem is that markdown (I’m sure others too) addressed tech guys preferentially, while general users might not care about writing code in the slightest.
There definitely should be “fenced codeblocks”, because quoting long extracts with > is a pain in the buttock…
Ideally, the behavior of every single bit of syntax would be parametrizable with hooks. If not for the performance issue.

That’s what HTML is for.

Markdown is not a replacement for HTML, or even close to it… For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

Mark Gruber
https://daringfireball.net/projects/markdown/syntax#philosophy

2 Likes

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