| Author | DaveJarvis <email> |
|---|---|
| Date | 2021-12-07 21:27:09 GMT-0800 |
| Commit | 78c140967959324a4bcaf495a82874b404174cee |
| Parent | e0f954c |
| // Pure JavaFX File Chooser | ||
| - implementation "com.io7m.jwheatsheaf:com.io7m.jwheatsheaf:${v_wheatsheaf}" | ||
| - implementation "com.io7m.jwheatsheaf:com.io7m.jwheatsheaf.api:${v_wheatsheaf}" | ||
| - implementation "com.io7m.jwheatsheaf:com.io7m.jwheatsheaf.ui:${v_wheatsheaf}" | ||
| +// implementation "com.io7m.jwheatsheaf:com.io7m.jwheatsheaf:${v_wheatsheaf}" | ||
| +// implementation "com.io7m.jwheatsheaf:com.io7m.jwheatsheaf.api:${v_wheatsheaf}" | ||
| +// implementation "com.io7m.jwheatsheaf:com.io7m.jwheatsheaf.ui:${v_wheatsheaf}" | ||
| // Markdown |
| /** | ||
| - * Returns the value for a key from the message bundle. | ||
| + * Returns the value for a key from the message bundle. If the value cannot | ||
| + * be found, this returns the key. | ||
| * | ||
| * @param key Retrieve the value for this key. | ||
| - * @return The value for the key. | ||
| + * @return The value for the key, or the key itself if not found. | ||
| */ | ||
| public static String get( final String key ) { | ||
| - return MAP.get( OPERATOR.entoken( key ) ); | ||
| + final var v = MAP.get( OPERATOR.entoken( key ) ); | ||
| + return v == null ? key : v; | ||
| } | ||
| import java.net.URI; | ||
| -import static com.keenwrite.events.HyperlinkOpenEvent.fire; | ||
| import static com.keenwrite.events.StatusEvent.clue; | ||
| import static com.keenwrite.util.ProtocolScheme.getProtocol; |
| import com.keenwrite.processors.markdown.extensions.HtmlRendererAdapter; | ||
| import com.vladsch.flexmark.ast.FencedCodeBlock; | ||
| +import com.vladsch.flexmark.html.HtmlWriter; | ||
| import com.vladsch.flexmark.html.renderer.DelegatingNodeRendererFactory; | ||
| import com.vladsch.flexmark.html.renderer.NodeRenderer; | ||
| +import com.vladsch.flexmark.html.renderer.NodeRendererContext; | ||
| import com.vladsch.flexmark.html.renderer.NodeRenderingHandler; | ||
| import com.vladsch.flexmark.util.data.DataHolder; | ||
| import static com.keenwrite.preferences.WorkspaceKeys.KEY_IMAGES_SERVER; | ||
| import static com.vladsch.flexmark.html.HtmlRenderer.Builder; | ||
| +import static com.vladsch.flexmark.html.renderer.CoreNodeRenderer.CODE_CONTENT; | ||
| import static com.vladsch.flexmark.html.renderer.LinkType.LINK; | ||
| } | ||
| else { | ||
| - context.delegateRender(); | ||
| + // TODO: Revert to using context.delegateRender() after flexmark | ||
| + // is updated to no longer trim blank lines up to the EOL. | ||
| + render( node, context, html ); | ||
| } | ||
| } ) ); | ||
| return set; | ||
| + } | ||
| + | ||
| + /** | ||
| + * This method is a stop-gap because blank lines that contain only | ||
| + * whitespace are collapsed into lines without any spaces. Consequently | ||
| + * the typesetting software does not honour the blank lines, which | ||
| + * then discards the blank lines entirely. | ||
| + * <p> | ||
| + * Given the following: | ||
| + * | ||
| + * <pre> | ||
| + * if( bool ) { | ||
| + * | ||
| + * | ||
| + * } | ||
| + * </pre> | ||
| + * <p> | ||
| + * The typesetter would otherwise render this incorrectly as: | ||
| + * | ||
| + * <pre> | ||
| + * if( bool ) { | ||
| + * } | ||
| + * </pre> | ||
| + * <p> | ||
| + */ | ||
| + private void render( | ||
| + final FencedCodeBlock node, | ||
| + final NodeRendererContext context, | ||
| + final HtmlWriter html ) { | ||
| + html.line(); | ||
| + html.srcPosWithTrailingEOL( node.getChars() ) | ||
| + .withAttr() | ||
| + .tag( "pre" ) | ||
| + .openPre(); | ||
| + | ||
| + final var info = node.getInfo(); | ||
| + final var htmlOptions = context.getHtmlOptions(); | ||
| + | ||
| + if( info.isNotNull() && !info.isBlank() ) { | ||
| + final var language = node | ||
| + .getInfoDelimitedByAny( htmlOptions.languageDelimiterSet ) | ||
| + .unescape(); | ||
| + final var languageClass = htmlOptions.languageClassMap | ||
| + .getOrDefault( language, htmlOptions.languageClassPrefix + language ); | ||
| + html.attr( "class", languageClass ); | ||
| + } | ||
| + else { | ||
| + final var noLanguageClass = htmlOptions.noLanguageClass.trim(); | ||
| + | ||
| + if( !noLanguageClass.isEmpty() ) { | ||
| + html.attr( "class", noLanguageClass ); | ||
| + } | ||
| + } | ||
| + | ||
| + html.srcPosWithEOL( node.getContentChars() ) | ||
| + .withAttr( CODE_CONTENT ) | ||
| + .tag( "code" ); | ||
| + | ||
| + final var lines = node.getContentLines(); | ||
| + for( final var line : lines ) { | ||
| + if( line.isBlank() ) { | ||
| + html.text( " " ); | ||
| + } | ||
| + | ||
| + html.text( line ); | ||
| + } | ||
| + | ||
| + html.tag( "/code" ); | ||
| + html.tag( "/pre" ) | ||
| + .closePre(); | ||
| + html.lineIf( htmlOptions.htmlBlockCloseTagEol ); | ||
| } | ||
| } | ||
| import com.vladsch.flexmark.html.HtmlRenderer; | ||
| import com.vladsch.flexmark.parser.Parser; | ||
| +import javafx.beans.property.SimpleObjectProperty; | ||
| import javafx.stage.Stage; | ||
| import org.junit.jupiter.api.Test; | ||
| import java.util.Map; | ||
| -import static com.keenwrite.constants.Constants.DOCUMENT_DEFAULT; | ||
| import static com.keenwrite.ExportFormat.NONE; | ||
| +import static com.keenwrite.constants.Constants.DOCUMENT_DEFAULT; | ||
| import static java.lang.String.format; | ||
| import static javafx.application.Platform.runLater; | ||
| return new ProcessorContext( | ||
| mPreview, | ||
| - new HashMap<>(), | ||
| + new SimpleObjectProperty<>(), | ||
| documentPath, | ||
| null, | ||
| } | ||
| - private StringProperty createToken( final String token ) { | ||
| + private StringProperty createSigil( final String token ) { | ||
| return new SimpleStringProperty( token ); | ||
| } | ||
| - private Sigils createRTokens() { | ||
| - return createTokens( "x(", ")" ); | ||
| + private Sigils createRSigils() { | ||
| + return createSigils( "x(", ")" ); | ||
| } | ||
| - private Sigils createYamlTokens() { | ||
| - return createTokens( "{{", "}}" ); | ||
| + private Sigils createYamlSigils() { | ||
| + return createSigils( "{{", "}}" ); | ||
| } | ||
| - private Sigils createTokens( final String began, final String ended ) { | ||
| - return new Sigils( createToken( began ), createToken( ended ) ); | ||
| + private Sigils createSigils( final String began, final String ended ) { | ||
| + return new Sigils( createSigil( began ), createSigil( ended ) ); | ||
| } | ||
| private YamlSigilOperator createYamlSigilOperator() { | ||
| - return new YamlSigilOperator( createYamlTokens() ); | ||
| + return new YamlSigilOperator( createYamlSigils() ); | ||
| } | ||
| private RSigilOperator createRSigilOperator() { | ||
| - return new RSigilOperator( createRTokens(), createYamlSigilOperator() ); | ||
| + return new RSigilOperator( createRSigils(), createYamlSigilOperator() ); | ||
| } | ||
| } |
| Delta | 97 lines added, 19 lines removed, 78-line increase |
|---|