A small, educational Grunt plugin that tackles typographic orphans in HTML block elements
I created this Grunt plugin to accompany my tutorial on SitePoint (yet to be published). It implements a simple task that replaces the last space in block elements with a non-breakable space to avoid typographic orphans.
The image above appeared in the article 8 Simple Ways to Improve Typography In Your Designs by Antonio Carusone on Smashing Magazine.
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-typographic-adoption --save-dev
In your project's Gruntfile, add a section named
typographic_adoption to the data object passed into
['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'th', 'td', 'dt', 'dd', 'li']
An array of standard CSS selectors to control which elements get processed by the task.
This example would tackle typographic orphans in all block elements specified in the default value of
This example shows how you can overwrite the default value of
options.selectors with any array of standard CSS selectors to steer which elements get processed by this task.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.