Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .RenderString render shortcodes #6703

Closed
regisphilibert opened this issue Jan 2, 2020 · 16 comments
Closed

Make .RenderString render shortcodes #6703

regisphilibert opened this issue Jan 2, 2020 · 16 comments
Assignees
Milestone

Comments

@regisphilibert
Copy link
Member

regisphilibert commented Jan 2, 2020

As requested I'm re-creating this issue.

Now that we have .RenderString. The problem mentioned in #6094 (comment) 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

@aaronpowell
Copy link

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.

@mlake
Copy link

mlake commented Jan 7, 2020

also seeing a need for this..

@bep
Copy link
Member

bep commented Jan 7, 2020

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

@regisphilibert
Copy link
Member Author

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!

@bep bep added Enhancement and removed Proposal labels Jan 7, 2020
@bep bep added this to the v0.63 milestone Jan 7, 2020
@bep bep modified the milestones: v0.63, v0.64 Jan 22, 2020
@bep bep modified the milestones: v0.64, v0.65 Jan 30, 2020
@bep bep modified the milestones: v0.65, v0.66 Feb 18, 2020
@bep bep modified the milestones: v0.66, v0.67 Mar 2, 2020
@bep bep modified the milestones: v0.67, v0.68 Mar 9, 2020
@bep bep modified the milestones: v0.68, v0.69 Mar 20, 2020
@NorseGaud
Copy link

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.

@bep bep modified the milestones: v0.69, v0.70 Apr 8, 2020
@bric3
Copy link

bric3 commented Apr 10, 2020

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>

@bep bep modified the milestones: v0.70, v0.71 Apr 28, 2020
@bep bep modified the milestones: v0.71, v0.72 May 18, 2020
@bep bep removed this from the v0.72 milestone May 31, 2020
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep self-assigned this May 29, 2022
bep added a commit to bep/hugo that referenced this issue May 29, 2022
@bep
Copy link
Member

bep commented May 29, 2022

@regisphilibert would you expect $page.HasShortcode "foo" to return true if foo was used only in $page.RenderString?

bep added a commit to bep/hugo that referenced this issue May 29, 2022
bep added a commit to bep/hugo that referenced this issue May 29, 2022
@regisphilibert
Copy link
Member Author

regisphilibert commented May 29, 2022

Yes! I would think so. .HasShortcode is usually used to load a dedicated script or style in the page's head in case the shortcode is used. I understand it could have value to know if given shortcode is used through .RenderString or .Content but don't mind not knowing either/or as long as I know the shortcode is used on the page.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests