mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-11-03 20:34:20 +01:00 
			
		
		
		
	#1038 Updated prefix for the internal dom id
This commit is contained in:
		@@ -356,4 +356,25 @@ describe('Flowcart', () => {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					  it('13: should render hexagons', () => {
 | 
				
			||||||
 | 
					    imgSnapshotTest(
 | 
				
			||||||
 | 
					      `
 | 
				
			||||||
 | 
					      graph TD
 | 
				
			||||||
 | 
					        A[Christmas] -->|Get money| B(Go shopping)
 | 
				
			||||||
 | 
					        B --> C{{Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?}}
 | 
				
			||||||
 | 
					        C -->|One| D[Laptop]
 | 
				
			||||||
 | 
					        C -->|Two| E[iPhone]
 | 
				
			||||||
 | 
					        C -->|Three| F[Car]
 | 
				
			||||||
 | 
					        click A "index.html#link-clicked" "link test"
 | 
				
			||||||
 | 
					        click B testClick "click test"
 | 
				
			||||||
 | 
					        classDef someclass fill:#f96;
 | 
				
			||||||
 | 
					        class A someclass;
 | 
				
			||||||
 | 
					      `,
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        listUrl: false,
 | 
				
			||||||
 | 
					        listId: 'color styling',
 | 
				
			||||||
 | 
					        logLevel: 0
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,8 @@ import { logger } from '../../logger';
 | 
				
			|||||||
import utils from '../../utils';
 | 
					import utils from '../../utils';
 | 
				
			||||||
import { getConfig } from '../../config';
 | 
					import { getConfig } from '../../config';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const MERMAID_DOM_ID_PREFIX = 'mermaid-dom-id';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const config = getConfig();
 | 
					const config = getConfig();
 | 
				
			||||||
let vertices = {};
 | 
					let vertices = {};
 | 
				
			||||||
let edges = [];
 | 
					let edges = [];
 | 
				
			||||||
@@ -48,7 +50,7 @@ export const addVertex = function(_id, text, type, style, classes) {
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (id[0].match(/\d/)) id = 's' + id;
 | 
					  if (id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (typeof vertices[id] === 'undefined') {
 | 
					  if (typeof vertices[id] === 'undefined') {
 | 
				
			||||||
    vertices[id] = { id: id, styles: [], classes: [] };
 | 
					    vertices[id] = { id: id, styles: [], classes: [] };
 | 
				
			||||||
@@ -96,8 +98,8 @@ export const addVertex = function(_id, text, type, style, classes) {
 | 
				
			|||||||
export const addLink = function(_start, _end, type, linktext) {
 | 
					export const addLink = function(_start, _end, type, linktext) {
 | 
				
			||||||
  let start = _start;
 | 
					  let start = _start;
 | 
				
			||||||
  let end = _end;
 | 
					  let end = _end;
 | 
				
			||||||
  if (start[0].match(/\d/)) start = 's' + start;
 | 
					  if (start[0].match(/\d/)) start = MERMAID_DOM_ID_PREFIX + start;
 | 
				
			||||||
  if (end[0].match(/\d/)) end = 's' + end;
 | 
					  if (end[0].match(/\d/)) end = MERMAID_DOM_ID_PREFIX + end;
 | 
				
			||||||
  logger.info('Got edge...', start, end);
 | 
					  logger.info('Got edge...', start, end);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const edge = { start: start, end: end, type: undefined, text: '' };
 | 
					  const edge = { start: start, end: end, type: undefined, text: '' };
 | 
				
			||||||
@@ -194,7 +196,7 @@ export const setDirection = function(dir) {
 | 
				
			|||||||
export const setClass = function(ids, className) {
 | 
					export const setClass = function(ids, className) {
 | 
				
			||||||
  ids.split(',').forEach(function(_id) {
 | 
					  ids.split(',').forEach(function(_id) {
 | 
				
			||||||
    let id = _id;
 | 
					    let id = _id;
 | 
				
			||||||
    if (_id[0].match(/\d/)) id = 's' + id;
 | 
					    if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
 | 
				
			||||||
    if (typeof vertices[id] !== 'undefined') {
 | 
					    if (typeof vertices[id] !== 'undefined') {
 | 
				
			||||||
      vertices[id].classes.push(className);
 | 
					      vertices[id].classes.push(className);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -215,7 +217,7 @@ const setTooltip = function(ids, tooltip) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const setClickFun = function(_id, functionName) {
 | 
					const setClickFun = function(_id, functionName) {
 | 
				
			||||||
  let id = _id;
 | 
					  let id = _id;
 | 
				
			||||||
  if (_id[0].match(/\d/)) id = 's' + id;
 | 
					  if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
 | 
				
			||||||
  if (config.securityLevel !== 'loose') {
 | 
					  if (config.securityLevel !== 'loose') {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -247,7 +249,7 @@ const setClickFun = function(_id, functionName) {
 | 
				
			|||||||
export const setLink = function(ids, linkStr, tooltip) {
 | 
					export const setLink = function(ids, linkStr, tooltip) {
 | 
				
			||||||
  ids.split(',').forEach(function(_id) {
 | 
					  ids.split(',').forEach(function(_id) {
 | 
				
			||||||
    let id = _id;
 | 
					    let id = _id;
 | 
				
			||||||
    if (_id[0].match(/\d/)) id = 's' + id;
 | 
					    if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
 | 
				
			||||||
    if (typeof vertices[id] !== 'undefined') {
 | 
					    if (typeof vertices[id] !== 'undefined') {
 | 
				
			||||||
      if (config.securityLevel !== 'loose') {
 | 
					      if (config.securityLevel !== 'loose') {
 | 
				
			||||||
        vertices[id].link = sanitizeUrl(linkStr); // .replace(/javascript:.*/g, '')
 | 
					        vertices[id].link = sanitizeUrl(linkStr); // .replace(/javascript:.*/g, '')
 | 
				
			||||||
@@ -406,11 +408,11 @@ export const addSubGraph = function(_id, list, _title) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  nodeList = uniq(nodeList.concat.apply(nodeList, list));
 | 
					  nodeList = uniq(nodeList.concat.apply(nodeList, list));
 | 
				
			||||||
  for (let i = 0; i < nodeList.length; i++) {
 | 
					  for (let i = 0; i < nodeList.length; i++) {
 | 
				
			||||||
    if (nodeList[i][0].match(/\d/)) nodeList[i] = 's' + nodeList[i];
 | 
					    if (nodeList[i][0].match(/\d/)) nodeList[i] = MERMAID_DOM_ID_PREFIX + nodeList[i];
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  id = id || 'subGraph' + subCount;
 | 
					  id = id || 'subGraph' + subCount;
 | 
				
			||||||
  if (id[0].match(/\d/)) id = 's' + id;
 | 
					  if (id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
 | 
				
			||||||
  title = title || '';
 | 
					  title = title || '';
 | 
				
			||||||
  title = sanitize(title);
 | 
					  title = sanitize(title);
 | 
				
			||||||
  subCount = subCount + 1;
 | 
					  subCount = subCount + 1;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user