Remove escaped quotes with backslash feature

This commit is contained in:
Ibrahim Wassouf
2023-07-31 21:35:56 -03:00
parent b5456813e8
commit 834c67ecaa
6 changed files with 4 additions and 20 deletions

View File

@@ -901,13 +901,8 @@ graph TD
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
);
});
it('67: allow escaping quotes with backslash', () => {
imgSnapshotTest(`
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', () => {
it('67: should be able to style default node independently', () => {
imgSnapshotTest(
`
flowchart TD

View File

@@ -610,13 +610,11 @@ For quotation marks, you can escape them with a backslash as well.
```mermaid-example
flowchart LR
A["A double quote:#quot;"] --> B["A dec char:#9829;"]
B --> C["This is a \"square\" vertex"]
```
```mermaid
flowchart LR
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.

View File

@@ -91,7 +91,6 @@ export const addVertex = function (_id, textObj, type, style, classes, dir, prop
if (textObj !== undefined) {
config = configApi.getConfig();
txt = sanitizeText(textObj.text.trim());
txt = textObj.type === 'string' ? txt.replaceAll('\\"', '"') : txt;
vertices[id].labelType = textObj.type;
// strip quotes if string starts and ends with a quote
if (txt[0] === '"' && txt[txt.length - 1] === '"') {

View File

@@ -598,13 +598,6 @@ describe('[Text] when parsing', () => {
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 () {
const str = `graph TD; node[hello ) world] --> works`;
expect(() => flow.parser.parse(str)).toThrowError("got 'PE'");

View File

@@ -61,7 +61,7 @@ Function arguments are optional: 'call <callbackname>()' simply executes 'callba
<md_string>[^`"]+ { return "MD_STR";}
<md_string>[`]["] { this.popState();}
<*>["][`] { this.begin("md_string");}
<string>(\\(?=\")\"|[^"])+ return "STR";
<string>[^"]+ return "STR";
<string>["] this.popState();
<*>["] this.pushState("string");
"style" return 'STYLE';

View File

@@ -392,7 +392,6 @@ For quotation marks, you can escape them with a backslash as well.
```mermaid-example
flowchart LR
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.