Hugo: Make `.RenderString` render shortcodes

Created on 2 Jan 2020  路  7Comments  路  Source: gohugoio/hugo

As requested I'm re-creating this issue.

Now that we have .RenderString. The problem mentioned in https://github.com/gohugoio/hugo/issues/6094#issuecomment-513116608 has been lifted and we should consider having .RenderString process shortcodes.

Do we really need this?

When building a page with blocks of data (CMS Blocks, Page Builders and so on), most of those are saved as Front Matter. It then falls on the developer to range on those blocks and apply the proper data processing/partial loading etc...

In the context of a very nice to have page builder, Hugo shortcodes are currently unusable by the editor and any search-and-replace workaround cooked up by developers (been there) will never match the reliability and usability of Hugo's shortcode API.

Will it break code?

The .RenderString method is fairly new and I don't see anyone including shortcodes in there with the expectation that they would not be processed. So I think: No

Enhancement

Most helpful comment

This is a huge need for us. Partials allow for a lot of DRYness in our docs site and not being able to include markdown with other shortcodes in it (like relrefs) is painful.

All 7 comments

I just came across .RenderString as a way to render some markdown that's in the front matter of a page and was surprised it didn't handle shortcodes (then I read the docs and saw it stated).

I see value in it handling that, if not, an alternative like shortcodify like was mentioned in the parent issue.

also seeing a need for this..

Filling up my notification screen with "I need this, too" does not help.

Hello @mlake, usually a "thumb up" emoji on the issue's description is enough to notify of your interest in this issue being treated. You'll get the same effect without the noise. Thanks a ton!

This is a huge need for us. Partials allow for a lot of DRYness in our docs site and not being able to include markdown with other shortcodes in it (like relrefs) is painful.

Hi I stumbled on this issue, and I wonder if the _new_ .RenderString that could process shortcodes could help me in the below case.


I have a mardown table that I'd like to wrap in a div, and I'd have shortcodes to highlight / mark some text in this table.

{{< wrapTable >}}

| Memory Type | # of Segments | Used Memory(bytes) | Used Memory(%) | Free Memory(bytes) | Free Memory(%) | Total Memory(bytes) |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| Internal | 13 | 1 191 740 | {{< mark >}}**88,4**{{< /mark >}} | 156 452 | 11,6 | 1 348 192 |
| Object (reversed) | 1 | 402 653 184 | {{< mark >}}**100**{{< /mark >}} | 0 | 0 | {{< mark >}}**402 653 184**{{< /mark >}} |
| Class | 9 735 | 228 637 344 | {{< mark >}}**90,96**{{< /mark >}} | 22 724 116 | 9,04 | {{< mark >}}**251 361 460**{{< /mark >}} |
| JIT Code Cache | 5 | 41 943 040 | {{< mark >}}**100**{{< /mark >}} | 0 | 0 | 41 943 040 |
| JIT Data Cache | 3 | 17 018 496 | 67,63 | 8 147 328 | 32,37 | 25 165 824 |
| Overall | 9 757 | 691 443 804 | 95,71 | 31 027 896 | 4,29 | 722 471 700 |

{{< /wrapTable >}}

My shortcodes are

  • wrapTable.html
<div class="table-wrapper">
    <!-- {{ .Inner | markdownify }} -->
</div>
  • mark.html
<mark>{{ .Inner | markdownify }}</mark>

However with this code the table is broken as soon as there's the {{< mark >}} shortcode.

I've tried using $.Page.RenderString instead of mardownify but this didn't actually change anything. So for now I'm using a hacky way with two shortcodes for the table wrapper.

  • openWrapTable that output the <div>
  • closeWrapTable that output </div>

Found this; my use case (which I've not yet seen mentioned in any of the various issue discussions so far, apologies if I missed it) is shortcodes with Remark.js. Typical implementation uses .RawContent, which of course means shortcodes go un-rendered. Being able to do .RawContent | shortcodify, or .RawContent | shortcodify . to have the .Page context if necessary would be excellent.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

antifuchs picture antifuchs  路  3Comments

VoidingWarranties picture VoidingWarranties  路  3Comments

mumblecrunch picture mumblecrunch  路  3Comments

kaushalmodi picture kaushalmodi  路  3Comments

MunifTanjim picture MunifTanjim  路  3Comments