Skip to content

Commit f2db070

Browse files
committed
Enkele regelovergangen als <br> behandelen in markdown-velden
Standaard markdown voegt regels samen tenzij er twee spaties of een lege regel tussen staan. Met breaks: true (GFM-gedrag) worden enkele newlines nu <br> in zowel de HTML-preview als de PDF-export.
1 parent 7ff0aa4 commit f2db070

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

packages/assessment-core/src/utils/markdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Content } from 'pdfmake/interfaces'
55
// Only safe HTML tags are produced; raw HTML input and images are stripped.
66
// Links are rendered with target="_blank" and rel="noopener noreferrer".
77
const safeMarked = new Marked({
8+
breaks: true,
89
renderer: {
910
html() { return '' },
1011
image() { return '' },
@@ -185,7 +186,7 @@ function processBlockTokens(tokens: Token[]): Content[] {
185186
export function markdownToPdfContent(markdown: string): Content {
186187
if (!markdown) return { text: '' }
187188

188-
const tokens = new Marked().lexer(markdown)
189+
const tokens = new Marked({ breaks: true }).lexer(markdown)
189190
const content = processBlockTokens(tokens)
190191

191192
if (content.length === 0) return { text: '' }

packages/assessment-core/test/markdown.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ describe('renderMarkdownToHtml', () => {
8989
expect(html).toContain('href="mailto:test@example.com"')
9090
})
9191

92+
it('converts single newlines to <br>', () => {
93+
const html = renderMarkdownToHtml('line one\nline two')
94+
expect(html).toContain('<br>')
95+
expect(html).toContain('line one')
96+
expect(html).toContain('line two')
97+
})
98+
9299
it('renders task list checkboxes as unicode', () => {
93100
const html = renderMarkdownToHtml('- [ ] todo\n- [x] done')
94101
expect(html).not.toContain('<input')
@@ -142,6 +149,12 @@ describe('markdownToPdfContent', () => {
142149
expect(content.stack).toHaveLength(2)
143150
})
144151

152+
it('converts single newlines to line breaks', () => {
153+
const content = markdownToPdfContent('line one\nline two') as any
154+
const texts = Array.isArray(content.text) ? content.text : [content.text]
155+
expect(texts).toContain('\n')
156+
})
157+
145158
it('handles mixed content', () => {
146159
const content = markdownToPdfContent('**bold** and *italic*') as any
147160
const texts = Array.isArray(content.text) ? content.text : [content.text]

0 commit comments

Comments
 (0)