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.
|
* You can set this attribute to base the seed on a static string.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
markdownAutoWrap?: boolean;
|
||||||
deterministicIDSeed?: string;
|
deterministicIDSeed?: string;
|
||||||
flowchart?: FlowchartDiagramConfig;
|
flowchart?: FlowchartDiagramConfig;
|
||||||
sequence?: SequenceDiagramConfig;
|
sequence?: SequenceDiagramConfig;
|
||||||
|
@ -2,6 +2,7 @@ import type { Content } from 'mdast';
|
|||||||
import { fromMarkdown } from 'mdast-util-from-markdown';
|
import { fromMarkdown } from 'mdast-util-from-markdown';
|
||||||
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 { getConfig } from '../config.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param markdown - markdown to process
|
* @param markdown - markdown to process
|
||||||
@ -58,10 +59,15 @@ export function markdownToLines(markdown: string): MarkdownLine[] {
|
|||||||
|
|
||||||
export function markdownToHTML(markdown: string) {
|
export function markdownToHTML(markdown: string) {
|
||||||
const { children } = fromMarkdown(markdown);
|
const { children } = fromMarkdown(markdown);
|
||||||
|
const markdownAutoWrap = getConfig().markdownAutoWrap;
|
||||||
|
|
||||||
function output(node: Content): string {
|
function output(node: Content): string {
|
||||||
if (node.type === 'text') {
|
if (node.type === 'text') {
|
||||||
return node.value.replace(/\n/g, '<br/>');
|
if (!markdownAutoWrap) {
|
||||||
|
return node.value.replace(/\n/g, '<br/>').replace(/ /g, ' ');
|
||||||
|
} else {
|
||||||
|
return node.value.replace(/\n/g, '<br/>');
|
||||||
|
}
|
||||||
} else if (node.type === 'strong') {
|
} else if (node.type === 'strong') {
|
||||||
return `<strong>${node.children.map(output).join('')}</strong>`;
|
return `<strong>${node.children.map(output).join('')}</strong>`;
|
||||||
} else if (node.type === 'emphasis') {
|
} else if (node.type === 'emphasis') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user