Skip to content

Commit

Permalink
feat(inline-svg): remove xml tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Nov 24, 2023
1 parent fe9973e commit 074f203
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/transform.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { fetchData, mime, toDataURL } from './utils.mjs';

/* eslint-disable no-param-reassign */

function removeXML(string) {
return string.replace(/<\?xml.+\?>/, '');
}

const modes = {
'img-base64': ({ node, diagramType, data, alt }) => {
node.type = 'paragraph';
Expand Down Expand Up @@ -31,7 +35,7 @@ const modes = {
node.type = 'html';
node.value = `<div class="kroki-inline-svg" data-type="${diagramType}" data-alt="${
alt || diagramType
}">${data.toString()}</div>`;
}">${removeXML(data.toString())}</div>`;
},
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-kroki",
"version": "0.2.11",
"version": "0.2.12",
"description": "Remark plugin for showing Kroki diagram",
"license": "MIT",
"author": {
Expand Down
4 changes: 2 additions & 2 deletions test/snapshots/output.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Generated by [AVA](https://avajs.dev).
[
{
type: 'html',
value: '<div class="kroki-inline-svg" data-type="plantuml" data-alt="plantuml"><?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http:https://www.w3.org/2000/svg" xmlns:xlink="http:https://www.w3.org/1999/xlink" contentStyleType="text/css" height="105px" preserveAspectRatio="none" style="width:68px;height:105px;background:#FFFFFF;" version="1.1" viewBox="0 0 68 105" width="68px" zoomAndPan="magnify"><defs/><g><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="16" x2="16" y1="36.2969" y2="70.2969"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="50" x2="50" y1="36.2969" y2="70.2969"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="24.9951">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="89.292">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="24.9951">B</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="89.292">B</text><polygon fill="#181818" points="38,48.2969,48,52.2969,38,56.2969,42,52.2969" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="16.5" x2="44" y1="52.2969" y2="52.2969"/><!--SRC=[SrJGrRLJS080]--></g></svg></div>',
value: '<div class="kroki-inline-svg" data-type="plantuml" data-alt="plantuml"><svg xmlns="http:https://www.w3.org/2000/svg" xmlns:xlink="http:https://www.w3.org/1999/xlink" contentStyleType="text/css" height="105px" preserveAspectRatio="none" style="width:68px;height:105px;background:#FFFFFF;" version="1.1" viewBox="0 0 68 105" width="68px" zoomAndPan="magnify"><defs/><g><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="16" x2="16" y1="36.2969" y2="70.2969"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="50" x2="50" y1="36.2969" y2="70.2969"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="24.9951">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="89.292">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="24.9951">B</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="89.292">B</text><polygon fill="#181818" points="38,48.2969,48,52.2969,38,56.2969,42,52.2969" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="16.5" x2="44" y1="52.2969" y2="52.2969"/><!--SRC=[SrJGrRLJS080]--></g></svg></div>',
},
]

> Snapshot 4
'<div class="kroki-inline-svg" data-type="plantuml" data-alt="plantuml"><?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http:https://www.w3.org/2000/svg" xmlns:xlink="http:https://www.w3.org/1999/xlink" contentStyleType="text/css" height="105px" preserveAspectRatio="none" style="width:68px;height:105px;background:#FFFFFF;" version="1.1" viewBox="0 0 68 105" width="68px" zoomAndPan="magnify"><defs/><g><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="16" x2="16" y1="36.2969" y2="70.2969"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="50" x2="50" y1="36.2969" y2="70.2969"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="24.9951">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="89.292">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="24.9951">B</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="89.292">B</text><polygon fill="#181818" points="38,48.2969,48,52.2969,38,56.2969,42,52.2969" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="16.5" x2="44" y1="52.2969" y2="52.2969"/><!--SRC=[SrJGrRLJS080]--></g></svg></div>'
'<div class="kroki-inline-svg" data-type="plantuml" data-alt="plantuml"><svg xmlns="http:https://www.w3.org/2000/svg" xmlns:xlink="http:https://www.w3.org/1999/xlink" contentStyleType="text/css" height="105px" preserveAspectRatio="none" style="width:68px;height:105px;background:#FFFFFF;" version="1.1" viewBox="0 0 68 105" width="68px" zoomAndPan="magnify"><defs/><g><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="16" x2="16" y1="36.2969" y2="70.2969"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="50" x2="50" y1="36.2969" y2="70.2969"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="24.9951">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="23" x="5" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="9" x="12" y="89.292">A</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="24.9951">B</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="24" x="38" y="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="45" y="89.292">B</text><polygon fill="#181818" points="38,48.2969,48,52.2969,38,56.2969,42,52.2969" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="16.5" x2="44" y1="52.2969" y2="52.2969"/><!--SRC=[SrJGrRLJS080]--></g></svg></div>'

## img-base64

Expand Down
Binary file modified test/snapshots/output.mjs.snap
Binary file not shown.

0 comments on commit 074f203

Please sign in to comment.