Typeset is an html pre-processor for web typography. It uses no client-side JavaScript but gives you hanging punctuation, soft hyphen insertion, optical margin outdents, small-caps conversion and punctuation substitution. See the results on the demo. The library is idempotent and runs on the server using Node – I'll adapt it to work on the client soon. The processed HTML & CSS renders correctly in IE5 and without any CSS!
npm install typeset
var typeset = require('typeset');
var html = '<p>"Hello," said the fox.</p>';
var output = typeset(html);
Then tweak typeset.css to match the metrics of your font and include it on your page.
Typeset.js is available as a plugin for grunt and gulp.
You can pass an options object to influence how your HTML is typeset:
var options = {
ignore: '.skip, #anything, .which-matches', // string of a CSS selector to skip
only: '#only-typeset, .these-elements' // string of a CSS selector to only apply typeset
};
$ npm install -g typeset
Usage: typeset-js <entry file> [options]
Options:
-h, --help output usage information
-V, --version output the version number
-o, --outfile write Typeset output to this file (if unspecified, Typeset will print to stdout)
-i, --ignore string of CSS selector(s) to ignore
-O, --only string of CSS selector(s) to exclusively apply typeset to
Example:
$ typeset-js inputFile.html -o outputFile.html --ignore ".some-class, h3"
Clone this repo then fetch its dependencies using npm install
. You can then edit the code in /src
.
- Add a build file
- Make this work on the client
- Incorporate features from Normalize Opentype?
- Remove recursion from eachTextNode.js
- Blot - a blogging platform I made, uses this to typeset blog posts
- You? Contact me or submit a pull request to add it here!