mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge branch '5237-unified-layout-common-renderer' of github.com:mermaid-js/mermaid into 5237-unified-layout-common-renderer
This commit is contained in:
commit
09c5c62e07
@ -99,7 +99,7 @@ describe('Flowchart v2', () => {
|
|||||||
const style = svg.attr('style');
|
const style = svg.attr('style');
|
||||||
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
||||||
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
||||||
expect(maxWidthValue).to.be.within(290 * 0.95 - 1, 290 * 1.05);
|
expect(maxWidthValue).to.be.within(446 * 0.95 - 1, 446 * 1.05);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('8: should render a flowchart when useMaxWidth is false', () => {
|
it('8: should render a flowchart when useMaxWidth is false', () => {
|
||||||
@ -118,7 +118,7 @@ describe('Flowchart v2', () => {
|
|||||||
const width = parseFloat(svg.attr('width'));
|
const width = parseFloat(svg.attr('width'));
|
||||||
// use within because the absolute value can be slightly different depending on the environment ±5%
|
// use within because the absolute value can be slightly different depending on the environment ±5%
|
||||||
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
|
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
|
||||||
expect(width).to.be.within(290 * 0.95 - 1, 290 * 1.05);
|
expect(width).to.be.within(446 * 0.95 - 1, 446 * 1.05);
|
||||||
expect(svg).to.not.have.attr('style');
|
expect(svg).to.not.have.attr('style');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1047,7 +1047,9 @@ end
|
|||||||
A --lb3--> TOP --lb4--> B
|
A --lb3--> TOP --lb4--> B
|
||||||
B1 --lb5--> B2
|
B1 --lb5--> B2
|
||||||
`,
|
`,
|
||||||
{ flowchart: { subGraphTitleMargin: { top: 10, bottom: 5 } } }
|
{
|
||||||
|
flowchart: { subGraphTitleMargin: { top: 10, bottom: 5 } },
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -733,7 +733,7 @@ describe('Graph', () => {
|
|||||||
});
|
});
|
||||||
it('38: should render a flowchart when useMaxWidth is true (default)', () => {
|
it('38: should render a flowchart when useMaxWidth is true (default)', () => {
|
||||||
renderGraph(
|
renderGraph(
|
||||||
`graph TD
|
`flowchart TD
|
||||||
A[Christmas] -->|Get money| B(Go shopping)
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
B --> C{Let me think}
|
B --> C{Let me think}
|
||||||
C -->|One| D[Laptop]
|
C -->|One| D[Laptop]
|
||||||
@ -751,7 +751,7 @@ describe('Graph', () => {
|
|||||||
const style = svg.attr('style');
|
const style = svg.attr('style');
|
||||||
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
||||||
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
||||||
expect(maxWidthValue).to.be.within(300 * 0.9, 300 * 1.1);
|
expect(maxWidthValue).to.be.within(446 * 0.9, 446 * 1.1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('39: should render a flowchart when useMaxWidth is false', () => {
|
it('39: should render a flowchart when useMaxWidth is false', () => {
|
||||||
@ -770,7 +770,7 @@ describe('Graph', () => {
|
|||||||
const width = parseFloat(svg.attr('width'));
|
const width = parseFloat(svg.attr('width'));
|
||||||
// use within because the absolute value can be slightly different depending on the environment ±10%
|
// use within because the absolute value can be slightly different depending on the environment ±10%
|
||||||
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
|
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
|
||||||
expect(width).to.be.within(300 * 0.9, 300 * 1.1);
|
expect(width).to.be.within(446 * 0.9, 446 * 1.1);
|
||||||
expect(svg).to.not.have.attr('style');
|
expect(svg).to.not.have.attr('style');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -911,7 +911,10 @@ graph TD
|
|||||||
|
|
||||||
style default stroke:#000,stroke-width:4px
|
style default stroke:#000,stroke-width:4px
|
||||||
`,
|
`,
|
||||||
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
{
|
||||||
|
flowchart: { htmlLabels: true },
|
||||||
|
securityLevel: 'loose',
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -224,7 +224,9 @@ export const createText = async (
|
|||||||
const vertexNode = await addHtmlSpan(el, node, width, classes, addSvgBackground);
|
const vertexNode = await addHtmlSpan(el, node, width, classes, addSvgBackground);
|
||||||
return vertexNode;
|
return vertexNode;
|
||||||
} else {
|
} else {
|
||||||
const structuredText = markdownToLines(text.replace('<br>', '<br/>'), config);
|
//sometimes the user might add br tags with 1 or more spaces in between, so we need to replace them with <br/>
|
||||||
|
const sanitizeBR = text.replace(/<br\s*\/?>/g, '<br/>');
|
||||||
|
const structuredText = markdownToLines(sanitizeBR.replace('<br>', '<br/>'), config);
|
||||||
const svgLabel = createFormattedText(
|
const svgLabel = createFormattedText(
|
||||||
width,
|
width,
|
||||||
el,
|
el,
|
||||||
@ -235,9 +237,13 @@ export const createText = async (
|
|||||||
if (/stroke:/.exec(style)) {
|
if (/stroke:/.exec(style)) {
|
||||||
style = style.replace('stroke:', 'lineColor:');
|
style = style.replace('stroke:', 'lineColor:');
|
||||||
}
|
}
|
||||||
select(svgLabel)
|
|
||||||
.select('text')
|
const nodeLabelTextStyle = style
|
||||||
.attr('style', style.replace(/color:/g, 'fill:'));
|
.replace(/stroke:[^;]+;?/g, '')
|
||||||
|
.replace(/stroke-width:[^;]+;?/g, '')
|
||||||
|
.replace(/fill:[^;]+;?/g, '')
|
||||||
|
.replace(/color:/g, 'fill:');
|
||||||
|
select(svgLabel).attr('style', nodeLabelTextStyle);
|
||||||
// svgLabel.setAttribute('style', style);
|
// svgLabel.setAttribute('style', style);
|
||||||
} else {
|
} else {
|
||||||
//On style, assume `stroke`, `stroke-width` are used for edge path, so remove them
|
//On style, assume `stroke`, `stroke-width` are used for edge path, so remove them
|
||||||
|
@ -81,6 +81,8 @@ export function markdownToHTML(markdown: string, { markdownAutoWrap }: MermaidCo
|
|||||||
return `<em>${node.tokens?.map(output).join('')}</em>`;
|
return `<em>${node.tokens?.map(output).join('')}</em>`;
|
||||||
} else if (node.type === 'paragraph') {
|
} else if (node.type === 'paragraph') {
|
||||||
return `<p>${node.tokens?.map(output).join('')}</p>`;
|
return `<p>${node.tokens?.map(output).join('')}</p>`;
|
||||||
|
} else if (node.type === 'space') {
|
||||||
|
return '';
|
||||||
} else if (node.type === 'html') {
|
} else if (node.type === 'html') {
|
||||||
return `${node.text}`;
|
return `${node.text}`;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user