The main purpose of this library is to enhance typography of your HTML. It supposes that your texts already have right quotes, dashes and other symbols (you can use Typography Keyboard Layout). Richtypo adds non-breaking spaces in right places, adds CSS classes for abbreviations, ampersands and hanging punctuation for special styling.
- Rules for English and Russian languages
- Non-breaking spaces after prepositions and conjunctions, before em-dash, etc.
<nobr>
for words with hyphens- CSS classes for abbreviations, ampersands and hanging punctuation
- Takes care of your HTML tags
- Simple typographer (quotes, em-dash, etc.) for user generated content (e.g. comments)
var richtypo = require('richtypo');
var beautiful = richtypo.rich('Welcome to the world of beautiful web typography — only with Richtypo.');
var awesome = richtypo.title('Beautiful & Awesome Web Typography with “Richtypo”');
Will produce something like that:
Welcome to the world of beautiful web typography — only with Richtypo.
Beautiful <span class="amp">&</span> Awesome Web Typography with <span class="slaquo"> </span> <span class="hlaquo">“</span>Richtypo”'
$ npm install [-g] richtypo
richtypo.rich(text, lang) // Enhancing typography: non-breaking spaces, abbreviations
richtypo.title(text, lang) // Typography for big text: the same as rich + ampersands and hanging punctuation
richtypo.lite(text, lang) // Simple typographer (quotes, em-dash, etc.) for user generated content (e.g. comments)
richtypo.full(text, lang) // lite() + rich()
text
is an HTML string;lang
(optional) is a text language ('en'
or'ru'
).
richtypo.richtypo(text, rulesets, lang)
text
is a HTML string;rulesets
is array of rulesets (available rulesets:'save_tags'
,'cleanup_before'
,'spaces_lite'
,'spaces_lite'
,'spaces'
,'abbrs'
,'amps'
,'hanging'
,'cleanup_after'
,'restore_tags'
);lang
(optional) is a text language ('en'
or'ru'
).
richtypo.lang(lang)
lang
is a language ('en'
or'ru'
).
If you don’t want HTML tags in the result string just wrap it in textify
method:
richtypo.textify(richtypo.full(text, lang))
Usage: richtypo [--rules full] [--lang en] [--text] filename
Define ruleset:
-
lite - Simple typographer (quotes, em-dash, etc.) for user generated content (e.g. comments);
-
rich - Enhancing typography: non-breaking spaces, abbreviations;
-
title - Typography for big text: the same as --rich + ampersands and hanging punctuation. [default: "full"]
-
full - --light + --rich;
Text language: en
or ru
.
Convert result to text.
- Fix hanging punctuation.
- New API methods: full() and textify(). Fix rules loading when lang() method not invoked. CLI.
The MIT License, see the included License.md
file.