diff --git a/editions/test/tiddlers/tests/data/serialize/VoidElements.tid b/editions/test/tiddlers/tests/data/serialize/VoidElements.tid new file mode 100644 index 0000000000..22bd47f4ff --- /dev/null +++ b/editions/test/tiddlers/tests/data/serialize/VoidElements.tid @@ -0,0 +1,12 @@ +tags: $:/tags/wikitext-serialize-test-spec +title: Serialize/VoidElements +type: text/vnd.tiddlywiki + +This tests void elements like
and
(without `/`). + +Line one
Line two +Line three
Line four + +
+ +Images are also void: diff --git a/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8258.tid b/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8258.tid index e6f118ee20..b6de1a50dd 100644 --- a/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8258.tid +++ b/editions/tw5.com/tiddlers/releasenotes/5.4.0/#8258.tid @@ -23,6 +23,7 @@ There is also a utility `serializeAttribute` for a single attribute node, like a * Separate serialize handlers for each WikiText rule as `module-type: wikiruleserializer` * Test suite with tag `$:/tags/wikitext-serialize-test-spec` * It uses each parser's name as rule (`nextMatch.rule.name`), each AST node that needs serialization has a `type` property matching the rule name +** HTML tags and widgets are handled by the `html` serializer !! Example Usage diff --git a/plugins/tiddlywiki/wikitext-serialize/rules/html.js b/plugins/tiddlywiki/wikitext-serialize/rules/html.js index ff9b7be67e..6de28bbd96 100644 --- a/plugins/tiddlywiki/wikitext-serialize/rules/html.js +++ b/plugins/tiddlywiki/wikitext-serialize/rules/html.js @@ -16,9 +16,13 @@ exports.serialize = function(tree,serialize) { // Children var children = tree.children ? serialize(tree.children) : ""; var result = ""; + var isVoidElement = $tw.config.htmlVoidElements.indexOf(tag) !== -1; // Self-closing tag if(tree.isSelfClosing) { - result += "<" + tag + (attributes ? " " + attributes : "") + "/>"; + result += "<" + tag + (attributes ? " " + attributes : "") + "/>"; + } else if(isVoidElement) { + // Void element without self-closing slash (e.g.,
instead of
) + result += "<" + tag + (attributes ? " " + attributes : "") + ">"; } else { // Opening and closing tags result += "<" + tag + (attributes ? " " + attributes : "") + ">" + children + "";