diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextSymbol.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextSymbol.kt index 8034e6cd..22ed7bc7 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextSymbol.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextSymbol.kt @@ -6,9 +6,15 @@ import eu.iamgio.quarkdown.visitor.node.NodeVisitor /** * A text-based symbol, such as `©`, `…`, `≥`. * This is usually the result of a combination of multiple characters (e.g. `(C)` -> `©`). - * @param text processed symbol (e.g. `©`) + * @param symbol processed symbol (e.g. `©`) * @see eu.iamgio.quarkdown.lexer.patterns.TextSymbolReplacement */ -data class TextSymbol(override val text: String) : PlainTextNode { +data class TextSymbol(val symbol: Char) : PlainTextNode { + /** + * @return [symbol] as a string + */ + override val text: String + get() = symbol.toString() + override fun accept(visitor: NodeVisitor): T = visitor.visit(this) } diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/patterns/TextSymbolReplacement.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/patterns/TextSymbolReplacement.kt index 775a7bf1..a3173715 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/patterns/TextSymbolReplacement.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/patterns/TextSymbolReplacement.kt @@ -5,104 +5,106 @@ import eu.iamgio.quarkdown.lexer.tokens.TextSymbolToken /** * Patterns for sequences of characters that correspond to text symbols. + * @param result symbol that the sequence is replaced with + * @param regex regex pattern that matches the sequence to be replaced */ -enum class TextSymbolReplacement(val result: String, val regex: Regex) { +enum class TextSymbolReplacement(val result: Char, val regex: Regex) { /** * `(C)` -> `©` */ - COPYRIGHT("©", "\\(C\\)".toRegex()), + COPYRIGHT('©', "\\(C\\)".toRegex()), /** * `(R)` -> `®` */ - REGISTERED("®", "\\(R\\)".toRegex()), + REGISTERED('®', "\\(R\\)".toRegex()), /** * `(TM)` -> `™` */ - TRADEMARK("™", "\\(TM\\)".toRegex()), + TRADEMARK('™', "\\(TM\\)".toRegex()), /** * `-` -> `—` * * It must be surrounded by a word character and a space on both sides. */ - EM_DASH("—", "(?<=\\w\\s)-(?=\\s\\w)".toRegex()), + EM_DASH('—', "(?<=\\w\\s)-(?=\\s\\w)".toRegex()), /** * `...` -> `…` * * Must be either at the beginning or end of a word, not in-between. */ - ELLIPSIS("…", "(\\.\\.\\.(?=\\s|\$))|((?<=\\s|^)\\.\\.\\.)".toRegex()), + ELLIPSIS('…', "(\\.\\.\\.(?=\\s|\$))|((?<=\\s|^)\\.\\.\\.)".toRegex()), /** * `->` -> `→` */ - SINGLE_RIGHT_ARROW("→", "->".toRegex()), + SINGLE_RIGHT_ARROW('→', "->".toRegex()), /** * `<-` -> `←` */ - SINGLE_LEFT_ARROW("←", "<-".toRegex()), + SINGLE_LEFT_ARROW('←', "<-".toRegex()), /** * `=>` -> `⇒` */ - DOUBLE_RIGHT_ARROW("⇒", "=>".toRegex()), + DOUBLE_RIGHT_ARROW('⇒', "=>".toRegex()), /** * `<==` -> `⇐` */ - DOUBLE_LEFT_ARROW("⇐", "<==".toRegex()), + DOUBLE_LEFT_ARROW('⇐', "<==".toRegex()), /** * `>=` -> `≥` */ - GREATER_EQUAL("≥", ">=".toRegex()), + GREATER_EQUAL('≥', ">=".toRegex()), /** * `<=` -> `≤` */ - LESS_EQUAL("≤", "<=".toRegex()), + LESS_EQUAL('≤', "<=".toRegex()), /** * `!=` -> `≠` */ - NOT_EQUAL("≠", "!=".toRegex()), + NOT_EQUAL('≠', "!=".toRegex()), /** * `+-` -> `±` */ - PLUS_MINUS("±", "\\+-".toRegex()), + PLUS_MINUS('±', "\\+-".toRegex()), /** * `'` -> `‘` * * Must not be preceded by a word and must be followed by a word character. */ - TYPOGRAPHIC_LEFT_APOSTROPHE("‘", "(?<=\\s|^)'(?=\\w)".toRegex()), + TYPOGRAPHIC_LEFT_APOSTROPHE('‘', "(?<=\\s|^)'(?=\\w)".toRegex()), /** * `'` -> `’` * * Must not be preceded by a whitespace. */ - TYPOGRAPHIC_RIGHT_APOSTROPHE("’", "(? `“` * * Must not be preceded by a word character and must be followed by a word character. */ - TYPOGRAPHIC_LEFT_QUOTATION_MARK("“", "(? `”` * * Must not be preceded by a whitespace and not followed by a word character. */ - TYPOGRAPHIC_RIGHT_QUOTATION_MARK("”", "(?