Repository: gohugoio/hugo (language: go)

Issue:
Comment in yaml-codeblock won't generate html
### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.139.4+extended linux/amd64 BuildDate=unknown
</pre>

### Does this issue reproduce with the latest release?
Yes, it does.


When using the string:
```
# more publishable markdown files...
```
in a yaml-codeblock, like this
```yaml
      - name: Copy over new files
        run: |
            # Whitelist of all publishable wiki articles
            cp index.md $content
            # more publishable markdown files...
```
instead of the block an `e>` gets generated. When removing the comment, everything works fine. I also tried different strings with which, it sometimes worked and sometimes not. I cannot guess pattern, when the error occurs.

Also there is no special output when building the site. I guess there is something wrong with `goldmark` but I do not fully understand how `hugo` uses `goldmark`. So I'm approaching you guys at first.

Thanks for your time. I would be happy to provide more information on this issue.




Discussion / hints:
>in a yaml-codeblock, like this

What exactly do you mean by this.
I mean it like this:
````markdown
Some text explaining the yaml
```yaml
      - name: Copy over new files
        run: |
            # Whitelist of all publishable wiki articles
            cp index.md $content
            # more publishable markdown files...
```
````
When building this, I just get 
```html
<p>Some text explaining the yaml</p>
e>
```

I tried your example, and it renders fine for me (I tested with both `markup.higlight.codeFences` true and false). 
I looked at the relevant page in your repository:
<https://github.com/hmaier-dev/wiki/blob/main/content/Github.md>

The first line of the file is:

```text
# How this wiki works
```

So, despite the `.md` extension, Hugo treats this as Emacs Org Mode front matter:

https://github.com/gohugoio/hugo/blob/a32c889a7b1b6cb7b9a80b4fbab342d9b660a988/parser/pageparser/pagelexer_intro.go#L31-L32

And when we call `lexFrontMatterOrgMode`...

https://github.com/gohugoio/hugo/blob/a32c889a7b1b6cb7b9a80b4fbab342d9b660a988/parser/pageparser/pagelexer_intro.go#L94

And `summaryDividerOrg` is... 

https://github.com/gohugoio/hugo/blob/a32c889a7b1b6cb7b9a80b4fbab342d9b660a988/parser/pageparser/pagelexer.go#L103

More about summary dividers here:
<https://gohugo.io/content-management/summaries/#manual-summary>

A simple example that reproduces the behavior you are seeing:

````text
# a

```yaml
x: 6
# more foo
y: 7
```
````

Looking at your repository, you need to:

1. Add YAML, TOML, or JSON front matter to every markdown file
2. Rename `content/index.md` to `content/_index.md`

Fix patch:
diff --git a/parser/pageparser/pagelexer_intro.go b/parser/pageparser/pagelexer_intro.go
index 925c61c9e58..334d9a79c15 100644
--- a/parser/pageparser/pagelexer_intro.go
+++ b/parser/pageparser/pagelexer_intro.go
@@ -91,14 +91,14 @@ func lexFrontMatterOrgMode(l *pageLexer) stateFunc {
 		#+DESCRIPTION: Just another golang parser for org content!
 	*/
 
-	l.summaryDivider = summaryDividerOrg
-
 	l.backup()
 
 	if !l.hasPrefix(delimOrg) {
 		return lexMainSection
 	}
 
+	l.summaryDivider = summaryDividerOrg
+
 	// Read lines until we no longer see a #+ prefix
 LOOP:
 	for {


Test patch:
diff --git a/parser/pageparser/pagelexer_intro_test.go b/parser/pageparser/pagelexer_intro_test.go
new file mode 100644
index 00000000000..c074e6f5050
--- /dev/null
+++ b/parser/pageparser/pagelexer_intro_test.go
@@ -0,0 +1,46 @@
+// Copyright 2024 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package pageparser
+
+import (
+	"testing"
+
+	qt "github.com/frankban/quicktest"
+)
+
+func Test_lexIntroSection(t *testing.T) {
+	t.Parallel()
+	c := qt.New(t)
+	for i, tt := range []struct {
+		input                string
+		expectItemType       ItemType
+		expectSummaryDivider []byte
+	}{
+		{"{\"title\": \"JSON\"}\n", TypeFrontMatterJSON, summaryDivider},
+		{"#+TITLE: ORG\n", TypeFrontMatterORG, summaryDividerOrg},
+		{"+++\ntitle = \"TOML\"\n+++\n", TypeFrontMatterTOML, summaryDivider},
+		{"---\ntitle: YAML\n---\n", TypeFrontMatterYAML, summaryDivider},
+		// Issue 13152
+		{"# ATX Header Level 1\n", tText, summaryDivider},
+	} {
+		errMsg := qt.Commentf("[%d] %v", i, tt.input)
+
+		l := newPageLexer([]byte(tt.input), lexIntroSection, Config{})
+		l.run()
+
+		c.Assert(l.items[0].Type, qt.Equals, tt.expectItemType, errMsg)
+		c.Assert(l.summaryDivider, qt.DeepEquals, tt.expectSummaryDivider, errMsg)
+
+	}
+}