Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
M publish.sh
7171
  cat "${PATH_TOKEN}" | glab auth login --hostname gitlab.com --stdin
7272
73
  glab release create ${RELEASE}
74
7375
  release "Windows"
7476
  release "MacOS"
M src/main/java/com/keenwrite/MainPane.java
446446
    if( inputFile.isFile() ) {
447447
      getRecentFiles().add( inputFile.getAbsolutePath() );
448
449
      final var dir = inputFile.getParentFile();
450
      mWorkspace.fileProperty( KEY_UI_RECENT_DIR ).setValue( dir );
448451
    }
449452
  }
M src/main/java/com/keenwrite/constants/Constants.java
1717
import static com.keenwrite.Bootstrap.USER_DATA_DIR;
1818
import static com.keenwrite.io.SysFile.toFile;
19
import static com.keenwrite.io.UserDataDir.getUserHome;
1920
import static com.keenwrite.preferences.LocaleScripts.withScript;
2021
import static com.keenwrite.util.SystemUtils.*;
...
290291
  public static File getFontDirectory() {
291292
    final var FONT_PATH = Path.of( "fonts" );
292
    final var USER_HOME = System.getProperty( "user.home" );
293
    final var USER_HOME = getUserHome();
293294
294295
    final String fontBase;
M src/main/java/com/keenwrite/dom/DocumentParser.java
194194
  }
195195
196
  public static Node createEncoding(
197
    final Document document, final String encoding
198
  ) {
199
    assert document != null;
200
    assert encoding != null;
201
202
    final var node = document.createElement( "meta" );
203
204
    node.setAttribute( "charset", encoding );
205
206
    return node;
207
  }
208
196209
  public static Node createElement(
197210
    final Document doc, final String nodeName, final String nodeValue ) {
...
294307
   * until an iterable sub-interface is written.
295308
   */
296
  private DocumentParser() { }
309
  private DocumentParser() {}
297310
}
298311
M src/main/java/com/keenwrite/editors/TextResource.java
206206
  void clearModifiedProperty();
207207
208
  private String asString( final byte[] text, final Charset encoding ) {
209
    return new String( text, encoding );
210
  }
211208
212209
  /**
...
226223
    detector.dataEnd();
227224
228
    final var charset = detector.getDetectedCharset();
225
    final var detectedCharset = detector.getDetectedCharset();
229226
230
    return charset == null
231
      ? DEFAULT_CHARSET
232
      : forName( charset.toUpperCase( ENGLISH ) );
227
    // TODO: Revert when the issue has been fixed.
228
    // https://github.com/albfernandez/juniversalchardet/issues/35
229
    return switch( detectedCharset ) {
230
      case null -> DEFAULT_CHARSET;
231
      case "US-ASCII", "TIS620" -> DEFAULT_CHARSET;
232
      default -> forName( detectedCharset.toUpperCase( ENGLISH ) );
233
    };
233234
  }
234235
...
243244
  default boolean supports( final MediaType mediaType ) {
244245
    return isMediaType( mediaType );
246
  }
247
248
  private static String asString( final byte[] text, final Charset encoding ) {
249
    return new String( text, encoding );
245250
  }
246251
}
M src/main/java/com/keenwrite/editors/markdown/MarkdownEditor.java
6363
public final class MarkdownEditor extends BorderPane implements TextEditor {
6464
  /**
65
   * Represents a failed index search.
66
   */
67
  private static final int INDEX_NOT_FOUND = -1;
68
69
  /**
7065
   * Regular expression that matches the type of markup block. This is used
7166
   * when Enter is pressed to continue the block environment.
M src/main/java/com/keenwrite/io/UserDataDir.java
4747
  private UserDataDir() { }
4848
49
  public static String getUserHome() {
50
    return PROP_USER_HOME;
51
  }
52
4953
  /**
5054
   * Makes a valiant attempt at determining where to create application-specific
M src/main/java/com/keenwrite/processors/XhtmlProcessor.java
2727
import static java.lang.String.format;
2828
import static java.lang.String.valueOf;
29
import static java.nio.charset.StandardCharsets.UTF_8;
2930
import static java.nio.file.Files.copy;
3031
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
...
118119
      // Insert <title>text</title> inside <head>.
119120
      node.appendChild( createElement( doc, "title", title ) );
121
      // Insert <meta charset="utf-8"> inside <head>.
122
      node.appendChild( createEncoding( doc, UTF_8.toString() ) );
120123
121124
      // Insert each <meta name=x content=y /> inside <head>.
M src/main/java/com/keenwrite/ui/explorer/FilePickerFactory.java
1616
1717
import static com.keenwrite.io.SysFile.toFile;
18
import static com.keenwrite.io.UserDataDir.getUserHome;
1819
import static com.keenwrite.preferences.AppKeys.KEY_UI_RECENT_DIR;
1920
import static com.keenwrite.ui.explorer.FilePickerFactory.SelectionType.*;
...
9697
9798
      mChooser.setInitialDirectory(
98
        file.exists() ? file : new File( System.getProperty( "user.home" ) )
99
        file.exists() ? file : new File( getUserHome() )
99100
      );
100101
    }
A src/test/java/com/keenwrite/encoding/EncodingTest.java
1
package com.keenwrite.encoding;
2
3
import org.junit.jupiter.api.Test;
4
import org.mozilla.universalchardet.UniversalDetector;
5
6
import java.nio.charset.Charset;
7
import java.nio.charset.StandardCharsets;
8
9
import static org.junit.jupiter.api.Assertions.assertEquals;
10
import static org.junit.jupiter.api.Assertions.assertNotNull;
11
12
public class EncodingTest {
13
  @Test
14
  public void test_Encoding_UTF8_UTF8() {
15
    final var bytes = testBytes();
16
17
    final var detector = new UniversalDetector( null );
18
    detector.handleData( bytes, 0, bytes.length );
19
    detector.dataEnd();
20
21
    final var expectedCharset = StandardCharsets.UTF_8;
22
    final var detectedCharset = detector.getDetectedCharset();
23
24
    assertNotNull( detectedCharset );
25
26
    final var actualCharset = Charset.forName( detectedCharset );
27
28
    assertEquals( expectedCharset, actualCharset );
29
  }
30
31
  private static byte[] testBytes() {
32
    return
33
      """
34
        One humid afternoon during the harrowing heatwave of 2060, Renato
35
        Salvatierra, a man with blood sausage fingers and a footfall that
36
        silenced rooms, received a box at his police station. Taped to the
37
        box was a ransom note; within were his wife's eyes. By year's end,
38
        a supermax prison overflowed with felons, owing to Salvatierra's
39
        efforts to find his beloved. Soon after, he flipped profession into
40
        an entry-level land management position that, his wife insisted,
41
        would be, in her words, *infinitamente más relajante*---infinitely
42
        more relaxing.
43
        """
44
        .getBytes();
45
  }
46
}
147