Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
src/main/java/com/keenwrite/processors/html/XhtmlProcessor.java
package com.keenwrite.processors.html;
+import com.keenwrite.collections.InterpolatingMap;
import com.keenwrite.dom.DocumentParser;
+import com.keenwrite.events.StatusEvent;
import com.keenwrite.io.MediaTypeExtension;
import com.keenwrite.processors.ExecutorProcessor;
final var doc = parse( html );
- visit( doc, "//img", node -> {
- try {
- final var attrs = node.getAttributes();
- final var attr = attrs.getNamedItem( "src" );
+ visit(
+ doc, "//img", node -> {
+ try {
+ final var attrs = node.getAttributes();
+ final var attr = attrs.getNamedItem( "src" );
- if( attr != null ) {
- final var src = attr.getTextContent();
- final Path location;
- final Path imagesDir;
+ if( attr != null ) {
+ final var src = attr.getTextContent();
+ final Path location;
+ final Path imagesDir;
- // Download into a cache directory, which can be written to without
- // any possibility of overwriting local image files. Further, the
- // filenames are hashed as a second layer of protection.
- if( getProtocol( src ).isRemote() ) {
- location = downloadImage( src );
- imagesDir = getCachesPath();
- }
- else {
- location = resolveImage( src );
- imagesDir = getImagesPath();
- }
+ // Download into a cache directory, which can be written to
+ // without
+ // any possibility of overwriting local image files. Further, the
+ // filenames are hashed as a second layer of protection.
+ if( getProtocol( src ).isRemote() ) {
+ location = downloadImage( src );
+ imagesDir = getCachesPath();
+ }
+ else {
+ location = resolveImage( src );
+ imagesDir = getImagesPath();
+ }
- final var relative = imagesDir.relativize( location );
+ final var relative = imagesDir.relativize( location );
- attr.setTextContent( relative.toString() );
+ attr.setTextContent( relative.toString() );
+ }
+ } catch( final Exception ex ) {
+ clue( ex );
}
- } catch( final Exception ex ) {
- clue( ex );
}
- } );
+ );
- final var metadata = createMetaDataMap( doc );
- final var title = metadata.get( "document.title" );
+ final var map = mContext.getInterpolatedDefinitions();
+ final var metadata = createMetaDataMap( doc, map );
+ final var title = map.get( "document.title" );
final var locale = mContext.getLocale();
final var xhtml = DocumentParser.create( doc, metadata, locale, title );
final var document = DTD + DocumentParser.toString( xhtml );
final var curl = mContext.getCurlQuotes();
- final var curler = createCurler( FILTER_XML, Apostrophe.fromType( curl ) );
+ final var curler = createCurler( FILTER_XML,
+ Apostrophe.fromType( curl ) );
return curler.apply( document );
* @return A map of metadata key/value pairs.
*/
- private Map<String, String> createMetaDataMap( final Document doc ) {
+ private Map<String, String> createMetaDataMap(
+ final Document doc, final InterpolatingMap map
+ ) {
final var result = new LinkedHashMap<String, String>();
- final var map = mContext.getInterpolatedDefinitions();
final var metadata = getMetadata();

Acquires document title from variable definitions

Author DaveJarvis <email>
Date 2025-08-22 00:48:26 GMT-0700
Commit 1d5cb0b81ea54c28bba1ab4eee3d1f137bb447e9
Parent b333c06
Delta 37 lines added, 29 lines removed, 8-line increase