From ed56e4858ade74ece5023fd5c0c7020d1336f91a Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Sat, 30 Apr 2022 16:14:43 +0200 Subject: [PATCH] Cleanup --- src/diagrams/er/erDb.js | 27 +++++++--------------- src/diagrams/gantt/ganttDb.js | 24 +++++++------------ src/diagrams/gantt/parser/gantt.spec.js | 2 +- src/diagrams/state/stateDiagram-v2.spec.js | 4 ++-- 4 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/diagrams/er/erDb.js b/src/diagrams/er/erDb.js index 6f537f27f..7cac00f49 100644 --- a/src/diagrams/er/erDb.js +++ b/src/diagrams/er/erDb.js @@ -2,6 +2,13 @@ import { log } from '../../logger'; import mermaidAPI from '../../mermaidAPI'; import * as configApi from '../../config'; import common from '../common/common'; +import { + setTitle, + getTitle, + getAccDescription, + setAccDescription, + clear as commonClear, +} from '../../commonDb'; let entities = {}; let relationships = []; @@ -68,29 +75,11 @@ const addRelationship = function (entA, rolA, entB, rSpec) { const getRelationships = () => relationships; -// Keep this - TODO: revisit...allow the diagram to have a title -const setTitle = function (txt) { - let sanitizedText = common.sanitizeText(txt, configApi.getConfig()); - title = sanitizedText; -}; - -const getTitle = function () { - return title; -}; - -const setAccDescription = function (txt) { - let sanitizedText = common.sanitizeText(txt, configApi.getConfig()); - description = sanitizedText; -}; - -const getAccDescription = function () { - return description; -}; - const clear = function () { entities = {}; relationships = []; title = ''; + commonClear(); }; export default { diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 0123c565a..a3fc7058c 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -5,6 +5,13 @@ import * as configApi from '../../config'; import utils from '../../utils'; import mermaidAPI from '../../mermaidAPI'; import common from '../common/common'; +import { + setTitle, + getTitle, + getAccDescription, + setAccDescription, + clear as commonClear, +} from '../../commonDb'; let dateFormat = ''; let axisFormat = ''; @@ -52,6 +59,7 @@ export const clear = function () { topAxis = false; lastOrder = 0; links = {}; + commonClear(); }; export const setAxisFormat = function (txt) { @@ -113,22 +121,6 @@ export const getLinks = function () { return links; }; -export const setTitle = function (txt) { - title = sanitizeText(txt); -}; - -export const getTitle = function () { - return title; -}; - -export const setAccDescription = function (txt) { - accDescription = sanitizeText(txt); -}; - -export const getAccDescription = function () { - return accDescription; -}; - export const addSection = function (txt) { currentSection = txt; sections.push(txt); diff --git a/src/diagrams/gantt/parser/gantt.spec.js b/src/diagrams/gantt/parser/gantt.spec.js index 0ed3d170c..39da0f690 100644 --- a/src/diagrams/gantt/parser/gantt.spec.js +++ b/src/diagrams/gantt/parser/gantt.spec.js @@ -175,7 +175,7 @@ describe('when parsing a gantt diagram it', function () { it('should allow for a accessibility title and multiline description (accDescr)', function () { const expectedTitle = 'Gantt Diagram'; const expectedAccDescription = `Tasks for Q4 row1 - row2`; +row2`; const ganttString = `gantt accTitle: ${expectedTitle} accDescr { diff --git a/src/diagrams/state/stateDiagram-v2.spec.js b/src/diagrams/state/stateDiagram-v2.spec.js index 27fce654c..a5aaf8372 100644 --- a/src/diagrams/state/stateDiagram-v2.spec.js +++ b/src/diagrams/state/stateDiagram-v2.spec.js @@ -29,7 +29,7 @@ describe('state diagram, ', function () { }); it('simple with accDescription', function () { const str = `stateDiagram-v2\n - accDescription a simple description of the diagram + accDescr: a simple description of the diagram State1 : this is another string [*] --> State1 State1 --> [*] @@ -41,7 +41,7 @@ describe('state diagram, ', function () { }); it('simple with title', function () { const str = `stateDiagram-v2\n - title a simple title of the diagram + accTitle: a simple title of the diagram State1 : this is another string [*] --> State1 State1 --> [*]