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

**URL:** <https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080>\
**Category:** support\
**Created:** [March 31, 2021, 2:16pm UTC](https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080 "2021-03-31T14:16:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![User2](https://avatars.discourse-cdn.com/v4/letter/u/ecb155/32.png) [@User2](https://discourse.gohugo.io/u/User2)\
**Post date:** [March 31, 2021, 2:16pm UTC](https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080/1 "2021-03-31T14:16:23Z")

</div>

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](https://discourse.gohugo.io/t/two-div-sections-one-markdown-file/27738/2)

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?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 31, 2021, 4:27pm UTC](https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080/2 "2021-03-31T16:27:14Z")

</div>

markdown

```auto
+++
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 >}}

[SECTION-BREAK]

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

```

layouts/\_default/single.html

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

  {{ $sectionBreak := "<p>[SECTION-BREAK]</p>" }}
  {{ $sections := split .Content $sectionBreak }}
  
  {{ if eq (len $sections) 1 }}
    {{ .Content }}
  {{ else }}
    {{ range $k, $v := $sections }}
      {{ $id := printf "section-%d" (add 1 $k) }}
      <div id="{{ $id }}">
        {{ $v | strings.TrimSpace | safeHTML }}
      </div>
    {{ end }}
  {{ end }}

{{ end }}

```

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

```auto
<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`.

---

<div class="post-metadata">

**Author:** ![User2](https://avatars.discourse-cdn.com/v4/letter/u/ecb155/32.png) [@User2](https://discourse.gohugo.io/u/User2)\
**Post date:** [March 31, 2021, 8:20pm UTC](https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080/3 "2021-03-31T20:20:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [April 2, 2021, 8:21pm UTC](https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080/4 "2021-04-02T20:21:39Z")

</div>

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