All Projects → ekalinin → Typogr.js

ekalinin / Typogr.js

Licence: mit
Typography utils for javascript

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Typogr.js

Commissioner
Commissioner is a variable and static sans typeface.
Stars: ✭ 147 (-49.13%)
Mutual labels:  typography
huozi.js
A simple typography engine for CJK languages, especially designed for game rich-text. 用于游戏富文本的中日韩文字排印引擎。
Stars: ✭ 135 (-53.29%)
Mutual labels:  typography
Typelighterjs
Take a stride into the world of dynamic and appealing typewriters. You can be sure that you will never even think of looking back.
Stars: ✭ 262 (-9.34%)
Mutual labels:  typography
baseline
New method for creating leading on the web
Stars: ✭ 31 (-89.27%)
Mutual labels:  typography
handwrite
Handwrite generates a custom font based on your handwriting sample.
Stars: ✭ 235 (-18.69%)
Mutual labels:  typography
Tourney
3 axes/variable/no curves
Stars: ✭ 20 (-93.08%)
Mutual labels:  typography
Tehreer-Cocoa
Standalone text engine for iOS
Stars: ✭ 31 (-89.27%)
Mutual labels:  typography
Awesome Falsehood
😱 Falsehoods Programmers Believe in
Stars: ✭ 16,614 (+5648.79%)
Mutual labels:  typography
typeset.css
✍ tr.v. type·set To set (written material) into type; compose.
Stars: ✭ 19 (-93.43%)
Mutual labels:  typography
Blotter
A JavaScript API for drawing unconventional text effects on the web.
Stars: ✭ 2,833 (+880.28%)
Mutual labels:  typography
jekyll-typogrify
A Jekyll plugin that improves the typography of your Liquid templates.
Stars: ✭ 26 (-91%)
Mutual labels:  typography
fibonacci
A simplistic read-friendly blog template built with golden ratio
Stars: ✭ 30 (-89.62%)
Mutual labels:  typography
diaeresis
A lightweight (<1kb minified + gzipped) JavaScript library that lets you wield diæreses like C̶h̶u̶c̶k̶ Mary Norris:
Stars: ✭ 15 (-94.81%)
Mutual labels:  typography
tipograph
A little javascript library and command line tool that makes your written content more typographically correct.
Stars: ✭ 52 (-82.01%)
Mutual labels:  typography
Web Typography Glossary
Webタイポグラフィの基礎知識と実践
Stars: ✭ 279 (-3.46%)
Mutual labels:  typography
typefaces
Collection of Google fonts as typeface data for usage with three.js, react-three-fiber, and other tools.
Stars: ✭ 53 (-81.66%)
Mutual labels:  typography
kironroy.github.io
Portfolio
Stars: ✭ 14 (-95.16%)
Mutual labels:  typography
T.js
⌨️ Lightweight $.Hypertext.Typewriter
Stars: ✭ 289 (+0%)
Mutual labels:  typography
Jolitypo
🔤 Microtypography fixer for the web
Stars: ✭ 282 (-2.42%)
Mutual labels:  typography
Gutenberg
A meaningful web typography starter kit.
Stars: ✭ 2,765 (+856.75%)
Mutual labels:  typography

Build Status

Table of Contents

typogr.js

typogr.js provides a set of functions which automatically apply various transformations to plain text in order to yield typographically-improved HTML.

typogr.js is inspired by these awesome packages:

Installation

It's recommended to install via npm:

npm install -g typogr

Usage

typogr.js has no external dependencies and can be used both on the server and in the browser.

Simple on the server

// Only for server side
var typogr = require('typogr');

typogr.typogrify('<h1>"Pretty header ...</h1>');
'<h1><span class="dquo">&#8220;</span>Pretty header&nbsp;&#8230;</h1>'

Simple in the browser

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ekalinin/[email protected]/typogr.min.js"></script>
<script>
$(document).ready(function() {
    $('#res').html(typogr.typogrify($('#src')));
})
</script>

OOP-style

// Only for server side
var typogr = require('typogr');

typogr('<h1>"Pretty header ...</h1>').typogrify();
'<h1><span class="dquo">&#8220;</span>Pretty header&nbsp;&#8230;</h1>'

Chains

// Only for server side
var typogr = require('typogr');

typogr('<h1>"Pretty header ...</h1>').chain().initQuotes().value();
'<h1><span class="dquo">"</span>Pretty header ...</h1>'

typogr('<h1>"Pretty header ...</h1>').chain().initQuotes().smartypants().value();
'<h1><span class="dquo">&#8220;</span>Pretty header &#8230;</h1>'

API

amp

Wraps ampersands in HTML with <span class="amp"> so they can be styled with CSS. Ampersands are also normalized to &amp;. Requires ampersands to have whitespace or an &nbsp; on both sides. Will not change any ampersand which has already been wrapped in this fashion.

initQuotes

Wraps initial quotes in <span class="dquo"> for double quotes or <span class="quo"> for single quotes. Works inside these block elements:

  • h1, h2, h3, h4, h5, h6
  • p
  • li
  • dt
  • dd

Also accounts for potential opening inline elements: a, em, strong, span, b, i.

smartypants

  • Straight quotes ( " and ' '") into “curly” quote HTML entities (‘ | ’ | “ | ”)
  • Backticks-style quotes (``like this''') into “curly” quote HTML entities (‘ | ’ | “ | ”)
  • Dashes (“--” and “---”) into n-dash and m-dash entities (– | —)
  • Three consecutive dots (“...”) into an ellipsis entity (…)

widont

Based on Shaun Inman's PHP utility of the same name, replaces the space between the last two words in a string with &nbsp; to avoid a final line of text with only one word.

Works inside these block elements:

  • h1, h2, h3, h4, h5, h6
  • p
  • li
  • dt
  • dd

Also accounts for potential closing inline elements: a, em, strong, span, b, i.

caps

Wraps multiple capital letters in <span class="caps"></span> so they can be styled.

ord

Wraps number suffix's in <span class="ord"></span> so they can be styled.

typogrify

Applies all of the following filters, in order:

  • amp
  • widont
  • smartypants
  • caps
  • initQuotes
  • ord

CLI

A command line interface can be used to typogrify html files.

% typogr --help

  Usage: typogr [options] [input] [output]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
    -i, --inplace  Use single path as both input and output
    -f, --force    Do not prompt to verify file overwrites

  reads input from stdin, individual files, directories, or globs
  writes ouput to stdout, individual files, or directories

  Examples:

    $ typogr inputFile.html outputFile.html
    $ typogr < inputFile.html > outputFile.html
    $ typogr -i singleFile.html
    $ typogr inputDirectory outputDirectory
    $ typogr inputDirectory/*.html outputDirectory

License

See LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].