Dave Jarvis' Repositories

M build.gradle
1818
  id 'org.openjfx.javafxplugin' version '0.1.0'
1919
  id 'com.palantir.git-version' version '3.0.0'
20
  id "com.github.spotbugs" version "5.2.4"
20
  id 'com.github.spotbugs' version '5.2.4'
2121
}
2222
...
3636
3737
  maven {
38
    url "https://css4j.github.io/maven"
38
    url 'https://css4j.github.io/maven'
3939
    mavenContent {
4040
      releasesOnly()
...
5353
if (project.hasProperty( 'targetOs' )) {
5454
  if ('windows' == targetOs) {
55
    os = ["win"]
55
    os = ['win']
5656
  } else if ('macos' == targetOs) {
57
    os = ["mac"]
57
    os = ['mac']
5858
  } else {
5959
    os = [targetOs]
...
165165
  }
166166
167
  testImplementation 'org.testfx:testfx-junit5:4.0.17'
168167
  testImplementation "org.junit.jupiter:junit-jupiter-api:${v_junit}"
169168
  testImplementation "org.junit.jupiter:junit-jupiter-params:${v_junit}"
169
  testImplementation 'org.testfx:testfx-junit5:4.0.17'
170170
  testImplementation 'org.assertj:assertj-core:3.24.2'
171171
  testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
...
209209
compileJava {
210210
  options.compilerArgs += [
211
    "-Xlint:unchecked",
212
    "-Xlint:deprecation",
211
    '-Xlint:unchecked',
212
    '-Xlint:deprecation',
213213
    "-Aproject=${applicationPackage}/${applicationName}"
214214
  ]
...
235235
236236
  from {
237
    (configurations.runtimeClasspath.findAll { !it.path.endsWith( ".pom" ) })
237
    (configurations.runtimeClasspath.findAll { !it.path.endsWith( '.pom' ) })
238238
      .collect { it.isDirectory() ? it : zipTree( it ) }
239239
  }
...
265265
266266
tasks.withType( JavaCompile ).configureEach {
267
  options.compilerArgs += "--enable-preview"
267
  options.encoding = 'UTF-8'
268
  options.compilerArgs += '--enable-preview'
268269
}
269270
270271
tasks.withType( JavaExec ).configureEach {
271
  jvmArgs += "--enable-preview"
272
  jvmArgs += '--enable-preview'
272273
}
273274
274275
tasks.withType( Test ).configureEach {
275
  jvmArgs += "--enable-preview"
276
  jvmArgs += '--enable-preview'
276277
}
277278
M src/main/java/com/keenwrite/preview/ImageReplacedElementFactory.java
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
24
import java.nio.file.Paths;
2425
import java.text.ParseException;
2526
...
6364
      return createElement( raster );
6465
    } catch( final Exception ex ) {
65
      clue( "Main.status.image.request.error.rasterize", ex );
66
      clue( "Main.status.image.request.error.create", ex );
6667
    }
6768
...
108109
    if( raster == null && mediaType.isImage() ) {
109110
      uri = resolve( source, uac, e );
110
      final var path = Path.of( uri.getPath() );
111
112
      final var path = Paths.get( uri );
111113
112114
      try( final var stream = Files.newInputStream( path ) ) {
113115
        raster = ImageIO.read( stream );
114116
      }
115117
    }
118
119
    // Image path resolved; image rendered successfully.
120
    clue();
116121
117122
    return raster;
118123
  }
119124
125
  /**
126
   * Attempt to rasterize based on file name.
127
   *
128
   * @param source The source URI from the document.
129
   * @param uac    A callback for retrieving the image resource.
130
   * @param e      The HTML element containing a reference to a file.
131
   * @return The resolved URI to the file.
132
   * @throws URISyntaxException Could not resolve URI.
133
   */
120134
  private static URI resolve(
121135
    final String source,
122136
    final UserAgentCallback uac,
123137
    final Element e )
124138
    throws URISyntaxException {
125
    // Attempt to rasterize based on file name.
126
    final var baseUri = new URI( uac.getBaseURL() );
127
    final var path = baseUri.resolve( source ).normalize();
139
    final var nSource = source.replaceAll( "\\\\", "/" );
128140
129
    if( path.isAbsolute() ) {
130
      return path;
131
    }
132
    else {
133
      final var base = new URI( e.getBaseURI() ).getPath();
134
      return Path.of( base, source ).toUri();
141
    try {
142
      final var baseUri = new URI( uac.getBaseURL() );
143
      final var resolved = baseUri.resolve( nSource );
144
      final var path = resolved.normalize();
145
      clue( "Main.status.image.request.resolve", path );
146
147
      return path.isAbsolute() ? path : resolve( nSource, e );
148
    } catch( final Exception ex ) {
149
      clue( "Main.status.image.request.error.resolve", nSource );
150
      throw new URISyntaxException( nSource, ex.getMessage() );
135151
    }
152
  }
153
154
  private static URI resolve( final String source, final Element e )
155
    throws URISyntaxException {
156
    final var base = new URI( e.getBaseURI() ).getPath();
157
    return Path.of( base, source ).toUri();
136158
  }
137159
M src/main/resources/com/keenwrite/messages.properties
179179
Main.status.image.request.fetch=Downloaded image ''{0}''
180180
Main.status.image.request.success=Determined content type ''{0}''
181
Main.status.image.request.resolve=Resolved image path: ''{0}''
181182
Main.status.image.request.error.media=No media type for ''{0}''
182183
Main.status.image.request.error.cert=Could not accept certificate for ''{0}''
183
Main.status.image.request.error.rasterize=Rasterizer could not parse SVG image
184
Main.status.image.request.error.create=Could not create image for preview document
185
Main.status.image.request.error.resolve=Could not resolve image path: ''{0}''
184186
185187
Main.status.image.xhtml.image.download=Downloading ''{0}''
M src/test/java/com/keenwrite/processors/markdown/extensions/images/ImageLinkExtensionTest.java
1010
1111
import java.io.File;
12
import java.io.IOException;
1213
import java.net.URI;
1314
import java.nio.file.Path;
...
2021
import static com.keenwrite.constants.Constants.DOCUMENT_DEFAULT;
2122
import static java.lang.String.format;
22
import static org.junit.jupiter.api.Assertions.assertEquals;
23
import static org.junit.jupiter.api.Assertions.assertNotNull;
23
import static org.junit.jupiter.api.Assertions.*;
2424
2525
/**
...
3232
  private static final String URI_FILE = "kitten";
3333
  private static final String URI_PATH = UIR_DIR + '/' + URI_FILE;
34
  private static final String PATH_KITTEN_JPG = URI_PATH + ".jpg";
35
  private static final String PATH_KITTEN_PNG = URI_PATH + ".png";
34
  private static final String PATH_KITTEN_PNG = STR."\{URI_PATH}.png";
35
  private static final String PATH_KITTEN_JPG = STR."\{URI_PATH}.jpg";
3636
3737
  private static final Map<String, String> IMAGES = new LinkedHashMap<>();
3838
3939
  static {
40
    add( PATH_KITTEN_PNG, URI_FILE );
4140
    add( PATH_KITTEN_PNG, URI_PATH );
41
    add( PATH_KITTEN_PNG, URI_FILE );
4242
    add( PATH_KITTEN_PNG, PATH_KITTEN_PNG );
4343
    add( PATH_KITTEN_JPG, PATH_KITTEN_JPG );
...
6666
   */
6767
  @Test
68
  void test_ImageLookup_RelativePathWithExtension_ResolvedSuccessfully() {
68
  void test_ImageLookup_RelativePathWithExtension_ResolvedSuccessfully()
69
    throws IOException {
6970
    final var resource = getResourcePath( PATH_KITTEN_PNG );
7071
    final var imagePath = new File( PATH_KITTEN_PNG ).toPath();
...
8889
    final var parser = pBuilder.extensions( extensions ).build();
8990
    final var renderer = hBuilder.extensions( extensions ).build();
91
    final var imageFile = resolved.resolve( imagePath ).toFile();
92
    imageFile.deleteOnExit();
9093
94
    assertTrue( imageFile.createNewFile() );
9195
    assertNotNull( parser );
9296
    assertNotNull( renderer );
...
100104
      assertEquals( expectedHtml, actualHtml );
101105
    }
106
107
    assertTrue( imageFile.delete() );
102108
  }
103109