| Author | DaveJarvis <email> |
|---|---|
| Date | 2021-07-02 23:45:22 GMT-0700 |
| Commit | 63350d047aaa6f033fb817aefcba96ab8239f896 |
| Parent | 78550aa |
| import com.keenwrite.preferences.Key; | ||
| import com.keenwrite.preferences.Workspace; | ||
| -import com.keenwrite.quotes.Typographer; | ||
| import com.keenwrite.ui.heuristics.WordCounter; | ||
| +import com.whitemagicsoftware.keenquotes.Converter; | ||
| import javafx.beans.property.StringProperty; | ||
| import org.w3c.dom.Document; | ||
| import static com.keenwrite.processors.text.TextReplacementFactory.replace; | ||
| import static com.keenwrite.util.ProtocolScheme.getProtocol; | ||
| +import static com.whitemagicsoftware.keenquotes.Converter.CHARS; | ||
| +import static com.whitemagicsoftware.keenquotes.ParserFactory.ParserType.PARSER_XML; | ||
| import static java.lang.String.format; | ||
| import static java.lang.String.valueOf; | ||
| private final static Pattern BLANK = | ||
| compile( "\\p{Blank}", UNICODE_CHARACTER_CLASS ); | ||
| + | ||
| + private final static Converter sTypographer = | ||
| + new Converter( lex -> clue( lex.toString() ), CHARS, PARSER_XML ); | ||
| private final ProcessorContext mContext; | ||
| final var document = DocumentParser.toString( doc ); | ||
| - return curl() ? Typographer.curl( document ) : document; | ||
| + return curl() ? sTypographer.apply( document ) : document; | ||
| } catch( final Exception ex ) { | ||
| clue( ex ); | ||
| -/* Copyright 2021 White Magic Software, Ltd. -- All rights reserved. */ | ||
| -package com.keenwrite.quotes; | ||
| - | ||
| -import com.whitemagicsoftware.keenquotes.Converter; | ||
| - | ||
| -import static com.keenwrite.events.StatusEvent.clue; | ||
| -import static com.whitemagicsoftware.keenquotes.Converter.CHARS; | ||
| -import static com.whitemagicsoftware.keenquotes.ParserFactory.ParserType.PARSER_XML; | ||
| - | ||
| -/** | ||
| - * Responsible for curling straight quotes. This class will curl as many | ||
| - * straight quotes within HTML elements as possible. First, any straight | ||
| - * quotes within preformatted elements are converted into reserved Unicode | ||
| - * characters. That is, <code>'</code> becomes code point U+FFFE and | ||
| - * <code>"</code> becomes code point U+FFFF. After the substitution is made, | ||
| - * all block-level elements are curled, then the code points are restored. | ||
| - * </p> | ||
| - */ | ||
| -public class Typographer { | ||
| - | ||
| - private final static Converter sConverter = | ||
| - new Converter( lex -> clue( lex.toString() ), CHARS, PARSER_XML ); | ||
| - | ||
| - private Typographer() { | ||
| - } | ||
| - | ||
| - public static String curl( final String xhtml ) { | ||
| - return sConverter.apply( xhtml ); | ||
| - } | ||
| -} | ||
| -/* Copyright 2021 White Magic Software, Ltd. -- All rights reserved. */ | ||
| -package com.keenwrite.quotes; | ||
| - | ||
| -import org.junit.jupiter.api.Test; | ||
| - | ||
| -import java.io.BufferedReader; | ||
| -import java.io.IOException; | ||
| -import java.io.InputStream; | ||
| -import java.io.InputStreamReader; | ||
| - | ||
| -import static java.lang.System.lineSeparator; | ||
| -import static java.util.stream.Collectors.joining; | ||
| -import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| - | ||
| -/** | ||
| - * Test to make sure that the {@link Typographer} can replace straight quotes | ||
| - * without affecting preformatted HTML text elements. | ||
| - */ | ||
| -class TypographerTest { | ||
| - private static final String LINE_SEP = lineSeparator(); | ||
| - | ||
| - @Test | ||
| - void test_Quotes_Straight_Curly() throws IOException { | ||
| - Typographer.curl( read( "17165.html" ) ); | ||
| - } | ||
| - | ||
| - @SuppressWarnings( "SameParameterValue" ) | ||
| - private String read( final String filename ) throws IOException { | ||
| - try( final var reader = openReader( filename ) ) { | ||
| - return reader.lines().collect( joining( LINE_SEP ) ); | ||
| - } | ||
| - } | ||
| - | ||
| - /** | ||
| - * Opens a text file for reading. Callers are responsible for closing. | ||
| - * | ||
| - * @param filename The file to open. | ||
| - * @return An instance of {@link BufferedReader} that can be used to | ||
| - * read all the lines in the file. | ||
| - */ | ||
| - private BufferedReader openReader( final String filename ) { | ||
| - return new BufferedReader( new InputStreamReader( openStream( filename ) ) ); | ||
| - } | ||
| - | ||
| - private InputStream openStream( final String filename ) { | ||
| - final var is = getClass().getResourceAsStream( filename ); | ||
| - assertNotNull( is ); | ||
| - | ||
| - return is; | ||
| - } | ||
| -} | ||
| Delta | 7 lines added, 83 lines removed, 76-line decrease |
|---|