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