diff --git a/src/diagrams/class/classDb.js b/src/diagrams/class/classDb.js index 158c8f4c7..78baed8d5 100644 --- a/src/diagrams/class/classDb.js +++ b/src/diagrams/class/classDb.js @@ -16,7 +16,7 @@ let classCounter = 0; let funs = []; export const parseDirective = function(statement, context, type) { - mermaidAPI.parseDirective(statement, context, type); + mermaidAPI.parseDirective(this, statement, context, type); }; const splitClassNameAndType = function(id) { diff --git a/src/diagrams/er/erDb.js b/src/diagrams/er/erDb.js index 7208c8594..1f1d92519 100644 --- a/src/diagrams/er/erDb.js +++ b/src/diagrams/er/erDb.js @@ -21,7 +21,7 @@ const Identification = { }; export const parseDirective = function(statement, context, type) { - mermaidAPI.parseDirective(statement, context, type); + mermaidAPI.parseDirective(this, statement, context, type); }; const addEntity = function(name) { diff --git a/src/diagrams/flowchart/flowDb.js b/src/diagrams/flowchart/flowDb.js index d5fcb7b94..5063ea655 100644 --- a/src/diagrams/flowchart/flowDb.js +++ b/src/diagrams/flowchart/flowDb.js @@ -21,7 +21,7 @@ let direction; let funs = []; export const parseDirective = function(statement, context, type) { - mermaidAPI.parseDirective(statement, context, type); + mermaidAPI.parseDirective(this, statement, context, type); }; /** diff --git a/src/diagrams/sequence/parser/sequenceDiagram.jison b/src/diagrams/sequence/parser/sequenceDiagram.jison index 73f057fb9..a8b4efe2c 100644 --- a/src/diagrams/sequence/parser/sequenceDiagram.jison +++ b/src/diagrams/sequence/parser/sequenceDiagram.jison @@ -26,12 +26,12 @@ ":" { this.popState(); this.begin('arg_directive'); return ':'; } \}\%\% { this.popState(); this.popState(); return 'close_directive'; } ((?:(?!\}\%\%).|\n)*) return 'arg_directive'; -\%%(?!\{)[^\n]* /* skip comments */ -[^\}]\%\%[^\n]* /* skip comments */ [\n]+ return 'NEWLINE'; \s+ /* skip all whitespace */ ((?!\n)\s)+ /* skip same-line whitespace */ \#[^\n]* /* skip comments */ +\%%(?!\{)[^\n]* /* skip comments */ +[^\}]\%\%[^\n]* /* skip comments */ "participant" { this.begin('ID'); return 'participant'; } [^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } "as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; } diff --git a/src/diagrams/sequence/sequenceDb.js b/src/diagrams/sequence/sequenceDb.js index bd32efd2b..92574dac7 100644 --- a/src/diagrams/sequence/sequenceDb.js +++ b/src/diagrams/sequence/sequenceDb.js @@ -13,7 +13,7 @@ let sequenceNumbersEnabled = false; let wrapEnabled = false; export const parseDirective = function(statement, context, type) { - mermaidAPI.parseDirective(statement, context, type); + mermaidAPI.parseDirective(this, statement, context, type); }; export const addActor = function(id, name, description) { @@ -140,12 +140,12 @@ export const parseMessage = function(str) { text: _str.replace(/^[:]?(?:no)?wrap:/, '').trim(), wrap: _str.match(/^[:]?(?:no)?wrap:/) === null - ? common.hasBreaks(_str) || autoWrap() + ? common.hasBreaks(_str) || undefined : _str.match(/^[:]?wrap:/) !== null ? true : _str.match(/^[:]?nowrap:/) !== null ? false - : autoWrap() + : undefined }; logger.debug('parseMessage:', message); return message; diff --git a/src/diagrams/sequence/sequenceDiagram.spec.js b/src/diagrams/sequence/sequenceDiagram.spec.js index a80c921d3..ffff6a1a8 100644 --- a/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/src/diagrams/sequence/sequenceDiagram.spec.js @@ -932,7 +932,6 @@ describe('when rendering a sequenceDiagram', function() { parser.yy = sequenceDb; parser.yy.clear(); conf = parser.yy.getConfig(); - renderer.bounds.init(); }); ['tspan', 'fo', 'old', undefined].forEach(function(textPlacement) { it(` diff --git a/src/diagrams/user-journey/journeyDb.js b/src/diagrams/user-journey/journeyDb.js index 6de0c5fad..aa721ee7d 100644 --- a/src/diagrams/user-journey/journeyDb.js +++ b/src/diagrams/user-journey/journeyDb.js @@ -8,7 +8,7 @@ const tasks = []; const rawTasks = []; export const parseDirective = function(statement, context, type) { - mermaidAPI.parseDirective(statement, context, type); + mermaidAPI.parseDirective(this, statement, context, type); }; export const clear = function() { diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index 4587033e6..77fd5b71c 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -438,7 +438,7 @@ const render = function(id, _txt, cb, container) { let currentDirective = {}; -const parseDirective = function(statement, context, type) { +const parseDirective = function(p, statement, context, type) { try { if (statement !== undefined) { statement = statement.trim(); @@ -453,7 +453,7 @@ const parseDirective = function(statement, context, type) { currentDirective.args = JSON.parse(statement); break; case 'close_directive': - handleDirective(currentDirective, type); + handleDirective(p, currentDirective, type); currentDirective = null; break; } @@ -466,7 +466,7 @@ const parseDirective = function(statement, context, type) { } }; -const handleDirective = function(directive, type) { +const handleDirective = function(p, directive, type) { logger.debug(`Directive type=${directive.type} with args:`, directive.args); switch (directive.type) { case 'init': @@ -486,17 +486,9 @@ const handleDirective = function(directive, type) { } case 'wrap': case 'nowrap': - directive.args = { config: { wrap: directive.type === 'wrap' } }; - ['config'].forEach(prop => { - if (typeof directive.args[prop] !== 'undefined') { - if (type === 'flowchart-v2') { - type = 'flowchart'; - } - directive.args[type] = directive.args[prop]; - delete directive.args[prop]; - } - }); - reinitialize(directive.args); + if (p && p['setWrap']) { + p.setWrap(directive.type === 'wrap'); + } break; default: logger.warn( diff --git a/src/utils.spec.js b/src/utils.spec.js index 85e9b1120..08c4654e0 100644 --- a/src/utils.spec.js +++ b/src/utils.spec.js @@ -116,13 +116,13 @@ Alice->Bob: hi`; }); it('should handle an init definition with config converted to the proper diagram configuration', function() { const str = ` -%%{init: { 'logLevel': 0, 'theme': 'dark', 'config': {'wrapEnabled': true} } }%% +%%{init: { 'logLevel': 0, 'theme': 'dark', 'config': {'wrap': true} } }%% sequenceDiagram Alice->Bob: hi`; const type = utils.detectType(str); const init = utils.detectInit(str); expect(type).toBe('sequence'); - expect(init).toEqual({logLevel:0, theme:"dark", sequence: { wrapEnabled: true }}); + expect(init).toEqual({logLevel:0, theme:"dark", sequence: { wrap: true }}); }); it('should handle a multiline init definition', function() { const str = `