Typography
Turn typed punctuation and symbols into typographic characters.
Typography converts patterns such as three periods, straight quotes, and (c) as the user types. Its input rules skip inline code and code blocks.
Try it
Section titled “Try it”Install
Section titled “Install”Run this from a Quickstart project.
cargo add gpdoc-plugin-typographyExample
Section titled “Example”With the paragraph plugin installed, type three periods in an empty paragraph to insert an ellipsis.
use gpdoc::{Editor, EditorConfig, Node};use gpdoc_plugin_paragraph::paragraph;use gpdoc_plugin_typography::{typography, TypographyOptions};
let config = EditorConfig::builder() .plugin(paragraph()) .plugin(typography(Default::default())) .build() .expect("configure editor");let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "")])?;for _ in 0..3 { editor.insert_text(".")?;}assert_eq!(editor.document().blocks(), [Node::textblock("paragraph", "…")]);Settings
Section titled “Settings”Right-to-left quotes
Section titled “Right-to-left quotes”Set TypographyOptions::rtl_quotes to reverse the opening and closing quote characters. The default is false.
let quotes = typography(TypographyOptions { rtl_quotes: true, ..Default::default() });Rule replacements
Section titled “Rule replacements”The default replacements map is empty. Insert Some(String) to override a rule or None to disable it. Missing keys use their built-in replacements.
let mut options = TypographyOptions::default();options.replacements.insert("ellipsis".into(), None);options.replacements.insert("rightArrow".into(), Some("⇒".into()));let punctuation = typography(options);Typing rules
Section titled “Typing rules”Built-in rule names
Section titled “Built-in rule names”The typography input rule checks the text leading up to the caret as you type. Use the following keys in the replacement map.
| Rule keys | Built-in replacements in the same order |
|---|---|
emDash, ellipsis |
—, … |
openDoubleQuote, closeDoubleQuote, openSingleQuote, closeSingleQuote |
“, ”, ‘, ’ |
leftArrow, rightArrow, laquo, raquo |
←, →, «, » |
copyright, trademark, servicemark, registeredTrademark |
©, ™, ℠, ® |
oneHalf, oneQuarter, threeQuarters |
½, ¼, ¾ |
plusMinus, notEqual, multiplication |
±, ≠, × |
superscriptTwo, superscriptThree |
², ³ |