Richtypo: HTML typography enhancer for Node.js
Richtypo prepares your texts to publication on web: applies typography rules like quotes (
“”), dashes (
—) and non-breaking spaces to make text easier to read.
npm install richtypo
You will probably need to install a rule package for your language, like this:
npm install richtypo-rules-en
But it’s not required, see how to create your own rules.
These packcages contain recommended typography rules for different languages:
;;const text ='There are 1000 "rules" to enrich your text with Richtypo.';;
Will produce something like that:
There are 1,000 “rules” to enrich your text with Richtypo.
Note: The default export of
richtypo-rules-encontains recommended rules but you can import each rule separately, see below.
is actually rendered by Richtypo as the Unicode character for non-breaking-space
\xA0which works well with any modern browser. We use
in the examples to make it visible.
Richtypo can be curried and used as below:
;;const rt = ;const text ='There are 1000 "rules" to enrich your text with Richtypo.';// Will produce the same output as in the previous section;
Run only rules you need by importing them separately:
;;const text ='There are 1000 "rules" to enrich your text with RichTypo.';// this will only run spaces and quotes rules;
...) with an ellipsis (
…) can look like this:
const ellipsis = text;
And then you use it as any other rule:
;;// -> Typography everywhere…
Common rules package
richtypo-rules-common package contains common typography rules that you can use or extend in your own rules.
The common rules package exports
definitions, convenience constants that you can use in your own rules. For example,
definitions.quotes is set as
'["“”«»‘’]', which allows you to write:
;const quoteToUnderscore =text;quoteToUnderscore;
The common rules package also exports rules that you can reuse as is.
For example, the
ellipsis rule replaces
… symbol. Rather than you having to rewrite that rule, you can reexport it as part of your rules.
Some rules such as the
quotes rule are factory rules and need to be “configured”.
For the complete list of common rules, check out the Readme page of the common rule package.
Don’t forget to test your rules. Have a look at the English rules package to see how tests are done.
Authors and license
MIT License, see the included License.md file.