Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Fixes SVG issue, fixes nbsp entity issue

AuthorDaveJarvis <email>
Date2025-10-08 14:26:02 GMT-0700
Commitbf40fd9da1d7ccbc89e1b876fcb462365584fd9f
Parentc2857f6
Delta19 lines added, 2 lines removed, 17-line increase
src/main/java/com/keenwrite/dom/DocumentParser.java
if( !xml.isBlank() ) {
- try( final var reader = new StringReader( xml ) ) {
+ try( final var reader = new StringReader( declareEntities( xml ) ) ) {
final var input = new InputSource();
return sDocumentBuilder.newDocument();
+ }
+
+ /**
+ * Fixes issue where entity "nbsp" was referenced, but not declared.
+ *
+ * @param xml The document text to convert to a DOM.
+ * @return The DOM with the "nbsp" entity declared.
+ */
+ private static String declareEntities( final String xml ) {
+ return xml.startsWith( "<!DOCTYPE" )
+ ? xml
+ : """
+ <!DOCTYPE html [
+ <!ENTITY nbsp "&#160;">
+ ]>
+ """ + xml;
}
}
- public static Node evaluate( final String xpath, final Document doc ) throws XPathExpressionException {
+ public static Node evaluate( final String xpath, final Document doc )
+ throws XPathExpressionException {
return (Node) XPATH.evaluate( xpath, doc, NODE );
}