Skip to content

Commit

Permalink
Merge pull request #1731 from mermaid-js/1724_fontawesome_edge_labels
Browse files Browse the repository at this point in the history
#1724 Adding fontawesome to edge labels
  • Loading branch information
knsv committed Oct 15, 2020
2 parents 1ade6cd + d8da248 commit 8e342e1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
10 changes: 10 additions & 0 deletions cypress/integration/rendering/flowchart-v2.spec.js
Expand Up @@ -346,5 +346,15 @@ flowchart TD
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
);
});
it('61: fontawesome icons in edge labels', () => {
imgSnapshotTest(
`
flowchart TD
C -->|fa:fa-car Car| F[fa:fa-car Car]
`,
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
);
});


});
9 changes: 9 additions & 0 deletions cypress/integration/rendering/flowchart.spec.js
Expand Up @@ -787,5 +787,14 @@ describe('Flowchart', () => {
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
);
});
it('61: fontawesome icons in edge labels', () => {
imgSnapshotTest(
`
graph TD
C -->|fa:fa-car Car| F[fa:fa-car Car]
`,
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
);
});

});
19 changes: 9 additions & 10 deletions cypress/platform/knsv.html
Expand Up @@ -22,7 +22,7 @@
<body>
<h1>info below</h1>
<div class="flex">
<div class="mermaid" style="width: 50%; height: 400px;">
<div class="mermaid2" style="width: 50%; height: 400px;">
graph TD
A[Christmas] ==> D
A[Christmas] -->|Get money| B(Go shopping)
Expand All @@ -38,7 +38,7 @@ <h1>info below</h1>
class T TestSub
linkStyle 0,1 color:orange, stroke: orange;
</div>
<div class="mermaid" style="width: 50%; height: 400px;">
<div class="mermaid2" style="width: 50%; height: 400px;">
flowchart TD
A[Christmas] ==> D
A[Christmas] -->|Get money| B(Go shopping)
Expand All @@ -55,14 +55,13 @@ <h1>info below</h1>
class T TestSub
linkStyle 0,1 color:orange, stroke: orange;
</div>
<div class="mermaid2" style="width: 50%; height: 20%;">
flowchart TB
subgraph A
a -->b
end
subgraph B
b
end
<div class="mermaid" style="width: 50%; height: 20%;">
graph TD
C -->|fa:fa-car Car| F[fa:fa-car Car]
</div>
<div class="mermaid" style="width: 50%; height: 20%;">
flowchart TD
C -->|fa:fa-car Car| F[fa:fa-car Car]
</div>
<div class="mermaid2" style="width: 50%; height: 20%;">
%%{init: {"fontFamily": "arial2"}}%%
Expand Down
5 changes: 4 additions & 1 deletion src/diagrams/flowchart/flowRenderer.js
Expand Up @@ -230,7 +230,10 @@ export const addEdges = function(edges, g) {

if (getConfig().flowchart.htmlLabels) {
edgeData.labelType = 'html';
edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}">${edge.text}</span>`;
edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}">${edge.text.replace(
/fa[lrsb]?:fa-[\w-]+/g,
s => `<i class='${s.replace(':', ' ')}'></i>`
)}</span>`;
} else {
edgeData.labelType = 'text';
edgeData.label = edge.text.replace(common.lineBreakRegex, '\n');
Expand Down

0 comments on commit 8e342e1

Please sign in to comment.