Split markdown content in two files, but don't render shortcodes as raw text

Hello everyone,
I found a way to split the content of my markdown file in parts and also use these parts thanks to this post: Two div sections one markdown file - #2 by jmooring

The problem however is, that it renders shortcodes as raw text without considering the fact that it’s actually a shortcode. Is there a way to avoid this behaviour and still consider shortcodes as shortcodes and not only as raw text? Or would you recommend another way to split the content of a markdown file in multiple/two parts?


title = "Test"
date = 2021-03-31T08:58:49-07:00
draft = false
This is the content for the **first** section.

{{< p >}}
I am _emphasized_ text.
{{< /p >}}


This is the content for the **second** section.


{{ define "main" }}
  <h1>{{ .Title }}</h1>

  {{- $sectionDelimiter := "[SECTION-BREAK]" -}}
  {{- $ContentSections := split .Content $sectionDelimiter -}}
  {{- if gt (len $ContentSections) 1 -}}
    <div id="section-1">
      {{ index $ContentSections 0 | safeHTML }}
    <div id="section-2">
      {{ index $ContentSections 1 | safeHTML}}
  {{- else -}}
    <div id="content-not-split-into-sections">
      {{ .Content }}
  {{- end -}}

{{ end }}

And the shortcode for testing (layouts/shortcodes/p.html)

<p>{{ .Inner | .Page.RenderString }}</p>

In the original solution I used .RawContent so that we could use an HTML comment to split the sections, without having to set markup.goldmark.renderer.unsafe to true in the site configuration file. So I let the choice of delimiter dictate the approach.

In this revision, we’ve changed the delimiter to something that is not recognized as HTML, so we can use .Content (fully rendered) instead of .RawContent.

1 Like

Hello there,

thank you very much for your answer. That is very understandable. I even tried changing .RawContent to .Content, however I didn’t consider using a delimiter that is not recognized as HTML.

I appreciate your answer, thank you very much!

1 Like

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