| | |
| | 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 ); |
| | } |
| | } |