Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/markdown/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func init() {
// Convert converts Markdown source to HTML.
// plantumlServer is the PlantUML server URL for code block conversion.
func Convert(source []byte, plantumlServer string) ([]byte, error) {
// Normalize CRLF to LF so all preprocessors and the parser see consistent line endings.
source = bytes.ReplaceAll(source, []byte("\r\n"), []byte("\n"))

// Pre-process: expand single-line $$...$$ to multi-line for goldmark-mathjax
source = PreprocessMathBlocks(source)

Expand Down
22 changes: 22 additions & 0 deletions internal/markdown/convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package markdown

import (
"strings"
"testing"
)

func TestConvert_CRLFMathBlock(t *testing.T) {
// Regression: CRLF line endings must not break $$ math block rendering.
input := []byte("$$\r\ny = x^2\r\n$$\r\n")
html, err := Convert(input, "")
if err != nil {
t.Fatalf("Convert returned error: %v", err)
}
s := string(html)
if !strings.Contains(s, `\(y = x^2\)`) && !strings.Contains(s, `y = x^2`) {
t.Errorf("math content missing from output:\n%s", s)
}
if strings.Contains(s, `\(\)`) || strings.Contains(s, `\(\r`) {
t.Errorf("CRLF leaked into math output:\n%s", s)
}
}
Loading