Skip to content

Commit e24a589

Browse files
committed
Fix xml formatter.
1 parent 03e62f4 commit e24a589

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Serilog.Ui.Web/wwwroot/js/main.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
let message = $(this).find("span").text();
4646

4747
if (dataType === "xml") {
48-
message = formatXml(message);
48+
message = formatXml(message, ' ');
4949
$(modalBody).removeClass('wrapped');
5050
} else if (dataType === "json") {
5151
const prop = JSON.parse(message);
@@ -58,4 +58,15 @@
5858
modalBody.find('pre').text(message);
5959
modal.modal("show");
6060
});
61-
})(jQuery);
61+
})(jQuery);
62+
63+
function formatXml(xml, tab) { // tab = optional indent value, default is tab (\t)
64+
var formatted = '', indent = '';
65+
tab = tab || '\t';
66+
xml.split(/>\s*</).forEach(function (node) {
67+
if (node.match(/^\/\w/)) indent = indent.substring(tab.length); // decrease indent by one 'tab'
68+
formatted += indent + '<' + node + '>\r\n';
69+
if (node.match(/^<?\w[^>]*[^\/]$/)) indent += tab; // increase indent
70+
});
71+
return formatted.substring(1, formatted.length - 3);
72+
}

src/Serilog.Ui.Web/wwwroot/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)