@@ -169,6 +169,8 @@ func render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error
169169 return
170170 }
171171
172+ // Log via gitea log package and also print to stderr for debugging when
173+ // running a local reproduction program (some test helpers may suppress log writers).
172174 log .Error ("Panic in markdown: %v\n %s" , err , log .Stack (2 ))
173175 escapedHTML := template .HTMLEscapeString (giteautil .UnsafeBytesToString (buf ))
174176 _ , _ = output .Write (giteautil .UnsafeStringToBytes (escapedHTML ))
@@ -181,6 +183,44 @@ func render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error
181183
182184 rc := & RenderConfig {Meta : markup .RenderMetaAsDetails }
183185 buf , _ = ExtractMetadataBytes (buf , rc )
186+ /*
187+ // Only attempt to extract YAML front matter when the first line is a YAML separator
188+ // AND there is a matching closing separator later in the content.
189+ // If there is only a leading '---' (no closing '---'), we must not try to
190+ // extract metadata because that will be treated as normal markdown (a
191+ // thematic break) and should not interfere with goldmark parsing.
192+ firstLineEnd := bytes.IndexByte(buf, '\n')
193+ if firstLineEnd == -1 {
194+ firstLineEnd = len(buf)
195+ }
196+ firstLine := buf[:firstLineEnd]
197+ if isYAMLSeparator(firstLine) {
198+ // scan for a later line that is also a YAML separator
199+ foundClosing := false
200+ start := firstLineEnd + 1
201+ for start < len(buf) {
202+ end := len(buf)
203+ if idx := bytes.IndexByte(buf[start:], '\n'); idx >= 0 {
204+ end = start + idx
205+ }
206+ line := buf[start:end]
207+ if isYAMLSeparator(line) {
208+ foundClosing = true
209+ break
210+ }
211+ start = end + 1
212+ }
213+ if foundClosing {
214+ buf, _ = ExtractMetadataBytes(buf, rc)
215+ } else {
216+ // If there's an opening YAML separator but no closing one, some versions
217+ // of the goldmark parser can panic when parsing inline/code spans.
218+ // Prepend a blank line so the leading '---' is treated as a thematic
219+ // break (horizontal rule) and not as frontmatter, matching the
220+ // behaviour when users insert an initial blank line.
221+ buf = append([]byte("\n"), buf...)
222+ }
223+ }*/
184224
185225 metaLength := max (bufWithMetadataLength - len (buf ), 0 )
186226 rc .metaLength = metaLength
0 commit comments