Skip to content

Commit

Permalink
cleanup attributes in XML formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 29, 2024
1 parent 67cf602 commit 7e9f956
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/terminal.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ exports[`Terminal utils xml formatting should render colors 2`] = `"<div data-in
exports[`Terminal utils xml formatting should render links 1`] = `"<div data-index=\\"0\\"><div style=\\"width: 100%;\\"><a href=\\"https://example.com\\" target=\\"_blank\\" class=\\"link\\" data-text=\\"\\">example.com</a></div><div style=\\"width: 100%;\\"><a href=\\"example.com\\" data-text=\\"\\">example.com</a></div><div class=\\"cmd-end-line\\" style=\\"width: 100%;\\"><a href=\\"https://example.com\\" style=\\";background:red\\" data-text=\\"\\">Error:&nbsp;invalid&nbsp;message</a></div></div>"`;
exports[`Terminal utils xml formatting should render tags 1`] = `
"[[;;;foo;;{\\"class\\":\\"foo\\",\\"style\\":\\"color:red\\"}]text]
"[[;;;foo;;{\\"style\\":\\"color:red\\"}]text]
[[;;;;;{\\"style\\":\\"color:red\\"}]text]
[[i;;;;;{}]lorem]
[[g;;;;;{}]ipsum]
Expand Down
6 changes: 6 additions & 0 deletions js/xml_formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
var alt = attrs.alt || '';
var src = attrs.src || '';
delete attrs.alt;
delete attrs.class;
delete attrs.src;
var formatting = ['@', '', '', cls, src, JSON.stringify(attrs)];
return '[[' + formatting.join(';') + ']' + alt + ']';
},
Expand All @@ -98,19 +100,23 @@
italic: style('i'),
span: function(attrs) {
var cls = attrs.class || '';
delete attrs.class;
var formatting = ['', '', '', cls, '', JSON.stringify(attrs)];
return '[[' + formatting.join(';') + ']';
},
link: function(attrs) {
var cls = attrs.class || '';
var href = attrs.href || '';
delete attrs.class;
delete attrs.href;
var formatting = ['!', '', '', cls, href, JSON.stringify(attrs)];
return '[[' + formatting.join(';') + ']';
}
};
function style(value) {
return function(attrs) {
var cls = attrs.class || '';
delete attrs.class;
var formatting = [value, '', '', cls, '', JSON.stringify(attrs)];
return '[[' + formatting.join(';') + ']';
};
Expand Down

0 comments on commit 7e9f956

Please sign in to comment.