Project

rtypeset

0.01
No commit activity in last 3 years
No release in over 3 years
A pure Ruby implementation of Typeset.js, an HTML pre-processor for web typography
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
~> 2.0.1
>= 5.8.0
~> 3.12

Runtime

 Project Readme

An HTML pre-processor for web typography

Gem Version Build Status Documentation Status Code Climate Test Coverage

A pure Ruby typographic pre-processor for HTML inspired by Typeset.js that gives you:

* Real hang­ing punc­tu­a­tion
* Soft hy­phen in­ser­tion
* Op­ti­cal mar­gin out­dents
* Small-caps conversion
* Punc­tu­a­tion sub­sti­tu­tion
* Space sub­sti­tu­tion

Installation

gem install rtypeset

Usage

Just require the typeset gem and then call #typeset to receive beautifully-formatted HTML:

require 'typeset'

raw_html = <<HTM
<p>Yjarni Sigurðardóttir spoke to NATO from Iceland yesterday:
"Light of my life, fire of my florins -- my sin, my soul.
The tip of the tongue taking a trip to 118° 19' 43.5".":</p>
HTM

# Output beautifully-formatted HTML
puts Typeset.typeset(raw_html)

Customisation

Want more control over your typesetting?

Disabling Features

You can selectively disable Typeset features by passing in an options hash to #typeset:

# Disable hyphenation and small caps conversion.
options = {:disable => [:hyphenate, :small-caps]}
Typeset.typeset(raw_html, options)

The full list of modules is: :quotes, :hanging_punctuation, :spaces, :small_caps, :hyphenate, :ligatures and :punctuation.

Hyphenation Language

If you're using hyphenation (it's on by default!) you may want to specify the language (the default is en_us):

Typeset.typeset(raw_html, {:language => "en_us"})