Dave Jarvis' Repositories

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

Properly inserts document metadata and title

AuthorDaveJarvis <email>
Date2023-01-07 12:32:34 GMT-0800
Commit4292ecb6aba0f737cd06cbbb1e8afa6cec316111
Parent0b53ba7
src/main/java/com/keenwrite/dom/DocumentParser.java
}
+ public static Node createElement(
+ final Document doc, final String nodeName, final String nodeValue ) {
+ assert doc != null;
+ assert nodeName != null;
+ assert !nodeName.isBlank();
+
+ final var node = doc.createElement( nodeName );
+
+ if( nodeValue != null ) {
+ node.setTextContent( nodeValue );
+ }
+
+ return node;
+ }
+
public static String toString( final Document xhtml ) {
assert xhtml != null;
* until an iterable sub-interface is written.
*/
- private DocumentParser() {}
+ private DocumentParser() { }
}
src/main/java/com/keenwrite/processors/XhtmlProcessor.java
import static com.keenwrite.Bootstrap.APP_TITLE_ABBR;
-import static com.keenwrite.dom.DocumentParser.createMeta;
-import static com.keenwrite.dom.DocumentParser.visit;
+import static com.keenwrite.dom.DocumentParser.*;
import static com.keenwrite.events.StatusEvent.clue;
import static com.keenwrite.io.downloads.DownloadManager.open;
private final ProcessorContext mContext;
-
- /**
- * Adorns the given document with {@code html}, {@code head}, and
- * {@code body} elements.
- *
- * @param html The document to decorate.
- * @return A document with a typical HTML structure.
- */
- private static String decorate( final String html ) {
- return
- "<html><head><title> </title><meta charset='utf8'/></head><body>"
- + html
- + "</body></html>";
- }
public XhtmlProcessor(
try {
- final var doc = DocumentParser.parse( decorate( html ) );
+ final var doc = parse( html );
setMetaData( doc );
private void setMetaData( final Document doc ) {
final var metadata = createMetaDataMap( doc );
-
- visit( doc, "/html/head", node ->
- metadata.entrySet()
- .forEach( entry -> node.appendChild( createMeta( doc, entry ) ) )
- );
-
final var title = metadata.get( "title" );
- if( title != null ) {
- visit( doc, "/html/head/title", node -> node.setTextContent( title ) );
- }
+ visit( doc, "/html/head", node -> {
+ // Insert <title>text</title> inside <head>.
+ node.appendChild( createElement( doc, "title", title ) );
+
+ // Insert each <meta name=x content=y /> inside <head>.
+ metadata.entrySet().forEach(
+ entry -> node.appendChild( createMeta( doc, entry ) )
+ );
+ } );
}
if( mediaType.isSvg() ) {
- DocumentParser.sanitize( imageFile );
+ sanitize( imageFile );
}
}
src/main/resources/com/keenwrite/messages.properties
Wizard.typesetter.container.version=4.3.1
Wizard.typesetter.container.checksum=b741702663234ca36e1555149721580dc31ae76985d50c022a8641c6db2f5b93
-Wizard.typesetter.themes.version=1.8.0
-Wizard.typesetter.themes.checksum=2e6177d23210ea183f7759e5b6232f70bb1d4638a2f911beca129f877d25f92d
+Wizard.typesetter.themes.version=1.8.1
+Wizard.typesetter.themes.checksum=0cdb637cd77a1cd672aeedaba7ae364214aff7ffd28dd2812a8f360dfcea9d28
# STEP 1: Introduction panel (all)
Delta30 lines added, 30 lines removed