From 620a34b3fc2736bb8fffc899b8e0078d7b71eca3 Mon Sep 17 00:00:00 2001 From: Sam Douglas Date: Wed, 7 Jan 2026 17:21:36 +1300 Subject: [PATCH] Fix CRLF line ending handling when processing markdown --- changelog.md | 3 +++ kibble/models/template.go | 5 +++-- kibble/models/template_test.go | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 22e9e2cf..382bb862 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ ## [Unreleased] + - Convert CRLF line endings to LF because blackfriday (markdown lib) doesn't + handle them properly + ## [0.17.9] - 2026-01-06 - Add support for 'post' page type diff --git a/kibble/models/template.go b/kibble/models/template.go index 46722108..0f517d51 100644 --- a/kibble/models/template.go +++ b/kibble/models/template.go @@ -205,8 +205,9 @@ func CreateTemplateView(routeRegistry *RouteRegistry, trans i18n.TranslateFunc, // ApplyContentTransforms - add the markdown / sanitization / shortcodes func ApplyContentTransforms(data string) string { - // apply mark down - unsafe := blackfriday.Run([]byte(data)) + // apply mark down. + // note: converting CRLF -> LF due to https://github.com/russross/blackfriday/issues/423 + unsafe := blackfriday.Run([]byte(strings.ReplaceAll(data, "\r\n", "\n"))) // apply the templates return insertTemplates(string(unsafe)) diff --git a/kibble/models/template_test.go b/kibble/models/template_test.go index 1501aeeb..29d1b14f 100644 --- a/kibble/models/template_test.go +++ b/kibble/models/template_test.go @@ -39,6 +39,14 @@ func TestMarkdownContent(t *testing.T) { ConfigureShortcodeTemplatePath(cfg) assert.Equal(t, "

ONE

\n", ApplyContentTransforms("# ONE")) } + +func TestMarkdownWithCRLFEndings(t *testing.T) { + // blackfriday doesn't automatically handle \r\n line endings so we convert + // to \n first. + ConfigureShortcodeTemplatePath(cfg) + assert.Equal(t, "

ONE

\n\n

Paragraph 1

\n\n

Paragraph 2

\n", ApplyContentTransforms("# ONE\r\n\r\nParagraph 1\r\n\r\nParagraph 2")) +} + func TestEchoEmbeddedTemplateContent(t *testing.T) { ConfigureShortcodeTemplatePath(cfg) assert.Equal(t,