Skip to content

Commit

Permalink
Fix xml formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-esmp committed Oct 25, 2020
1 parent 03e62f4 commit e24a589
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Serilog.Ui.Web/wwwroot/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
let message = $(this).find("span").text();

if (dataType === "xml") {
message = formatXml(message);
message = formatXml(message, ' ');
$(modalBody).removeClass('wrapped');
} else if (dataType === "json") {
const prop = JSON.parse(message);
Expand All @@ -58,4 +58,15 @@
modalBody.find('pre').text(message);
modal.modal("show");
});
})(jQuery);
})(jQuery);

function formatXml(xml, tab) { // tab = optional indent value, default is tab (\t)
var formatted = '', indent = '';
tab = tab || '\t';
xml.split(/>\s*</).forEach(function (node) {
if (node.match(/^\/\w/)) indent = indent.substring(tab.length); // decrease indent by one 'tab'
formatted += indent + '<' + node + '>\r\n';
if (node.match(/^<?\w[^>]*[^\/]$/)) indent += tab; // increase indent
});
return formatted.substring(1, formatted.length - 3);
}
2 changes: 1 addition & 1 deletion src/Serilog.Ui.Web/wwwroot/js/main.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e24a589

Please sign in to comment.