` 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, '
');
// Output:
// (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.