From 93a5dd7254ae8f350604201fd09e995da331fc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 8 Jul 2020 01:13:35 +0200 Subject: Javascript self closing XML tags. --- static/script.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'static/script.js') diff --git a/static/script.js b/static/script.js index bdeca8f5..27a46ae0 100644 --- a/static/script.js +++ b/static/script.js @@ -5,6 +5,10 @@ function start_tag(str) { } function end_tag(str) { + return "</" + str + ">"; +} + +function self_tag(str) { return "<" + str + "/>"; } @@ -19,10 +23,14 @@ function pretty_print_xml(xml, indent=0) { if (xml.childElementCount == 0) { - return istring(indent) - + start_tag(tag) - + "" + xml.textContent + "" - + end_tag(tag); + if (xml.textContent) { + return istring(indent) + + start_tag(tag) + + "" + xml.textContent + "" + + end_tag(tag); + } else { + return istring(indent) + self_tag(tag); + } } else { let str = istring(indent) + start_tag(tag) + "
"; for (let child of xml.children) { -- cgit v1.2.3