Skip to content

Conversation

@tobias-kuendig
Copy link
Contributor

@tobias-kuendig tobias-kuendig commented Feb 1, 2025

This PR fixes line breaks in the output of the markdown renderer.

Currently, if a markdown document is parsed and rendered using this markdown library, some relevant line breaks are lost:

  • double line breaks after paragraphs

There are other (cosmetic) line breaks that are lost, but don't affect the validity of the markdown output:

  • line breaks after headings
  • line breaks after lists

There are some line-breaks that are added that should not be added:

  • A new line at the end of code blocks is added.

Example

Input:

# heading

Paragraph 1

Paragraph 2

- List item 1
- List item 2

Paragraph 3

\```
some code
\```

Is currently rendered as:

# heading
Paragraph 1
Paragraph 2
- List item 1
- List item 2
Paragraph 3
\```
some code

\```
Details
func TestPR(t *testing.T) {
	input := markdown.Parse([]byte(`
# heading

Paragraph 1

Paragraph 2

- List item

Paragraph 3
`), nil)

	fmt.Println(string(markdown.Render(input, NewRenderer())))
}

Note that paragraphs 1 and 2 are now no longer two separate paragraphs. It is also common to add double line breaks after a list and a heading for better readability.

This PR ensures, that there are always two line breaks after a heading, a paragraph or a list.

@kjk kjk merged commit 4f606c7 into gomarkdown:master Feb 2, 2025
1 check passed
@kjk
Copy link
Contributor

kjk commented Feb 2, 2025

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants