Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

A small, educational Grunt plugin that tackles typographic orphans in HTML block elements

License

Notifications You must be signed in to change notification settings

stephanmax/grunt-typographic-adoption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-typographic-adoption

A small, educational Grunt plugin that tackles typographic orphans in HTML block elements

I created this Grunt plugin to accompany my tutorial Build and Publish Your Own Grunt Plugin on SitePoint. It implements a simple task that replaces the last space in block elements with a non-breakable space to avoid typographic orphans.

Typographic orphans and widows

The image above appeared in the article 8 Simple Ways to Improve Typography In Your Designs by Antonio Carusone on Smashing Magazine.

Getting Started

This plugin requires Grunt ~0.4.5

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

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-typographic-adoption');

The "typographic_adoption" task

Overview

In your project's Gruntfile, add a section named typographic_adoption to the data object passed into grunt.initConfig().

grunt.initConfig({
  typographic_adoption: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.selectors

Type: Array

Default value: ['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.

Usage Examples

Default Options

This example would tackle typographic orphans in all block elements specified in the default value of options.selectors.

grunt.initConfig({
  typographic_adoption: {
    options: {},
    files: {
      'dest/default_options': [ 'src/sourcefile' ],
    },
  },
});

Custom Options

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.

grunt.initConfig({
  typographic_adoption: {
    options: {
      selectors: ['p', '.quote', '#masthead-title']
    },
    files: {
      'dest/default_options': [ 'src/sourcefile' ],
    },
  },
});

Contributing

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.

Release History

  • 0.1.0

    First version

About

A small, educational Grunt plugin that tackles typographic orphans in HTML block elements

Resources

License

Stars

Watchers

Forks

Packages