mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-19 00:06:47 +02:00
Remove escaped quotes with backslash feature
This commit is contained in:
@@ -901,13 +901,8 @@ graph TD
|
|||||||
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('67: allow escaping quotes with backslash', () => {
|
|
||||||
imgSnapshotTest(`
|
it('67: should be able to style default node independently', () => {
|
||||||
graph TD
|
|
||||||
a_node("This has an escaped \\" in it") -- "edge string can escape too \\"" --> b_node
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
it('68: should be able to style default node independently', () => {
|
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
flowchart TD
|
flowchart TD
|
||||||
|
@@ -610,13 +610,11 @@ For quotation marks, you can escape them with a backslash as well.
|
|||||||
```mermaid-example
|
```mermaid-example
|
||||||
flowchart LR
|
flowchart LR
|
||||||
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
|
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
|
||||||
B --> C["This is a \"square\" vertex"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart LR
|
flowchart LR
|
||||||
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
|
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
|
||||||
B --> C["This is a \"square\" vertex"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Numbers given are base 10, so `#` can be encoded as `#35;`. It is also supported to use HTML character names.
|
Numbers given are base 10, so `#` can be encoded as `#35;`. It is also supported to use HTML character names.
|
||||||
|
@@ -91,7 +91,6 @@ export const addVertex = function (_id, textObj, type, style, classes, dir, prop
|
|||||||
if (textObj !== undefined) {
|
if (textObj !== undefined) {
|
||||||
config = configApi.getConfig();
|
config = configApi.getConfig();
|
||||||
txt = sanitizeText(textObj.text.trim());
|
txt = sanitizeText(textObj.text.trim());
|
||||||
txt = textObj.type === 'string' ? txt.replaceAll('\\"', '"') : txt;
|
|
||||||
vertices[id].labelType = textObj.type;
|
vertices[id].labelType = textObj.type;
|
||||||
// strip quotes if string starts and ends with a quote
|
// strip quotes if string starts and ends with a quote
|
||||||
if (txt[0] === '"' && txt[txt.length - 1] === '"') {
|
if (txt[0] === '"' && txt[txt.length - 1] === '"') {
|
||||||
|
@@ -598,13 +598,6 @@ describe('[Text] when parsing', () => {
|
|||||||
expect(() => flow.parser.parse(str)).toThrowError("Expecting 'SQE'");
|
expect(() => flow.parser.parse(str)).toThrowError("Expecting 'SQE'");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should parse escaped quotes in a string state', function () {
|
|
||||||
//prettier-ignore
|
|
||||||
flow.parser.parse('graph TD; A["This is a \\"()\\" in text"];'); //eslint-disable-line no-useless-escape
|
|
||||||
const vert = flow.parser.yy.getVertices();
|
|
||||||
expect(vert['A'].text).toBe('This is a "()" in text');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw error', function () {
|
it('should throw error', function () {
|
||||||
const str = `graph TD; node[hello ) world] --> works`;
|
const str = `graph TD; node[hello ) world] --> works`;
|
||||||
expect(() => flow.parser.parse(str)).toThrowError("got 'PE'");
|
expect(() => flow.parser.parse(str)).toThrowError("got 'PE'");
|
||||||
|
@@ -60,8 +60,8 @@ Function arguments are optional: 'call <callbackname>()' simply executes 'callba
|
|||||||
|
|
||||||
<md_string>[^`"]+ { return "MD_STR";}
|
<md_string>[^`"]+ { return "MD_STR";}
|
||||||
<md_string>[`]["] { this.popState();}
|
<md_string>[`]["] { this.popState();}
|
||||||
<*>["][`] { this.begin("md_string");}
|
<*>["][`] { this.begin("md_string");}
|
||||||
<string>(\\(?=\")\"|[^"])+ return "STR";
|
<string>[^"]+ return "STR";
|
||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<*>["] this.pushState("string");
|
<*>["] this.pushState("string");
|
||||||
"style" return 'STYLE';
|
"style" return 'STYLE';
|
||||||
|
@@ -392,7 +392,6 @@ For quotation marks, you can escape them with a backslash as well.
|
|||||||
```mermaid-example
|
```mermaid-example
|
||||||
flowchart LR
|
flowchart LR
|
||||||
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
|
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
|
||||||
B --> C["This is a \"square\" vertex"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Numbers given are base 10, so `#` can be encoded as `#35;`. It is also supported to use HTML character names.
|
Numbers given are base 10, so `#` can be encoded as `#35;`. It is also supported to use HTML character names.
|
||||||
|
Reference in New Issue
Block a user