mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
make auto wrapping in markdown optional
This commit is contained in:
parent
4201e4775d
commit
43885e6d0b
@ -139,6 +139,7 @@ export interface MermaidConfig {
|
||||
* You can set this attribute to base the seed on a static string.
|
||||
*
|
||||
*/
|
||||
markdownAutoWrap?: boolean;
|
||||
deterministicIDSeed?: string;
|
||||
flowchart?: FlowchartDiagramConfig;
|
||||
sequence?: SequenceDiagramConfig;
|
||||
|
@ -2,6 +2,7 @@ import type { Content } from 'mdast';
|
||||
import { fromMarkdown } from 'mdast-util-from-markdown';
|
||||
import { dedent } from 'ts-dedent';
|
||||
import type { MarkdownLine, MarkdownWordType } from './types.js';
|
||||
import { getConfig } from '../config.js';
|
||||
|
||||
/**
|
||||
* @param markdown - markdown to process
|
||||
@ -58,10 +59,15 @@ export function markdownToLines(markdown: string): MarkdownLine[] {
|
||||
|
||||
export function markdownToHTML(markdown: string) {
|
||||
const { children } = fromMarkdown(markdown);
|
||||
const markdownAutoWrap = getConfig().markdownAutoWrap;
|
||||
|
||||
function output(node: Content): string {
|
||||
if (node.type === 'text') {
|
||||
if (!markdownAutoWrap) {
|
||||
return node.value.replace(/\n/g, '<br/>').replace(/ /g, ' ');
|
||||
} else {
|
||||
return node.value.replace(/\n/g, '<br/>');
|
||||
}
|
||||
} else if (node.type === 'strong') {
|
||||
return `<strong>${node.children.map(output).join('')}</strong>`;
|
||||
} else if (node.type === 'emphasis') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user