Skip to content

Commit

Permalink
resolves #1632 workaround to produce valid xhtml (#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie authored Sep 23, 2023
1 parent fa9915d commit 2130ff8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion mermaid/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ export class Worker {
page.evaluate(async (definition, mermaidConfig) => {
window.mermaid.initialize(mermaidConfig)
try {
const { svg } = await window.mermaid.render('container', definition)
let { svg } = await window.mermaid.render('container', definition)
// workaround: https://github.com/yuzutech/kroki/issues/1632
// upstream issue: https://github.com/mermaid-js/mermaid/issues/1766
// taken from: https://github.com/mermaid-js/mermaid-live-editor/blob/83382901cd7e15414b6f18b48b7dd9c4775f3a21/src/lib/components/Actions.svelte#L23-L26
svg = svg
.replaceAll('<br>', '<br/>')
.replaceAll(/<img([^>]*)>/g, (m, g) => `<img ${g} />`)
return { svg, error: null }
} catch (err) {
return {
Expand Down
5 changes: 3 additions & 2 deletions mermaid/test/convert-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const svgTests = [
{ content: 'Hello<br/>World' },
{ content: 'Hello<br>World' },
{ content: 'Hello<br >World' },
{ content: 'Hello<br />World' }
{ content: 'Hello<br />World' },
{ content: 'Hello\\nWorld' }
]

const pngTests = [
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('#convert', function () {
const worker = new Worker(browser)
const result = await worker.convert(new Task(`graph TD
A{{ ${testCase.content} }}`))
expect(result).to.contains('<span class="nodeLabel">Hello<br>World</span>')
expect(result).to.contains('<span class="nodeLabel">Hello<br/>World</span>')
} finally {
await browser.close()
}
Expand Down

0 comments on commit 2130ff8

Please sign in to comment.