Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output XML elements with no content as singular tags. #50

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/>`);
}