Skip to content

Commit

Permalink
Use a library-level variable for assigning ids
Browse files Browse the repository at this point in the history
The current behavior is unexpected when re-running `init()`, as every run through will start with the first `.mermaid` it finds, and start re-indexing at 0, irrespective if the original `id=mermaidChart0` is still around.

This change ensures that successive runs will not clobber old ones.
  • Loading branch information
bollwyvl committed Mar 10, 2015
1 parent 3ae1b5f commit 6aff481
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var gantt = require('./diagrams/gantt/ganttRenderer');
var ganttParser = require('./diagrams/gantt/parser/gantt');
var ganttDb = require('./diagrams/gantt/ganttDb');

var nextId = 0;

/**
* Function that parses a mermaid diagram defintion. If parsing fails the parseError callback is called and an error is
* thrown and
Expand Down Expand Up @@ -80,7 +82,6 @@ var init = function (sequenceConfig) {
}
}

var cnt = 0;
for (i = 0; i < arr.length; i++) {
var element = arr[i];

Expand All @@ -91,10 +92,7 @@ var init = function (sequenceConfig) {
continue;
}

var id;

id = 'mermaidChart' + cnt;
cnt++;
id = 'mermaidChart' + nextId++;

var txt = element.innerHTML;
txt = txt.replace(/>/g,'&gt;');
Expand Down

0 comments on commit 6aff481

Please sign in to comment.