Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
M src/main/java/com/keenwrite/ExportFormat.java
22
package com.keenwrite;
33
4
import com.keenwrite.io.MediaType;
5
import com.keenwrite.io.MediaTypeExtension;
6
47
import java.io.File;
58
import java.nio.file.Path;
...
5356
5457
  /**
55
   * Looks up the {@link ExportFormat} based on the given format type and
56
   * subtype combination.
58
   * Looks up the {@link ExportFormat} based on the given path and subtype.
5759
   *
58
   * @param type    The type to find.
59
   * @param subtype The subtype to find (for HTML).
60
   * @return An object that defines the export format according to the given
61
   * parameters.
62
   * @throws IllegalArgumentException Could not determine the type and
63
   *                                  subtype combination.
60
   * @param path     The type to find.
61
   * @param modifier The subtype to find (for HTML).
62
   * @return An object to control the output file format.
63
   * @throws IllegalArgumentException The type/subtype could not be found.
64
   */
65
  public static ExportFormat valueFrom( final Path path, final String modifier )
66
    throws IllegalArgumentException {
67
    assert path != null;
68
69
    return valueFrom( MediaType.valueFrom( path ), modifier );
70
  }
71
72
  /**
73
   * Looks up the {@link ExportFormat} based on the given path and subtype.
74
   *
75
   * @param extension The type to find.
76
   * @param modifier  The subtype to find (for HTML).
77
   * @return An object to control the output file format.
78
   * @throws IllegalArgumentException The type/subtype could not be found.
6479
   */
6580
  public static ExportFormat valueFrom(
66
    final String type,
67
    final String subtype ) throws IllegalArgumentException {
68
    assert type != null;
69
    assert subtype != null;
81
    final String extension, final String modifier )
