`.Page.RenderString` does not resolve reference style links in shortcodes

I have the following table shortcode:

{{ $caption := "" }}
{{ with .Get "caption" }}
  {{ $caption = printf `<caption class="text-center">%s</caption>` . }}
{{ end }}

{{ $class := "" }}
{{ with .Get "class" }}
  {{ $class = . }}
{{ end }}
{{ with .Get "small" }}
  {{ $class = print $class "table-sm" }}
{{ end }}


<div class="table-responsive extra-wide">
  {{ .Page.RenderString .Inner |
    replaceRE "<table>" (printf `<table class="table %s mb-0">%s` $class $caption) |
    replaceRE "<tbody>" `<tbody class="table-group-divider"` |
    safeHTML
  }}
</div>

I’m trying to use Markdown’s reference style links within the inner content of the table shortcode as follows:

{{< table small=true >}}

| Field         | Description                                                                                                                                                   |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`          | Tag ID specified in the [wiki][mbox-propif].                                                                                                                         |
| `buffer_size` | Size of the buffer (not the tag) in bytes.                                                                                                                    |
| `status`      | Tag status: <ul><li>Bit 31 should be cleared for requests.</li><li>In responses, bit 31 is set and bits `[30:0]` indicate the response buffer size.</li></ul> |

{{< /table >}}

However, the shortcode does not resolve the [mbox-propif] reference link. How do I get this to work?

You need to define the link target within the shortcode call.

{{< table small=true >}}

| Field         | Description                                                                                                                                                   |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`          | Tag ID specified in the [wiki][mbox-propif].                                                                                                                         |
| `buffer_size` | Size of the buffer (not the tag) in bytes.                                                                                                                    |
| `status`      | Tag status: <ul><li>Bit 31 should be cleared for requests.</li><li>In responses, bit 31 is set and bits `[30:0]` indicate the response buffer size.</li></ul> |

[mbox-propif]: https://gohugo.io
{{< /table >}}

Thanks. Is there an alternative where the definition can be read from the page context? I use that reference as plain text in the document as well.

No. The .Page.RenderString method passes the string through the markdown renderer, and the markdown renderer can’t see the link target unless it’s part of the string.

Okay, thanks for the information.

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