| 18 | 18 | |
| 19 | 19 | import static com.keenwrite.Bootstrap.APP_TITLE_ABBR; |
| 20 | | import static com.keenwrite.dom.DocumentParser.createMeta; |
| 21 | | import static com.keenwrite.dom.DocumentParser.visit; |
| 20 | import static com.keenwrite.dom.DocumentParser.*; |
| 22 | 21 | import static com.keenwrite.events.StatusEvent.clue; |
| 23 | 22 | import static com.keenwrite.io.downloads.DownloadManager.open; |
| ... |
| 39 | 38 | |
| 40 | 39 | private final ProcessorContext mContext; |
| 41 | | |
| 42 | | /** |
| 43 | | * Adorns the given document with {@code html}, {@code head}, and |
| 44 | | * {@code body} elements. |
| 45 | | * |
| 46 | | * @param html The document to decorate. |
| 47 | | * @return A document with a typical HTML structure. |
| 48 | | */ |
| 49 | | private static String decorate( final String html ) { |
| 50 | | return |
| 51 | | "<html><head><title> </title><meta charset='utf8'/></head><body>" |
| 52 | | + html |
| 53 | | + "</body></html>"; |
| 54 | | } |
| 55 | 40 | |
| 56 | 41 | public XhtmlProcessor( |
| ... |
| 74 | 59 | |
| 75 | 60 | try { |
| 76 | | final var doc = DocumentParser.parse( decorate( html ) ); |
| 61 | final var doc = parse( html ); |
| 77 | 62 | setMetaData( doc ); |
| 78 | 63 | |
| ... |
| 126 | 111 | private void setMetaData( final Document doc ) { |
| 127 | 112 | final var metadata = createMetaDataMap( doc ); |
| 128 | | |
| 129 | | visit( doc, "/html/head", node -> |
| 130 | | metadata.entrySet() |
| 131 | | .forEach( entry -> node.appendChild( createMeta( doc, entry ) ) ) |
| 132 | | ); |
| 133 | | |
| 134 | 113 | final var title = metadata.get( "title" ); |
| 135 | 114 | |
| 136 | | if( title != null ) { |
| 137 | | visit( doc, "/html/head/title", node -> node.setTextContent( title ) ); |
| 138 | | } |
| 115 | visit( doc, "/html/head", node -> { |
| 116 | // Insert <title>text</title> inside <head>. |
| 117 | node.appendChild( createElement( doc, "title", title ) ); |
| 118 | |
| 119 | // Insert each <meta name=x content=y /> inside <head>. |
| 120 | metadata.entrySet().forEach( |
| 121 | entry -> node.appendChild( createMeta( doc, entry ) ) |
| 122 | ); |
| 123 | } ); |
| 139 | 124 | } |
| 140 | 125 | |
| ... |
| 209 | 194 | |
| 210 | 195 | if( mediaType.isSvg() ) { |
| 211 | | DocumentParser.sanitize( imageFile ); |
| 196 | sanitize( imageFile ); |
| 212 | 197 | } |
| 213 | 198 | } |