diff --git a/src/diagrams/common/common.js b/src/diagrams/common/common.js
index 975bd6176..8362449a0 100644
--- a/src/diagrams/common/common.js
+++ b/src/diagrams/common/common.js
@@ -27,6 +27,14 @@ export const sanitizeText = (text, config) => {
export const lineBreakRegex = /
/gi;
+export const hasBreaks = text => {
+ return /
/gi.test(text);
+};
+
+export const splitBreaks = text => {
+ return text.split(/
/gi);
+};
+
const breakToPlaceholder = s => {
return s.replace(lineBreakRegex, '#br#');
};
@@ -38,5 +46,7 @@ const placeholderToBreak = s => {
export default {
getRows,
sanitizeText,
+ hasBreaks,
+ splitBreaks,
lineBreakRegex
};
diff --git a/src/diagrams/sequence/sequenceDb.js b/src/diagrams/sequence/sequenceDb.js
index e615cb238..bd32efd2b 100644
--- a/src/diagrams/sequence/sequenceDb.js
+++ b/src/diagrams/sequence/sequenceDb.js
@@ -1,5 +1,7 @@
import mermaidAPI from '../../mermaidAPI';
import configApi from '../../config';
+import common from '../common/common';
+import { logger } from '../../logger';
let prevActor = undefined;
let actors = {};
@@ -134,17 +136,19 @@ export const clear = function() {
export const parseMessage = function(str) {
const _str = str.trim();
- return {
+ const message = {
text: _str.replace(/^[:]?(?:no)?wrap:/, '').trim(),
wrap:
_str.match(/^[:]?(?:no)?wrap:/) === null
- ? autoWrap()
+ ? common.hasBreaks(_str) || autoWrap()
: _str.match(/^[:]?wrap:/) !== null
? true
: _str.match(/^[:]?nowrap:/) !== null
? false
: autoWrap()
};
+ logger.debug('parseMessage:', message);
+ return message;
};
export const LINETYPE = {
diff --git a/src/diagrams/sequence/sequenceRenderer.js b/src/diagrams/sequence/sequenceRenderer.js
index 30f0925b3..88e952250 100644
--- a/src/diagrams/sequence/sequenceRenderer.js
+++ b/src/diagrams/sequence/sequenceRenderer.js
@@ -249,7 +249,7 @@ const drawNote = function(elem, noteModel) {
*/
const drawMessage = function(g, msgModel) {
const { startx, stopx, starty, message, type, sequenceIndex, wrap } = msgModel;
- const lines = message.split(common.lineBreakRegex).length;
+ const lines = common.splitBreaks(message).length;
let textDims = utils.calculateTextDimensions(message, conf.messageFont());
const lineHeight = textDims.height / lines;
msgModel.height += lineHeight;
@@ -461,7 +461,7 @@ function adjustLoopHeightForWrap(loopWidths, msg, preMargin, postMargin, addLoop
msg.width = loopWidth;
msg.wrap = true;
- // const lines = msg.message.split(common.lineBreakRegex).length;
+ // const lines = common.splitBreaks(msg.message).length;
const textDims = utils.calculateTextDimensions(msg.message, textConf);
const totalOffset = Math.max(textDims.height, conf.labelBoxHeight);
heightAdjust = postMargin + totalOffset;
@@ -864,7 +864,7 @@ const calculateActorMargins = function(actors, actorToMessageWidth) {
const buildNoteModel = function(msg, actors) {
let startx = actors[msg.from].x;
let stopx = actors[msg.to].x;
- let shouldWrap = msg.wrap && msg.message && !common.lineBreakRegex.test(msg.message);
+ let shouldWrap = msg.wrap && msg.message;
let textDimensions = utils.calculateTextDimensions(
shouldWrap ? utils.wrapLabel(msg.message, conf.width, conf.noteFont()) : msg.message,
@@ -958,7 +958,7 @@ const buildMessageModel = function(msg, actors) {
const allBounds = fromBounds.concat(toBounds);
const boundedWidth = Math.abs(toBounds[toIdx] - fromBounds[fromIdx]);
const msgDims = utils.calculateTextDimensions(msg.message, conf.messageFont());
- if (msg.wrap && msg.message && !common.lineBreakRegex.test(msg.message)) {
+ if (msg.wrap && msg.message) {
msg.message = utils.wrapLabel(
msg.message,
Math.max(boundedWidth + 2 * conf.wrapPadding, conf.width),
diff --git a/src/utils.js b/src/utils.js
index 6b2222848..b4d59868d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -627,7 +627,7 @@ export const calculateTextDimensions = function(text, config) {
// thus, we'll take the max width between the user supplied font family, and a default
// of sans-serif.
const fontFamilies = ['sans-serif', fontFamily];
- const lines = text.split(common.lineBreakRegex);
+ const lines = common.splitBreaks(text);
let dims = [];
const body = select('body');