mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-16 05:49:43 +02:00
Render empty lines correctly
This commit is contained in:
@@ -93,7 +93,7 @@ context('Sequence diagram', () => {
|
|||||||
`
|
`
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
Alice->>John: Hello John<br/>
|
Alice->>John: Hello John<br/>
|
||||||
John-->>Alice: Great!
|
John-->>Alice: Great<br/><br/>day!
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import common from '../common/common.js';
|
import common from '../common/common.js';
|
||||||
import * as svgDrawCommon from '../common/svgDrawCommon';
|
import * as svgDrawCommon from '../common/svgDrawCommon';
|
||||||
import { addFunction } from '../../interactionDb.js';
|
import { addFunction } from '../../interactionDb.js';
|
||||||
import { parseFontSize } from '../../utils.js';
|
import { ZERO_WIDTH_SPACE, parseFontSize } from '../../utils.js';
|
||||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||||
|
|
||||||
export const drawRect = function (elem, rectData) {
|
export const drawRect = function (elem, rectData) {
|
||||||
@@ -224,15 +224,16 @@ export const drawText = function (elem, textData) {
|
|||||||
textElem.attr('dy', dy);
|
textElem.attr('dy', dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const text = line || ZERO_WIDTH_SPACE;
|
||||||
if (textData.tspan) {
|
if (textData.tspan) {
|
||||||
const span = textElem.append('tspan');
|
const span = textElem.append('tspan');
|
||||||
span.attr('x', textData.x);
|
span.attr('x', textData.x);
|
||||||
if (textData.fill !== undefined) {
|
if (textData.fill !== undefined) {
|
||||||
span.attr('fill', textData.fill);
|
span.attr('fill', textData.fill);
|
||||||
}
|
}
|
||||||
span.text(line);
|
span.text(text);
|
||||||
} else {
|
} else {
|
||||||
textElem.text(line);
|
textElem.text(text);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
textData.valign !== undefined &&
|
textData.valign !== undefined &&
|
||||||
|
@@ -32,6 +32,8 @@ import assignWithDepth from './assignWithDepth.js';
|
|||||||
import { MermaidConfig } from './config.type.js';
|
import { MermaidConfig } from './config.type.js';
|
||||||
import memoize from 'lodash-es/memoize.js';
|
import memoize from 'lodash-es/memoize.js';
|
||||||
|
|
||||||
|
export const ZERO_WIDTH_SPACE = '\u200b';
|
||||||
|
|
||||||
// Effectively an enum of the supported curve types, accessible by name
|
// Effectively an enum of the supported curve types, accessible by name
|
||||||
const d3CurveTypes = {
|
const d3CurveTypes = {
|
||||||
curveBasis: curveBasis,
|
curveBasis: curveBasis,
|
||||||
@@ -764,11 +766,8 @@ export const calculateTextDimensions: (
|
|||||||
let cheight = 0;
|
let cheight = 0;
|
||||||
const dim = { width: 0, height: 0, lineHeight: 0 };
|
const dim = { width: 0, height: 0, lineHeight: 0 };
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const textObj = getTextObj();
|
const textObj = getTextObj();
|
||||||
textObj.text = line;
|
textObj.text = line || ZERO_WIDTH_SPACE;
|
||||||
const textElem = drawSimpleText(g, textObj)
|
const textElem = drawSimpleText(g, textObj)
|
||||||
.style('font-size', _fontSizePx)
|
.style('font-size', _fontSizePx)
|
||||||
.style('font-weight', fontWeight)
|
.style('font-weight', fontWeight)
|
||||||
|
Reference in New Issue
Block a user