richtypo-rules-en v5.1.3
Richtypo English Rule Package
Converts this:
The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on
sunny morning...
to this:
The quick brown <abbr>FOX</abbr> = weighting
47 kg =  jumps over “the lazy dog”
on sunny morning…
Note:  
is and HTML entity for a hair space.
Installation
npm install --save richtypo richtypo-rules-en
Basic usage
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 <abbr>FOX</abbr> = weighting 47 kg = 
// jumps over “the lazy dog” on sunny morning…
The default export of richtypo-rules-en
contains recommended rules (marked with ¹ in a table below), but you can import each rule separately:
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
See more examples in Richtypo docs.
The rules
Rule | Description | Input | Output | |||||
---|---|---|---|---|---|---|---|---|
abbrs ¹ | wrap abbreviations in <abbr> tag | FOX | <abbr>FOX</abbr> | |||||
amps | wrap ampersands (&) in <span class="amp"> tag | Dog & Cat | Dog <span class="amp">&</span> Cat | |||||
dashes ¹ | transform a dash between two words to an em dash (—), add a non-breaking space before an em dash | dog - friend | dog — friend ² | |||||
degreeSigns ¹ | add a non-breaking space between a number and a degree sign (°) | 13 °C | 13 °C | |||||
ellipses ¹ | transform three dots (...) to an ellipsis (…) | ... | … | |||||
hyphenatedWords ¹ | wrap words with a hyphen in <nobr> tag | to-day | <nobr>to-day</nobr> | |||||
numberUnits ¹ | add a non-breaking space between a number and its unit | 2 kg | 2 kg ² | |||||
numbers | adds thousands separators to large numbers and put ordinals within <sup> tags | 10000.123, 1st 2nd 3rd | 10,000.123, 1<sup>st</sup> 2<sup>nd</sup> 3<sup>rd</sup> | |||||
orphans ¹ | add a non-breaking space in front of the last word in a paragraph (line) | their worst dreams | their worst dreams ² | quotes ¹ | transform dumb quotes (") to typography quotes («») | text "in quotes" | text «in quotes» | |
shortWords ¹ | add a non-breaking space after short words | my dogs | my dogs ² |
¹ Recommended rules (see code examples above)
²
is actually rendered as a symbol (\xA0
), not an HTML entity. We use
only in the docs for readability.
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago