Bug: Parsing inline code containing triple backticks injects trailing spaces into subsequent code blocks #33

Open
opened 2026-05-10 14:14:00 +00:00 by humanborch · 0 comments
humanborch commented 2026-05-10 14:14:00 +00:00 (Migrated from github.com)

Bug Report: Parsing inline code containing triple backticks injects trailing spaces into subsequent code blocks

Describe the bug

When goldmark-markdown renders a document containing an inline code span that encloses triple backticks (e.g., using <code> blocks or escaped backticks to represent an inline code span containing three backticks), it successfully renders that line but appears to enter a corrupted internal state. From that point forward, the renderer appends an extra trailing space to every subsequent inline code span it processes in the document.

Successive renders of the same output compound this issue, recursively adding extra padding to all subsequent inline code blocks.

To Reproduce

Here is a minimal, standalone Go program that demonstrates the bug.

package main

import (
	"bytes"
	"fmt"

	markdown "github.com/teekennedy/goldmark-markdown"
	"github.com/yuin/goldmark"
)

func main() {
	md := goldmark.New(
		goldmark.WithRenderer(markdown.NewRenderer()),
	)
	
	// The first line contains an inline code block with triple backticks.
	// The second line contains a normal inline code block.
	content := []byte("- test (` ``` `).\n- test `code`.\n")
	
	var buf bytes.Buffer
	if err := md.Convert(content, &buf); err != nil {
		panic(err)
	}
	
	fmt.Printf("INPUT:\n%s\n", string(content))
	fmt.Printf("OUTPUT:\n%s\n", buf.String())
}

Expected behavior

The output should match the input markdown without injecting additional spaces into the second code block.

INPUT:
- test (` ``` `).
- test `code`.

OUTPUT:
- test (` ``` `).
- test `code`.

Actual behavior

The renderer injects a trailing space into the second inline code block.

INPUT:
- test (` ``` `).
- test `code`.

OUTPUT:
- test (` ``` `).
- test `code `.

If you take the OUTPUT string and pass it through the converter a second time, the trailing spaces will compound, resulting in - test code `.

Environment

  • Go version: 1.22+
  • goldmark version: v1.7.1 (or relevant version)
  • goldmark-markdown version: v0.5.1

Additional Context

This bug was encountered during the development of an automated Markdown linter and formatter using goldmark-markdown. Because the pipeline reads, formats, and writes the Markdown back to disk, the inline triple-backtick string in our documentation caused trailing spaces to rapidly balloon across hundreds of code blocks in the document across multiple linter runs.

# Bug Report: Parsing inline code containing triple backticks injects trailing spaces into subsequent code blocks ## Describe the bug When `goldmark-markdown` renders a document containing an inline code span that encloses triple backticks (e.g., using `<code>` blocks or escaped backticks to represent an inline code span containing three backticks), it successfully renders that line but appears to enter a corrupted internal state. From that point forward, the renderer appends an extra trailing space to **every subsequent inline code span** it processes in the document. Successive renders of the same output compound this issue, recursively adding extra padding to all subsequent inline code blocks. ## To Reproduce Here is a minimal, standalone Go program that demonstrates the bug. ```go package main import ( "bytes" "fmt" markdown "github.com/teekennedy/goldmark-markdown" "github.com/yuin/goldmark" ) func main() { md := goldmark.New( goldmark.WithRenderer(markdown.NewRenderer()), ) // The first line contains an inline code block with triple backticks. // The second line contains a normal inline code block. content := []byte("- test (` ``` `).\n- test `code`.\n") var buf bytes.Buffer if err := md.Convert(content, &buf); err != nil { panic(err) } fmt.Printf("INPUT:\n%s\n", string(content)) fmt.Printf("OUTPUT:\n%s\n", buf.String()) } ``` ### Expected behavior The output should match the input markdown without injecting additional spaces into the second code block. ```text INPUT: - test (` ``` `). - test `code`. OUTPUT: - test (` ``` `). - test `code`. ``` ### Actual behavior The renderer injects a trailing space into the second inline code block. ```text INPUT: - test (` ``` `). - test `code`. OUTPUT: - test (` ``` `). - test `code `. ``` If you take the `OUTPUT` string and pass it through the converter a second time, the trailing spaces will compound, resulting in `- test ` `code ` `. ## Environment - Go version: `1.22+` - `goldmark` version: `v1.7.1` (or relevant version) - `goldmark-markdown` version: `v0.5.1` ## Additional Context This bug was encountered during the development of an automated Markdown linter and formatter using `goldmark-markdown`. Because the pipeline reads, formats, and writes the Markdown back to disk, the inline triple-backtick string in our documentation caused trailing spaces to rapidly balloon across hundreds of code blocks in the document across multiple linter runs.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/goldmark-markdown#33
No description provided.