Skip to content

Commit

Permalink
fix: SVG did not include source in <desc>
Browse files Browse the repository at this point in the history
  • Loading branch information
skanaar committed Apr 12, 2022
1 parent 900bcbd commit 40294d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/nomnoml.js
Original file line number Diff line number Diff line change
Expand Up @@ -1927,8 +1927,8 @@
const data = (_a = getDefined(this.group(), (e) => e.data)) !== null && _a !== void 0 ? _a : {};
const attrs = toAttrString(Object.assign(Object.assign({}, this.attr), data));
const content = this.children.map((o) => o.serialize()).join('\n');
if (this.name === 'text')
return `<text ${attrs}>${xmlEncode(this.text)}</text>`;
if (this.text && this.children.length === 0)
return `<${this.name} ${attrs}>${xmlEncode(this.text)}</${this.name}>`;
else if (this.children.length === 0)
return this.elideEmpty ? '' : `<${this.name} ${attrs}></${this.name}>`;
else
Expand Down
3 changes: 2 additions & 1 deletion src/GraphicsSvg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export function GraphicsSvg(document?: HTMLDocument): ISvgGraphics {
const data = getDefined(this.group(), (e) => e.data) ?? {}
const attrs = toAttrString({ ...this.attr, ...data })
const content = this.children.map((o) => o.serialize()).join('\n')
if (this.name === 'text') return `<text ${attrs}>${xmlEncode(this.text)}</text>`
if (this.text && this.children.length === 0)
return `<${this.name} ${attrs}>${xmlEncode(this.text)}</${this.name}>`
else if (this.children.length === 0)
return this.elideEmpty ? '' : `<${this.name} ${attrs}></${this.name}>`
else
Expand Down
6 changes: 6 additions & 0 deletions test/test.misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ suite.test('escape [data-name] attribute value in SVG', function () {
assert(output, 'includes', 'data-name="&amp;"')
})

suite.test('SVG export includes nomnoml source in <desc>', function () {
var output = renderSvg('[a]->[b]')
var desc = output.match('<desc ?>(.*)</desc>')[1]
assert(desc.trim(), '=', '[a]-&gt;[b]')
})

suite.report()

0 comments on commit 40294d3

Please sign in to comment.