diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java
index 4dc2bf00d..d84755ed5 100644
--- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java
+++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java
@@ -39,6 +39,7 @@ import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
+import org.hl7.fhir.utilities.DebugUtilities;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.IXMLWriter;
import org.w3c.dom.Element;
@@ -236,15 +237,18 @@ public class XhtmlComposer {
if (!pretty || noPrettyOverride)
indent = "";
- // html self closing tags: http://xahlee.info/js/html5_non-closing_tag.html
- boolean concise = node.getChildNodes().size() == 0;
- if (node.hasEmptyExpanded() && node.getEmptyExpanded()) {
- concise = false;
+ boolean concise = false;
+ if (!node.hasChildren()) {
+ if (this.xml) {
+ concise = true;
+ } else if (!(node.hasEmptyExpanded() && node.getEmptyExpanded()) &&
+ Utilities.existsInList(node.getName(), "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr")) {
+ // In HTML5, only these elements can self-close
+ // https://developer.mozilla.org/en-US/docs/Glossary/Void_element
+ concise = true;
+ }
}
- if (!xml && Utilities.existsInList(node.getName(), "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr")) {
- concise = true;
- }
-
+
if (concise)
dst.append(indent + "<" + node.getName() + attributes(node) + "/>" + (pretty && !noPrettyOverride ? "\r\n" : ""));
else {
diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java
index daa53b551..95c855cb8 100644
--- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java
+++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java
@@ -1024,6 +1024,14 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
return addTag("link").attribute("rel", rel).attribute("href", href);
}
+ public XhtmlNode ahOrNot(String href) {
+ if (href == null) {
+ return this;
+ }
+ XhtmlNode x = addTag("a").attribute("href", href);
+ return x;
+ }
+
public void wbr() {
addTag("wbr");
diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java
index 06e0fec73..5dd09e3e2 100644
--- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java
+++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java
@@ -1,4 +1,4 @@
-package org.hl7.fhir.utilities.tests;
+package org.hl7.fhir.utilities.xhtml;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -6,6 +6,7 @@ import java.io.ObjectOutputStream;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
+import org.hl7.fhir.utilities.tests.BaseTestingUtilities;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@@ -145,9 +146,8 @@ public class XhtmlNodeTest {
String src = BaseTestingUtilities.loadTestResource("xhtml", "xhtml-empty-elements.xml");
XhtmlNode x = new XhtmlParser().parse(src, "xml");
-
- String xml = new XhtmlComposer(false, false).compose(x);
- Assertions.assertEquals(src.trim(), xml.trim());
+ String xml = new XhtmlComposer(true, false).compose(x);
+ Assertions.assertEquals("", xml.trim());
}
@Test
diff --git a/pom.xml b/pom.xml
index 8206048fe..6a7ac481a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
32.0.1-jre
6.4.1
- 1.5.0
+ 1.5.1-SNAPSHOT
2.16.0
5.9.2
1.8.2