mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-11-04 04:44:08 +01:00 
			
		
		
		
	Updated user journey diagram parsing with the new syntax
This commit is contained in:
		@@ -1,6 +1,13 @@
 | 
			
		||||
import mermaidAPI from '../../mermaidAPI';
 | 
			
		||||
import * as configApi from '../../config';
 | 
			
		||||
import common from '../common/common';
 | 
			
		||||
import {
 | 
			
		||||
  setTitle,
 | 
			
		||||
  getTitle,
 | 
			
		||||
  getAccDescription,
 | 
			
		||||
  setAccDescription,
 | 
			
		||||
  clear as commonClear,
 | 
			
		||||
} from '../../commonDb';
 | 
			
		||||
 | 
			
		||||
const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig());
 | 
			
		||||
 | 
			
		||||
@@ -23,22 +30,7 @@ export const clear = function () {
 | 
			
		||||
  title = '';
 | 
			
		||||
  description = '';
 | 
			
		||||
  rawTasks.length = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const setTitle = function (txt) {
 | 
			
		||||
  title = sanitizeText(txt);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getTitle = function () {
 | 
			
		||||
  return title;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const setAccDescription = function (txt) {
 | 
			
		||||
  description = sanitizeText(txt);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getAccDescription = function () {
 | 
			
		||||
  return description;
 | 
			
		||||
  commonClear();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const addSection = function (txt) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,9 @@
 | 
			
		||||
 */
 | 
			
		||||
%lex
 | 
			
		||||
%options case-insensitive
 | 
			
		||||
%x acc_title
 | 
			
		||||
%x acc_descr
 | 
			
		||||
%x acc_descr_multiline
 | 
			
		||||
 | 
			
		||||
// Directive states
 | 
			
		||||
%x open_directive type_directive arg_directive
 | 
			
		||||
@@ -25,7 +28,13 @@
 | 
			
		||||
 | 
			
		||||
"journey"               return 'journey';
 | 
			
		||||
"title"\s[^#\n;]+       return 'title';
 | 
			
		||||
"accDescription"\s[^#\n;]+       				return 'accDescription';
 | 
			
		||||
accTitle\s*":"\s*                                               { this.begin("acc_title");return 'acc_title'; }
 | 
			
		||||
<acc_title>(?!\n|;|#)*[^\n]*                                    { this.popState(); return "acc_title_value"; }
 | 
			
		||||
accDescr\s*":"\s*                                               { this.begin("acc_descr");return 'acc_descr'; }
 | 
			
		||||
<acc_descr>(?!\n|;|#)*[^\n]*                                    { this.popState(); return "acc_descr_value"; }
 | 
			
		||||
accDescr\s*"{"\s*                                { this.begin("acc_descr_multiline");}
 | 
			
		||||
<acc_descr_multiline>[\}]                       { this.popState(); }
 | 
			
		||||
<acc_descr_multiline>[^\}]*                     return "acc_descr_multiline_value";
 | 
			
		||||
"section"\s[^#:\n;]+    return 'section';
 | 
			
		||||
[^#:\n;]+               return 'taskName';
 | 
			
		||||
":"[^#\n;]+             return 'taskData';
 | 
			
		||||
@@ -65,7 +74,9 @@ directive
 | 
			
		||||
 | 
			
		||||
statement
 | 
			
		||||
  : title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
 | 
			
		||||
  | accDescription {yy.setAccDescription($1.substring(15));$$=$1.substring(15);}
 | 
			
		||||
  | acc_title acc_title_value  { $$=$2.trim();yy.setTitle($$); }
 | 
			
		||||
  | acc_descr acc_descr_value  { $$=$2.trim();yy.setAccDescription($$); }
 | 
			
		||||
  | acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); }
 | 
			
		||||
  | section {yy.addSection($1.substr(8));$$=$1.substr(8);}
 | 
			
		||||
  | taskName taskData {yy.addTask($1, $2);$$='task';}
 | 
			
		||||
  | directive
 | 
			
		||||
 
 | 
			
		||||
@@ -19,15 +19,38 @@ describe('when parsing a journey diagram it', function () {
 | 
			
		||||
    expect(parserFnConstructor(str)).not.toThrow();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('it should handle an accDescription', function () {
 | 
			
		||||
  it('it should handle an accessibility description (accDescr)', function () {
 | 
			
		||||
    const str =
 | 
			
		||||
      'journey\n' +
 | 
			
		||||
      'accDescription A user journey for family shopping\n' +
 | 
			
		||||
      'accDescr: A user journey for family shopping\n' +
 | 
			
		||||
      'title Adding journey diagram functionality to mermaid\n' +
 | 
			
		||||
      'section Order from website';
 | 
			
		||||
 | 
			
		||||
    expect(parserFnConstructor(str)).not.toThrow();
 | 
			
		||||
  });
 | 
			
		||||
  it('it should handle an accessibility multiline description (accDescr)', function () {
 | 
			
		||||
    const str =
 | 
			
		||||
      'journey\n' +
 | 
			
		||||
      `accDescr {
 | 
			
		||||
        A user journey for
 | 
			
		||||
        family shopping
 | 
			
		||||
      }` +
 | 
			
		||||
      'title Adding journey diagram functionality to mermaid\n' +
 | 
			
		||||
      'section Order from website';
 | 
			
		||||
 | 
			
		||||
    expect(parserFnConstructor(str)).not.toThrow();
 | 
			
		||||
    expect(journeyDb.getAccDescription()).toBe('A user journey for\nfamily shopping');
 | 
			
		||||
    expect(journeyDb.getTitle()).toBe('Adding journey diagram functionality to mermaid');
 | 
			
		||||
  });
 | 
			
		||||
  it('it should handle an accessibility title (accDescr)', function () {
 | 
			
		||||
    const str = `journey
 | 
			
		||||
    accTitle: The title
 | 
			
		||||
    section Order from website`;
 | 
			
		||||
 | 
			
		||||
    expect(parserFnConstructor(str)).not.toThrow();
 | 
			
		||||
    expect(journeyDb.getAccDescription()).toBe('');
 | 
			
		||||
    expect(journeyDb.getTitle()).toBe('The title');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should handle a section definition', function () {
 | 
			
		||||
    const str =
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user