Skip to content

Commit

Permalink
Merge pull request #50 from rejectedsoftware/xml_singular_tags
Browse files Browse the repository at this point in the history
Output XML elements with no content as singular tags.
  • Loading branch information
s-ludwig authored Mar 12, 2018
2 parents 91f095c + bfc62fb commit a1aaafa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/diet/html.d
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ unittest {
}

test!"doctype html\nfoo(test=true)"("<!DOCTYPE html><foo test></foo>");
test!"doctype X\nfoo(test=true)"("<!DOCTYPE X><foo test=\"test\"></foo>");
test!"doctype html X\nfoo(test=true)"("<!DOCTYPE html X><foo test=\"test\"></foo>");
test!"doctype X\nfoo(test=true)"("<!DOCTYPE X><foo test=\"test\"/>");
test!"foo(test=2+3)"("<foo test=\"5\"></foo>");
test!"foo(test='#{2+3}')"("<foo test=\"5\"></foo>");
test!"foo #{2+3}"("<foo>5</foo>");
Expand Down Expand Up @@ -295,7 +296,7 @@ private string getElementMixin(ref CTX ctx, in Node node, bool in_pre)
need_newline = true;
break;
}
}
} else if (!node.hasNonWhitespaceContent) is_singular_tag = true;

// write tag name
string tagname = node.name.length ? node.name : "div";
Expand Down Expand Up @@ -804,3 +805,8 @@ unittest { // issue #45 - no singular tags for XML
assert(utCompile!("doctype xml\nlink foo") == `<?xml version="1.0" encoding="utf-8" ?><link>foo</link>`);
assert(utCompile!("doctype foo\nlink foo") == `<!DOCTYPE foo><link>foo</link>`);
}

unittest { // output empty tags as singular for XML output
assert(utCompile!("doctype html\nfoo") == `<!DOCTYPE html><foo></foo>`);
assert(utCompile!("doctype xml\nfoo") == `<?xml version="1.0" encoding="utf-8" ?><foo/>`);
}

0 comments on commit a1aaafa

Please sign in to comment.