mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-14 22:09:29 +02:00
Merge pull request #6855 from mermaid-js/sidv/showRawData
fix: fallback to raw text instead of rendering *Unsupported markdown*
This commit is contained in:
9
.changeset/strong-laws-confess.md
Normal file
9
.changeset/strong-laws-confess.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: fallback to raw text instead of rendering _Unsupported markdown_ or empty blocks
|
||||||
|
|
||||||
|
Instead of printing **Unsupported markdown: XXX**, or empty blocks when using a markdown feature
|
||||||
|
that Mermaid does not yet support when `htmlLabels: true`(default) or `htmlLabels: false`,
|
||||||
|
fallback to the raw markdown text.
|
@@ -1164,4 +1164,26 @@ end
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when rendering unsuported markdown', () => {
|
||||||
|
const graph = `flowchart TB
|
||||||
|
mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"\`<**1**1\`"--> fine["No bug"]
|
||||||
|
mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"]
|
||||||
|
subgraph subgraph1["\`How to fix **fix**\`"]
|
||||||
|
broken --> B["B"]
|
||||||
|
end
|
||||||
|
githost["Github, Gitlab, BitBucket, etc."]
|
||||||
|
githost2["\`Github, Gitlab, BitBucket, etc.\`"]
|
||||||
|
a["1."]
|
||||||
|
b["- x"]
|
||||||
|
`;
|
||||||
|
|
||||||
|
it('should render raw strings', () => {
|
||||||
|
imgSnapshotTest(graph);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render raw strings with htmlLabels: false', () => {
|
||||||
|
imgSnapshotTest(graph, { htmlLabels: false });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -285,7 +285,11 @@ test('markdownToHTML - Unsupported formatting', () => {
|
|||||||
- l1
|
- l1
|
||||||
- l2
|
- l2
|
||||||
- l3`)
|
- l3`)
|
||||||
).toMatchInlineSnapshot('"<p>Hello</p>Unsupported markdown: list"');
|
).toMatchInlineSnapshot(`
|
||||||
|
"<p>Hello</p> - l1
|
||||||
|
- l2
|
||||||
|
- l3"
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('markdownToHTML - no auto wrapping', () => {
|
test('markdownToHTML - no auto wrapping', () => {
|
||||||
|
@@ -3,6 +3,7 @@ import { marked } from 'marked';
|
|||||||
import { dedent } from 'ts-dedent';
|
import { dedent } from 'ts-dedent';
|
||||||
import type { MarkdownLine, MarkdownWordType } from './types.js';
|
import type { MarkdownLine, MarkdownWordType } from './types.js';
|
||||||
import type { MermaidConfig } from '../config.type.js';
|
import type { MermaidConfig } from '../config.type.js';
|
||||||
|
import { log } from '../logger.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param markdown - markdown to process
|
* @param markdown - markdown to process
|
||||||
@@ -61,6 +62,8 @@ export function markdownToLines(markdown: string, config: MermaidConfig = {}): M
|
|||||||
});
|
});
|
||||||
} else if (treeNode.type === 'html') {
|
} else if (treeNode.type === 'html') {
|
||||||
lines[currentLine].push({ content: treeNode.text, type: 'normal' });
|
lines[currentLine].push({ content: treeNode.text, type: 'normal' });
|
||||||
|
} else {
|
||||||
|
lines[currentLine].push({ content: treeNode.raw, type: 'normal' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -89,7 +92,8 @@ export function markdownToHTML(markdown: string, { markdownAutoWrap }: MermaidCo
|
|||||||
} else if (node.type === 'escape') {
|
} else if (node.type === 'escape') {
|
||||||
return node.text;
|
return node.text;
|
||||||
}
|
}
|
||||||
return `Unsupported markdown: ${node.type}`;
|
log.warn(`Unsupported markdown: ${node.type}`);
|
||||||
|
return node.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes.map(output).join('');
|
return nodes.map(output).join('');
|
||||||
|
Reference in New Issue
Block a user