82
    throws IllegalArgumentException {
83
    assert extension != null;
7084
71
    return switch( type.trim().toLowerCase() ) {
72
      case "html" -> "svg".equalsIgnoreCase( subtype.trim() )
85
    return valueFrom( MediaTypeExtension.fromExtension( extension ), modifier );
86
  }
87
88
  /**
89
   * Looks up the {@link ExportFormat} based on the given path and subtype.
90
   *
91
   * @param type     The media type to find.
92
   * @param modifier The subtype to find (for HTML).
93
   * @return An object to control the output file format.
94
   * @throws IllegalArgumentException The type/subtype could not be found.
95
   */
96
  public static ExportFormat valueFrom(
97
    final MediaType type, final String modifier ) {
98
    return switch( type ) {
99
      case TEXT_HTML, TEXT_XHTML -> "svg".equalsIgnoreCase( modifier.trim() )
73100
        ? HTML_TEX_SVG
74101
        : HTML_TEX_DELIMITED;
75
      case "md" -> MARKDOWN_PLAIN;
76
      case "pdf" -> APPLICATION_PDF;
102
      case TEXT_MARKDOWN -> MARKDOWN_PLAIN;
103
      case APP_PDF -> APPLICATION_PDF;
77104
      default -> throw new IllegalArgumentException( format(
78
        "Unrecognized format type and subtype: '%s' and '%s'", type, subtype
105
        "Unrecognized format type and subtype: '%s' and '%s'", type, modifier
79106
      ) );
80107
    };
M src/main/java/com/keenwrite/MainPane.java
750750
      .collect(
751751
        groupingBy(
752
          path -> bin.apply( MediaType.fromFilename( path ) ),
752
          path -> bin.apply( MediaType.valueFrom( path ) ),
753753
          () -> new TreeMap<>( Enum::compareTo ),
754754
          Collectors.toList()
M src/main/java/com/keenwrite/cmdline/Arguments.java
7777
7878
  @CommandLine.Option(
79
    names = {"--format-type"},
80
    description =
81
      "Export type: html, md, pdf, xml (${DEFAULT-VALUE})",
82
    paramLabel = "String",
83
    defaultValue = "pdf",
84
    required = true
85
  )
86
  private String mFormatType;
87
88
  @CommandLine.Option(
89
    names = {"--format-subtype-tex"},
79
    names = {"--format-subtype"},
9080
    description =
91
      "Export subtype for HTML formats: svg, delimited",
92
    defaultValue = "",
81
      "Export TeX subtype for HTML formats: svg, delimited",
82
    defaultValue = "svg",
9383
    paramLabel = "String"
9484
  )
...
215205
    throws IOException {
216206
    final var definitions = parse( mPathVariables );
217
    final var format = ExportFormat.valueFrom( mFormatType, mFormatSubtype );
207
    final var format = ExportFormat.valueFrom( mPathOutput, mFormatSubtype );
218208
    final var locale = lookupLocale( mLocale );
219209
    final var rScript = read( mRScriptPath );
...
263253
264254
  private static String read( final Path path ) throws IOException {
265
    return Files.readString( path );
255
    return path == null ? "" : Files.readString( path );
266256
  }
267257
M src/main/java/com/keenwrite/io/MediaType.java
44
import java.io.File;
55
import java.io.IOException;
6
import java.net.URL;
67
import java.nio.file.Path;
78
89
import static com.keenwrite.io.MediaType.TypeName.*;
9
import static com.keenwrite.io.MediaTypeExtension.getMediaType;
10
import static com.keenwrite.io.MediaTypeExtension.fromExtension;
1011
import static java.io.File.createTempFile;
1112
import static org.apache.commons.io.FilenameUtils.getExtension;
...
184185
   * @return {@link MediaType#UNDEFINED} if the extension has not been
185186
   * assigned, otherwise the {@link MediaType} associated with this
186
   * URL's file name extension.
187
   * {@link URL}'s file name extension.
187188
   */
188189
  public static MediaType fromFilename( final String filename ) {
189190
    assert filename != null;
190
    return getMediaType( getExtension( filename ) );
191
    return fromExtension( getExtension( filename ) );
191192
  }
192193
M src/main/java/com/keenwrite/io/MediaTypeExtension.java
4747
  MEDIA_TEXT_R_MARKDOWN( TEXT_R_MARKDOWN, of( "Rmd" ) ),
4848
  MEDIA_TEXT_PROPERTIES( TEXT_PROPERTIES, of( "properties" ) ),
49
  MEDIA_TEXT_XHTML( TEXT_XHTML, of( "xhtml" ) ),
49
  MEDIA_TEXT_XHTML( TEXT_XHTML, of( "html", "xhtml" ) ),
5050
  MEDIA_TEXT_XML( TEXT_XML ),
5151
  MEDIA_TEXT_YAML( TEXT_YAML, of( "yaml", "yml" ) ),
...
7676
   * @return The associated {@link MediaType} as defined by IANA.
7777
   */
78
  static MediaType getMediaType( final String extension ) {
78
  public static MediaType fromExtension( final String extension ) {
7979
    final var sanitized = sanitize( extension );
8080
M src/main/java/com/keenwrite/preferences/SkinProperty.java
2525
    sSkins.add( "Haunted Grey" );
2626
    sSkins.add( "Modena Dark" );
27
    sSkins.add( "Monokai" );
2728
    sSkins.add( SKIN_DEFAULT );
2829
    sSkins.add( "Silver Cavern" );
M src/main/java/com/keenwrite/processors/ProcessorFactory.java
6868
    final Processor<String> processor;
6969
70
    if( preview == null && outputType == MARKDOWN_PLAIN ) {
71
      processor = inputType == RMARKDOWN
72
        ? createInlineRProcessor( successor, context )
73
        : createMarkdownProcessor( successor, context );
70
    // When there's no preview, determine processor by file name extension.
71
    if( preview == null ) {
72
      if( outputType == MARKDOWN_PLAIN ) {
73
        processor = inputType == RMARKDOWN
74
          ? createInlineRProcessor( successor, context )
75
          : createVariableProcessor( successor, context );
76
      }
77
      else {
78
        processor = createMarkdownProcessor( successor, context );
79
      }
7480
    }
7581
    else {
A src/main/resources/com/keenwrite/skins/monokai.css
1
/*
2
 * Theme contributed by mery6299
3
 *
4
 * https://github.com/mery6299
5
 */
6
.root { 
7
  -fx-accent: #75715E;
8
  -fx-focus-color: -fx-accent;
9
  -fx-base: #262626;
10
  -fx-control-inner-background: -fx-base;
11
  -fx-control-inner-background-alt: -fx-control-inner-background;
12
13
  -theme-text-selection: #78dce8;
14
  -theme-search-selection: #ffd866;
15
16
  -fx-light-text-color: derive( -fx-base, 150% );
17
  -fx-mid-text-color: derive( -fx-base, 100% );
18
  -fx-dark-text-color: derive( -fx-base, 25% );
19
  -fx-text-foreground: -fx-light-text-color;
20
  -fx-text-background: derive( -fx-control-inner-background, 25% );
21
  -fx-text-selection: derive( -theme-text-selection, -50% );
22
}
23
24
/* Caret colour */
25
.styled-text-area .caret {
26
  -fx-stroke: white;
27
}
28
29
/* Spelling errors */
30
.markdown .spelling {
31
  -rtfx-underline-color: #fc9867;
32
}
33
34
/* Search result */
35
.markdown .search {
36
  -rtfx-background-color: derive( -theme-search-selection, -25% );
37
}
38
39
.glyph-icon {
40
  -fx-text-fill: -fx-light-text-color;
41
  -fx-fill: -fx-light-text-color;
42
}
43
44
.glyph-icon:hover {
45
  -fx-effect: dropshadow( three-pass-box, rgba( 0, 0, 0, 0.2 ), 4, 0, 0, 0 );
46
}
47
48
.label {
49
  -fx-text-fill: -fx-light-text-color;
50
}
51
52
.text-field {
53
  -fx-prompt-text-fill: gray;
54
}
55
56
.button {
57
  -fx-focus-traversable: false;
58
}
59
60
.button:hover {
61
  -fx-text-fill: white;
62
}
63
64
.separator *.line { 
65
  -fx-background-color: #3C3C3C;
66
  -fx-border-style: solid;
67
  -fx-border-width: 1px;
68
}
69
70
.scroll-bar {
71
  -fx-background-color: derive( -fx-base, 15% );
72
}
73
74
.button:default {
75
  -fx-base: derive( -fx-accent, -25% );
76
} 
77
78
.table-view {
79
  -fx-selection-bar-non-focused: derive( -fx-base, 50% );
80
}
81
82
.table-view .column-header .label {
83
  -fx-alignment: CENTER_LEFT;
84
  -fx-font-weight: none;
85
}
86
87
.list-cell:even,
88
.list-cell:odd,
89
.table-row-cell:even,
90
.table-row-cell:odd {  
91
  -fx-control-inner-background: derive( -fx-base, 15% );
92
}
93
94
.list-cell:empty,
95
.table-row-cell:empty {
96
  -fx-background-color: transparent;
97
}
98
99
.list-cell,
100
.table-row-cell {
101
  -fx-border-color: transparent;
102
  -fx-table-cell-border-color: transparent;
103
}
104
105
/* Avoid clipping text descenders in statistics table row. */
106
.table-row-cell {
107
  -fx-cell-size: 30px;
108
}
109
110
/* Toolbar */
111
.tool-bar .button:hover {
112
  -fx-background-color: derive( -fx-accent, -25% );
113
  -fx-color: -fx-hover-base;
114
}
115
116
/* Tabs */
117
.tab-pane *.tab-header-background {
118
	-fx-background-color: -fx-base;
119
}
120
121
.tab:selected {
122
	-fx-background-color: derive( #A9DC76, -30% );
123
}
124
1125