### Install project dependencies Source: https://github.com/sapegin/richtypo.js/blob/master/Contributing.md Run this command to install all required project dependencies before starting development. ```bash npm install ``` -------------------------------- ### Installation Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/FrenchRules.md Install the Richtypo.js library using npm. ```APIDOC ## Installation ```bash npm install --save richtypo ``` ``` -------------------------------- ### Install Richtypo Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/RussianRules.md Use npm to install the library as a project dependency. ```bash npm install --save richtypo ``` -------------------------------- ### Rule Factories Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/CommonRules.md Rule factories allow for the customization of common rules based on language-specific typographic conventions. Examples include quote styles and number formatting. ```APIDOC ## Rule factories Use factory rules to customize some common rules, like quotes, for your language. For example, quotes in English are written as `“”` while in French they are written as `«»`. ```js import { quotesFactory } from 'richtypo/rules/common'; export const quotes = quotesFactory({ openingQuote: '«', closingQuote: '»' }); ``` | Rule | Arguments | Description | | ----------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | | **`numberOrdinalsFactory`** | `{ ordinal }` | format _1st, 2nd, 3rd_ etc. into _1st, 2nd, 3rd_. `ordinal` should be a regex array of strings such as `'(st | nd | rd | th)'`. | | **`numberSeparatorsFactory`** | `{ decimalsSeparator, thousandsSeparator }` | format numbers with thousands separator | | **`quotesFactory`** | `{ openingQuote, closingQuote }` | replace dumb quotes with typography quotes | ``` -------------------------------- ### Create Custom Quotes Rule Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/CommonRules.md Use the quotesFactory to create a custom quotes rule for a specific language. This example sets French-style opening and closing quotes. ```javascript import { quotesFactory } from 'richtypo/rules/common'; export const quotes = quotesFactory({ openingQuote: '«', closingQuote: '»' }); ``` -------------------------------- ### Run linters and tests Source: https://github.com/sapegin/richtypo.js/blob/master/Contributing.md Execute the test suite and linters to ensure code quality. ```bash npm test ``` -------------------------------- ### Apply basic typography rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/Readme.md Import the library and language-specific rules to process text. ```javascript import richtypo from 'richtypo'; import rules from 'richtypo/rules/en'; const text = 'There are 1000 "rules" to enrich your text with Richtypo.'; richtypo(rules, text); ``` ```html There are 1,000 “rules” to enrich your text with Richtypo. ``` -------------------------------- ### Use and configure common rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/Readme.md Re-export common rules or configure factory rules like quotes. ```javascript import { ellipsis } from 'richtypo/rules/common'; export default { quoteToUnderscore, ellipsis }; ``` ```javascript import { ellipsis, quotesFactory } from 'richtypo/rules/common'; export default { ellipsis, quotes: quotesFactory({ openingQuote: '«', closingQuote: '»' }) }; ``` -------------------------------- ### Create typography rules using definitions Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/CommonRules.md Import common definitions to improve the readability and maintainability of custom typography rules. ```js import { definitions } from 'richtypo/rules/common'; const { space, nbsp } = definitions; export function numberSigns(text) { return text.replace(new RegExp(`№${space}`, 'g'), `№${nbsp}`); } ``` -------------------------------- ### Apply default Russian typography rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/RussianRules.md Import the default rule set and apply it to a string to automatically format Russian typography. ```javascript import richtypo from 'richtypo'; import rules from 'richtypo/rules/ru'; const text = 'Настругал Папа Карло тысячу БУРАТИН 29 февраля - ' + 'используйте "Ричтайпо" и ваши уши будут торчать из-за туч.'; richtypo(rules, text); // -> Настругал Папа Карло тысячу БУРАТИН 29 февраля — // используйте «Ричтайпо» и ваши уши будут торчать из-за туч. ``` -------------------------------- ### Run tests in watch mode Source: https://github.com/sapegin/richtypo.js/blob/master/Contributing.md Run the test suite in watch mode for continuous feedback during development. ```bash npm run test:watch ``` -------------------------------- ### Create custom rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/Readme.md Define custom transformation functions and pass them to the richtypo processor. ```javascript function ellipsis(text) { return text.replace(/\.{2,}/gim, '…'); } ``` ```javascript import richtypo from 'richtypo'; richtypo(ellipsis, 'Typography everywhere...'); // -> Typography everywhere… ``` -------------------------------- ### Apply default English typography rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/EnglishRules.md Import the recommended English rules and apply them to a text string using the richtypo function. ```javascript import richtypo from 'richtypo'; import rules from 'richtypo/rules/en'; const text = `The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on sunny morning...`; richtypo(rules, text); // → The quick brown FOX — weighting 47 kg —  // jumps over “the lazy dog” on sunny morning… ``` -------------------------------- ### Use Common Definitions in Custom Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Demonstrates using definitions like space, nbsp, and letter from the common module to create custom typography rules. ```javascript import { definitions, shortWords, orphans, numberUnits, degreeSigns, ellipses, abbrs, hyphenatedWords, dashesBasic, quotesFactory, numberOrdinalsFactory, numberSeparatorsFactory } from 'richtypo/rules/common'; // Use definitions in custom rules const { space, nbsp, letter, notInTag } = definitions; function customNumberRule(text) { return text.replace(new RegExp(`№${space}`, 'g'), `№${nbsp}`); } ``` -------------------------------- ### Use rule definitions Source: https://github.com/sapegin/richtypo.js/blob/master/docs/Readme.md Utilize exported constants from common rules to simplify regex patterns in custom rules. ```javascript import { definitions } from 'richtypo/rules/common'; function quoteToUnderscore(text) { return text.replace(new RegExp(`${definitions.quotes}`, 'gm'), '_'); } export default { quoteToUnderscore }; ``` -------------------------------- ### Core API Usage Source: https://context7.com/sapegin/richtypo.js/llms.txt Process text using recommended language rules, single rules, or custom arrays of rules. ```javascript import richtypo from 'richtypo'; import rules from 'richtypo/rules/en'; // Using recommended rules from a language module const text = 'The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on sunny morning...'; const result = richtypo(rules, text); // Output: The quick brown FOX —​weighting 47 kg — jumps over "the lazy dog" on sunny morning… // (with non-breaking spaces and proper em dashes) // Using a single rule import { quotes } from 'richtypo/rules/en'; richtypo(quotes, 'He said "hello" to her'); // Output: He said "hello" to her // Using an array of specific rules import { shortWords, orphans, ellipses } from 'richtypo/rules/en'; richtypo([shortWords, orphans, ellipses], 'We go to the mall...'); // Output: We go to the mall… // (with non-breaking spaces after short words and before the last word) ``` -------------------------------- ### Apply specific Russian typography rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/RussianRules.md Import individual rules to apply only a subset of formatting to the input text. ```javascript import richtypo from 'richtypo'; import { quotes, numberSeparators } from 'richtypo/rules/ru'; richtypo( [quotes, numberSeparators], 'Текст "в кавычках" - 123456,78' ); // -> Текст «в кавычках» - 123 456,78 ``` -------------------------------- ### Create and Combine Custom Richtypo Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Define custom JavaScript functions for text transformations and combine them with built-in rules. Ensure all necessary rules are imported before use. ```javascript import richtypo from 'richtypo'; import { definitions } from 'richtypo/rules/common'; import { quotes, orphans } from 'richtypo/rules/en'; // Simple custom rule: replace three dots with ellipsis function customEllipsis(text) { return text.replace(/\.{3,}/g, '…'); } // Custom rule using definitions const { nbsp, notInTag } = definitions; function noBreakAfterDash(text) { return text.replace( new RegExp(`${notInTag}(\\w+)-(\\w+)\\s`, 'g'), `$1-$2${nbsp}` ); } // Custom rule to wrap specific terms function highlightTrademark(text) { return text.replace(/\bMyBrand\b/g, 'MyBrand'); } // Combine custom rules with built-in rules const myRules = [ quotes, orphans, customEllipsis, noBreakAfterDash, highlightTrademark ]; richtypo(myRules, 'Visit MyBrand for day-to-day needs...'); // Output: Visit MyBrand for day-to-day needs… ``` -------------------------------- ### Richtypo Definitions Usage Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/CommonRules.md How to import and utilize the common typography definitions to create custom text transformation rules. ```APIDOC ## Richtypo Definitions ### Description Definitions are pre-configured regular expression components used to improve the readability and maintainability of custom typography rules. ### Available Definitions | Definition name | Description | | --- | --- | | **dash** | hyphen (-) or em dash (—) | | **thinspace** | thin space (\u2009) | | **nbthinspace** | thin non-breaking space (\u202f) | | **letter** | any European or Cyrillic letter | | **letterOrQuote** | any European or Cyrillic letter with quotes | | **nbsp** | non-breaking space | | **notInTag** | negative lookbehind to ensure rules do not run inside HTML tags | | **openingQuote** | any opening quote | | **punctuation** | punctuation symbols | | **quote** | any quotes | | **semicolon** | a semicolon | | **shortWord** | a word of one or two letters | | **space** | any space (except \n) | | **tag** | matches any HTML tag | | **upperLetter** | any uppercase European or Cyrillic letter | ### Usage Example ```js import { definitions } from 'richtypo/rules/common'; const { space, nbsp } = definitions; export function numberSigns(text) { return text.replace(new RegExp(`№${space}`, 'g'), `№${nbsp}`); } ``` ``` -------------------------------- ### Compose specific rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/Readme.md Selectively apply specific rules by passing an array of imported rule functions. ```javascript import richtypo from 'richtypo'; import { spaces, quotes } from 'richtypo/rules/en'; const text = 'There are 1000 "rules" to enrich your text with RichTypo.'; // this will only run spaces and quotes rules richtypo([spaces, quotes], text); ``` -------------------------------- ### Import Common Rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/CommonRules.md Import common rules like abbreviations from the 'richtypo/rules/common' module. These rules can be used directly for text formatting. ```javascript import { abbrs } from 'richtypo/rules/common'; ``` -------------------------------- ### Common Definitions for Custom Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Lists available definitions from the common module that can be used when building custom typography rules. ```javascript // Available definitions for custom rules: // - nbsp: non-breaking space (\u00A0) // - thinspace: thin space (\u2009) // - nbthinspace: thin non-breaking space (\u202F) // - space: any space character pattern // - letter: any letter pattern (European + Cyrillic) // - upperLetter: uppercase letter pattern // - dash: hyphen or em dash pattern // - quote: any quote character pattern // - punctuation: punctuation symbols pattern // - notInTag: negative lookbehind for HTML tag context // - shortWord: 1-2 letter word pattern // - tag: HTML tag pattern ``` -------------------------------- ### Apply specific English typography rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/EnglishRules.md Import individual rules to apply only specific typographic transformations to a text string. ```javascript import richtypo from 'richtypo'; import { quotes, numberSeparators } from 'richtypo/rules/en'; richtypo([quotes, numberSeparators], 'Text "in quotes" - 123456.78'); // → Text “in quotes” - 123,456.78 ``` -------------------------------- ### Typography Rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/FrenchRules.md Overview of French typography rules provided by the richtypo/rules/french module. ```APIDOC ## Rules The rules of this module include the `spaces`, `abbr`, `emdash`, `amp`, `ellipsis` rules that are directly imported from the [`richtypo/rules/common` module](./CommonRules.md). > [!NOTE] > For better readability, the non-breaking space symbol ` ` is replaced with two underscores `__` and the narrow non-breaking space symbol ` ` with a single underscore `_`. | Rule | Description | | ---------------------- | ------------------------------------------------------------------------------------------------- | | **`quotes`** | transforms straight double quotes into double angle quotes | | **`numberOrdinals`** | put ordinals within `` tags | | **`numberSeparators`** | adds thousands separators to large numbers | | **`punctuationMarks`** | adds narrow non-breaking space before or after punctuation as it is the rule in French typography | | **`recommended`** | runs all rules except `numberOrdinals` and `numberSeparators` | ``` -------------------------------- ### Common Rules Source: https://github.com/sapegin/richtypo.js/blob/master/docs/rules/CommonRules.md This section lists the common rules available for direct import and use in RichTypo.js. Each rule targets specific typographic adjustments. ```APIDOC ## Rules Rules are available as named exports: ```js import { abbrs } from 'richtypo/rules/common'; ``` | Rule name | Description | | -------------------- | ----------------------------------------------------------------------- | | **`abbrs`** | wrap abbreviations in `` tags | | **`amps`** | wrap an ampersand (&) in `` tags | | **`dashesBasic`** | replace `-` and `--` with an em-dashes | | **`dashesAdvanced`** | add a non-breaking thin space before an em dash, and a thin space after | | **`degreeSigns`** | add a non-breaking thin space between numbers and degree symbol | | **`ellipses`** | replace three consecutive dots with an ellipsis | | **`numberUnits`** | insert non-breaking space between numbers and the following word | | **`orphans`** | add a non-breaking space to avoid orphans | | **`shortWords`** | add a non-breaking space after short words | _¹ ` ` is actually rendered as a symbol (`\xA0`), not an HTML entity. We use ` ` only in the docs for readability._ ``` -------------------------------- ### Apply French Typography Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Applies default French typography rules, including French-style guillemets and punctuation spacing. ```javascript import richtypo from 'richtypo'; import rules, { quotes, punctuationMarks, numberOrdinals, numberSeparators } from 'richtypo/rules/fr'; // Default recommended rules richtypo(rules, 'texte entre "guillemets"'); // Output: texte entre «guillemets» ``` -------------------------------- ### Apply Russian Typography Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Applies a recommended set of Russian typography rules to a given text, including quotes, abbreviations, and spacing. ```javascript import richtypo from 'richtypo'; import rules, { quotes, shortWords, orphans, dashes, ellipses, abbrs, hyphenatedWords, initials, particles, numberSigns, sectionSigns, etcs, numberUnits, degreeSigns } from 'richtypo/rules/ru'; // Default recommended rules const text = 'Настругал Папа Карло тысячу БУРАТИН 29 февраля - используйте "Ричтайпо" и ваши уши будут торчать из-за туч.'; richtypo(rules, text); // Output: Настругал Папа Карло тысячу БУРАТИН 29 февраля — используйте «Ричтайпо» и ваши уши будут торчать из-за туч. ``` -------------------------------- ### English Typography Rules (richtypo/rules/en) Source: https://context7.com/sapegin/richtypo.js/llms.txt This section details the various typography rules available for English text, including transformations for quotes, dashes, ellipses, number formatting, and more. Each rule can be used individually or combined. ```APIDOC ## English Typography Rules (richtypo/rules/en) ### Description Provides typography transformations optimized for English text. ### Rules #### `rules` (Default Recommended Rules) Applies all common English typography transformations. ```javascript import rules from 'richtypo/rules/en'; richtypo(rules, 'The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on sunny morning...'); // Output: The quick brown FOX — weighting 47 kg — jumps over "the lazy dog" on sunny morning… ``` #### `quotes` Transforms straight quotes to curly quotes. ```javascript import { quotes } from 'richtypo/rules/en'; richtypo(quotes, 'He said "hello" and "goodbye"'); // Output: He said "hello" and "goodbye" ``` #### `shortWords` Adds a non-breaking space after 1-2 letter words. ```javascript import { shortWords } from 'richtypo/rules/en'; richtypo(shortWords, 'We go to the mall'); // Output: We go to the mall (with non-breaking spaces) ``` #### `orphans` Adds a non-breaking space before the last word of a sentence to prevent orphans. ```javascript import { orphans } from 'richtypo/rules/en'; richtypo(orphans, 'Avoid single words at line end'); // Output: Avoid single words at line end (with non-breaking space before "end") ``` #### `dashesBasic` Transforms double hyphens to em dashes. ```javascript import { dashesBasic } from 'richtypo/rules/en'; richtypo(dashesBasic, 'dog -- friend'); // Output: dog — friend ``` #### `dashesAdvanced` Transforms single hyphens to em dashes with thin spaces around them. ```javascript import { dashesAdvanced } from 'richtypo/rules/en'; richtypo(dashesAdvanced, 'word - another'); // Output: word — another (with thin spaces around dash) ``` #### `ellipses` Replaces three dots with the ellipsis character. ```javascript import { ellipses } from 'richtypo/rules/en'; richtypo(ellipses, 'thinking...'); // Output: thinking… ``` #### `numberUnits` Adds a non-breaking space between a number and its unit. ```javascript import { numberUnits } from 'richtypo/rules/en'; richtypo(numberUnits, '100 km'); // Output: 100 km (with non-breaking space) ``` #### `degreeSigns` Applies proper spacing for degree signs. ```javascript import { degreeSigns } from 'richtypo/rules/en'; richtypo(degreeSigns, '25 °C'); // Output: 25 °C (with thin non-breaking space) ``` #### `numberSeparators` Adds thousands separators to numbers (not in recommended rules). ```javascript import { numberSeparators } from 'richtypo/rules/en'; richtypo(numberSeparators, '1234567.89'); // Output: 1,234,567.89 ``` #### `numberOrdinals` Adds superscript ordinal suffixes to numbers (not in recommended rules). ```javascript import { numberOrdinals } from 'richtypo/rules/en'; richtypo(numberOrdinals, '1st 2nd 3rd 4th'); // Output: 1st 2nd 3rd 4th ``` #### `abbrs` Wraps abbreviations in `abbr` tags (not in recommended rules). ```javascript import { abbrs } from 'richtypo/rules/en'; richtypo(abbrs, 'The NASA and FBI'); // Output: The NASA and FBI ``` #### `amps` Wraps ampersands in a styled span (not in recommended rules). ```javascript import { amps } from 'richtypo/rules/en'; richtypo(amps, 'Tom & Jerry'); // Output: Tom & Jerry ``` #### `hyphenatedWords` Wraps short hyphenated words in `nobr` tags (not in recommended rules). ```javascript import { hyphenatedWords } from 'richtypo/rules/en'; richtypo(hyphenatedWords, 'day-to-day'); // Output: day-to-day ``` ``` -------------------------------- ### Create Custom Quote Rules with Factory Source: https://context7.com/sapegin/richtypo.js/llms.txt Uses the quotesFactory from the common module to create custom quote characters for specific languages, like French guillemets. ```javascript // Use quotesFactory for custom quote characters const frenchQuotes = quotesFactory({ openingQuote: '«', closingQuote: '»' }); frenchQuotes('texte "en guillemets"'); // Output: texte «en guillemets» ``` -------------------------------- ### Create Custom Number Ordinal Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Uses numberOrdinalsFactory to create locale-specific rules for formatting number ordinals, such as English 'st', 'nd', 'rd', 'th'. ```javascript // Use numberOrdinalsFactory for locale-specific ordinals const englishOrdinals = numberOrdinalsFactory({ ordinal: '(st|nd|rd|th)' }); englishOrdinals('1st 2nd 3rd'); // Output: 1st 2nd 3rd ``` -------------------------------- ### Create Custom Number Separator Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Uses numberSeparatorsFactory to create locale-specific number formatting rules, such as for German thousands and decimal separators. ```javascript // Use numberSeparatorsFactory for locale-specific number formatting const germanNumberSeparators = numberSeparatorsFactory({ decimalsSeparator: ',', thousandsSeparator: '.' }); germanNumberSeparators('1234567,89'); // Output: 1.234.567,89 ``` -------------------------------- ### Core API: richtypo(rules, text) Source: https://context7.com/sapegin/richtypo.js/llms.txt The main function of Richtypo.js processes input text through provided rules. It can accept a single rule, an array of rules, or a rules module default export. The library preserves HTML tags, Markdown code blocks, and other protected content during processing. ```APIDOC ## Core API: richtypo(rules, text) ### Description Processes input text through provided rules, preserving HTML tags and code blocks. ### Method ```javascript richtypo(rules, text) ``` ### Parameters #### Arguments - **rules** (Rule | Rule[] | object) - A single rule, an array of rules, or a rules module default export. - **text** (string) - The input text to process. ### Request Example ```javascript import richtypo from 'richtypo'; import rules from 'richtypo/rules/en'; const text = 'The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on sunny morning...'; const result = richtypo(rules, text); // Output: The quick brown FOX —​weighting 47 kg — jumps over "the lazy dog" on sunny morning… // Using a single rule import { quotes } from 'richtypo/rules/en'; richtypo(quotes, 'He said "hello" to her'); // Output: He said "hello" to her // Using an array of specific rules import { shortWords, orphans, ellipses } from 'richtypo/rules/en'; richtypo([shortWords, orphans, ellipses], 'We go to the mall...'); // Output: We go to the mall… ``` ### Response #### Success Response - **string** - The processed text with applied typography rules. ``` -------------------------------- ### Apply Specific French Typography Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Applies individual French typography rules for quotes, punctuation, number ordinals, and number separators. ```javascript // French quotes (guillemets with narrow non-breaking spaces) richtypo(quotes, 'texte entre "guillemets"'); // Output: texte entre «guillemets» ``` ```javascript // French punctuation: narrow non-breaking space before certain punctuation richtypo(punctuationMarks, 'Ceci ? est: un «texte» avec de la ponctuation!'); // Output: Ceci ? est : un « texte » avec de la ponctuation ! // (with narrow non-breaking spaces before ?, :, !, and inside «») ``` ```javascript // Number ordinals richtypo(numberOrdinals, '1er 2nd 3èmes'); // Output: 1er 2nd 3èmes ``` ```javascript // Number separators (French uses space as thousands separator) richtypo(numberSeparators, '10000,123'); // Output: 10 000,123 (with non-breaking spaces) ``` -------------------------------- ### Apply Specific Russian Typography Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Applies individual Russian typography rules such as quotes, dashes, hyphenated words, initials, particles, and signs. ```javascript // Russian quotes (guillemets) richtypo(quotes, 'текст "в кавычках"'); // Output: текст «в кавычках» ``` ```javascript // Dashes: em dash with non-breaking space before richtypo(dashes, 'собака - друг'); // Output: собака — друг ``` ```javascript // Hyphenated words: wrap in nobr richtypo(hyphenatedWords, 'из-за'); // Output: из-за ``` ```javascript // Initials: wrap in nobr richtypo(initials, 'В. И. Ленин'); // Output: В. И. Ленин ``` ```javascript // Particles: non-breaking space before particles richtypo(particles, 'это ж как бы'); // Output: это ж как бы (with non-breaking spaces) ``` ```javascript // Number signs: non-breaking space after № richtypo(numberSigns, '№ 3'); // Output: № 3 (with non-breaking space) ``` ```javascript // Section signs: non-breaking space after § richtypo(sectionSigns, '§ 3'); // Output: § 3 (with non-breaking space) ``` ```javascript // Russian etc abbreviations richtypo(etcs, 'и т. д.'); // Output: и т. д. (with non-breaking spaces) ``` -------------------------------- ### English Typography Rules Source: https://context7.com/sapegin/richtypo.js/llms.txt Apply specific English typography transformations including quotes, dashes, number formatting, and abbreviations. ```javascript import richtypo from 'richtypo'; import rules, { quotes, shortWords, orphans, dashesBasic, dashesAdvanced, ellipses, numberUnits, degreeSigns, numberSeparators, numberOrdinals, abbrs, amps, hyphenatedWords } from 'richtypo/rules/en'; // Default recommended rules (all common transformations) richtypo(rules, 'The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on sunny morning...'); // Output: The quick brown FOX — weighting 47 kg — jumps over "the lazy dog" on sunny morning… // Quotes: straight to curly richtypo(quotes, 'He said "hello" and "goodbye"'); // Output: He said "hello" and "goodbye" // Short words: non-breaking space after 1-2 letter words richtypo(shortWords, 'We go to the mall'); // Output: We go to the mall (with non-breaking spaces) // Orphans: non-breaking space before last word richtypo(orphans, 'Avoid single words at line end'); // Output: Avoid single words at line end (with non-breaking space before "end") // Dashes: transform hyphens to em dashes richtypo(dashesBasic, 'dog -- friend'); // Output: dog — friend richtypo(dashesAdvanced, 'word - another'); // Output: word — another (with thin spaces around dash) // Ellipses: three dots to ellipsis character richtypo(ellipses, 'thinking...'); // Output: thinking… // Number units: non-breaking space between number and unit richtypo(numberUnits, '100 km'); // Output: 100 km (with non-breaking space) // Degree signs: proper spacing richtypo(degreeSigns, '25 °C'); // Output: 25 °C (with thin non-breaking space) // Number separators: add thousands separator (not in recommended) richtypo(numberSeparators, '1234567.89'); // Output: 1,234,567.89 // Number ordinals: superscript ordinal suffixes (not in recommended) richtypo(numberOrdinals, '1st 2nd 3rd 4th'); // Output: 1st 2nd 3rd 4th // Abbreviations: wrap in abbr tags (not in recommended) richtypo(abbrs, 'The NASA and FBI'); // Output: The NASA and FBI // Ampersands: wrap in styled span (not in recommended) richtypo(amps, 'Tom & Jerry'); // Output: Tom & Jerry // Hyphenated words: wrap short hyphenated words in nobr (not in recommended) richtypo(hyphenatedWords, 'day-to-day'); // Output: day-to-day ``` -------------------------------- ### HTML and Markdown Preservation in Richtypo Source: https://context7.com/sapegin/richtypo.js/llms.txt Richtypo.js automatically preserves content within HTML tags, code blocks, and Markdown syntax. Rules only affect regular text content. ```javascript import richtypo from 'richtypo'; import rules from 'richtypo/rules/en'; // HTML tags are preserved (content inside tags is not modified) richtypo(rules, 'A nice photo - 2024'); // Output: A nice photo - 2024 // (alt attribute content unchanged) // HTML content between tags IS processed richtypo(rules, '

Some "quoted" text - with dashes...

'); // Output:

Some "quoted" text — with dashes…

// Code and pre tags preserve their content richtypo(rules, 'const x = "string";'); // Output: const x = "string"; // Markdown inline code is preserved richtypo(rules, 'Use `const x = "y"` for variables...'); // Output: Use `const x = "y"` for variables… // Markdown fenced code blocks are preserved const markdown = " Some text \"with quotes\"... \ \nSome text \"with quotes\"... \ \n\ javascript const greeting = \"Hello\"; console.log(greeting); \ \ \ More text... "; richtypo(rules, markdown); // Output: Text outside code block is processed, code block content unchanged // Markdown links preserve URLs richtypo(rules, 'Visit [our \"site\"](/path/to/page) today...'); // Output: Visit [our \"site\"](/path/to/page) today… // Markdown tables are preserved richtypo(rules, '| Column A | Column B |\n| --- | --- |\n| data | data |'); // Output unchanged - tables preserved ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.