2015-03-12 23:42:06 -07:00
|
|
|
# markdownlint
|
|
|
|
|
2015-03-14 22:34:28 -07:00
|
|
|
> A Node.js style checker and lint tool for Markdown files.
|
2015-03-12 23:42:06 -07:00
|
|
|
|
2015-03-17 22:58:26 -07:00
|
|
|
[![npm version][npm-image]][npm-url]
|
|
|
|
[![GitHub tag][github-tag-image]][github-tag-url]
|
|
|
|
[![Build status][travis-image]][travis-url]
|
|
|
|
[![Coverage][coveralls-image]][coveralls-url]
|
|
|
|
[![License][license-image]][license-url]
|
|
|
|
|
2015-03-12 23:42:06 -07:00
|
|
|
## Install
|
|
|
|
|
|
|
|
```shell
|
|
|
|
npm install markdownlint --save-dev
|
|
|
|
```
|
|
|
|
|
|
|
|
## Overview
|
|
|
|
|
|
|
|
The [Markdown](http://en.wikipedia.org/wiki/Markdown) markup language is
|
2015-03-14 22:34:28 -07:00
|
|
|
designed to be easy to read, write, and understand. It succeeds - and its
|
|
|
|
flexibility is both a benefit and a drawback. Many styles are possible, so
|
|
|
|
formatting can be inconsistent. Some constructs don't work well in all
|
|
|
|
parsers and should be avoided.
|
2015-03-12 23:42:06 -07:00
|
|
|
|
|
|
|
`markdownlint` is a [static analysis](http://en.wikipedia.org/wiki/Static_program_analysis)
|
|
|
|
tool for [Node.js](https://nodejs.org/) and [io.js](https://iojs.org/) with a
|
2015-03-14 22:34:28 -07:00
|
|
|
library of rules to enforce standards and consistency for Markdown files. It
|
|
|
|
was inspired by - and heavily influenced by - Mark Harrison's
|
|
|
|
[markdownlint](https://github.com/mivok/markdownlint) for
|
|
|
|
[Ruby](https://www.ruby-lang.org/). The rules, rule documentation, and test
|
|
|
|
cases come directly from that project.
|
2015-03-12 23:42:06 -07:00
|
|
|
|
2015-03-14 22:34:28 -07:00
|
|
|
> If you need a Ruby implementation or a [CLI](http://en.wikipedia.org/wiki/Command-line_interface),
|
|
|
|
> please consider the [mdl](https://rubygems.org/gems/mdl) gem.
|
2015-03-12 23:42:06 -07:00
|
|
|
|
|
|
|
## Rules
|
|
|
|
|
2015-03-16 22:31:18 -07:00
|
|
|
* **MD001** - Header levels should only increment by one level at a time
|
|
|
|
* **MD002** - First header should be a h1 header
|
|
|
|
* **MD003** - Header style
|
|
|
|
* **MD004** - Unordered list style
|
|
|
|
* **MD005** - Inconsistent indentation for list items at the same level
|
|
|
|
* **MD006** - Consider starting bulleted lists at the beginning of the line
|
|
|
|
* **MD007** - Unordered list indentation
|
|
|
|
* **MD009** - Trailing spaces
|
|
|
|
* **MD010** - Hard tabs
|
|
|
|
* **MD011** - Reversed link syntax
|
|
|
|
* **MD012** - Multiple consecutive blank lines
|
|
|
|
* **MD013** - Line length
|
|
|
|
* **MD014** - Dollar signs used before commands without showing output
|
|
|
|
* **MD018** - No space after hash on atx style header
|
|
|
|
* **MD019** - Multiple spaces after hash on atx style header
|
|
|
|
* **MD020** - No space inside hashes on closed atx style header
|
|
|
|
* **MD021** - Multiple spaces inside hashes on closed atx style header
|
|
|
|
* **MD022** - Headers should be surrounded by blank lines
|
|
|
|
* **MD023** - Headers must start at the beginning of the line
|
|
|
|
* **MD024** - Multiple headers with the same content
|
|
|
|
* **MD025** - Multiple top level headers in the same document
|
|
|
|
* **MD026** - Trailing punctuation in header
|
|
|
|
* **MD027** - Multiple spaces after blockquote symbol
|
|
|
|
* **MD028** - Blank line inside blockquote
|
|
|
|
* **MD029** - Ordered list item prefix
|
|
|
|
* **MD030** - Spaces after list markers
|
|
|
|
* **MD031** - Fenced code blocks should be surrounded by blank lines
|
|
|
|
* **MD032** - Lists should be surrounded by blank lines
|
2015-04-13 08:47:15 -07:00
|
|
|
* **MD033** - Inline HTML
|
2015-04-14 00:01:57 -07:00
|
|
|
* **MD034** - Bare URL used
|
2015-04-14 09:40:16 -07:00
|
|
|
* **MD035** - Horizontal rule style
|
2015-04-14 22:37:56 -07:00
|
|
|
* **MD036** - Emphasis used instead of a header
|
2015-04-15 17:50:01 -07:00
|
|
|
* **MD037** - Spaces inside emphasis markers
|
2015-04-15 18:24:42 -07:00
|
|
|
* **MD038** - Spaces inside code span elements
|
|
|
|
* **MD039** - Spaces inside link text
|
2015-04-16 09:13:56 -07:00
|
|
|
* **MD040** - Fenced code blocks should have a language specified
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
See [Rules.md](doc/Rules.md) for more details.
|
2015-03-12 23:42:06 -07:00
|
|
|
|
2015-03-16 22:31:18 -07:00
|
|
|
## Tags
|
|
|
|
|
|
|
|
* **atx** - MD018, MD019
|
|
|
|
* **atx_closed** - MD020, MD021
|
|
|
|
* **blank_lines** - MD012, MD022, MD031, MD032
|
|
|
|
* **blockquote** - MD027, MD028
|
|
|
|
* **bullet** - MD004, MD005, MD006, MD007, MD032
|
2015-04-16 09:13:56 -07:00
|
|
|
* **code** - MD014, MD031, MD038, MD040
|
2015-04-15 17:50:01 -07:00
|
|
|
* **emphasis** - MD036, MD037
|
2015-03-17 22:34:47 -07:00
|
|
|
* **hard_tab** - MD010
|
2015-03-16 22:31:18 -07:00
|
|
|
* **headers** - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023,
|
2015-04-14 22:37:56 -07:00
|
|
|
MD024, MD025, MD026, MD036
|
2015-04-14 09:40:16 -07:00
|
|
|
* **hr** - MD035
|
2015-04-14 00:01:57 -07:00
|
|
|
* **html** - MD033
|
2015-03-16 22:31:18 -07:00
|
|
|
* **indentation** - MD005, MD006, MD007, MD027
|
2015-04-16 09:13:56 -07:00
|
|
|
* **language** - MD040
|
2015-03-16 22:31:18 -07:00
|
|
|
* **line_length** - MD013
|
2015-04-15 18:24:42 -07:00
|
|
|
* **links** - MD011, MD034, MD039
|
2015-03-16 22:31:18 -07:00
|
|
|
* **ol** - MD029, MD030, MD032
|
|
|
|
* **spaces** - MD018, MD019, MD020, MD021, MD023
|
|
|
|
* **ul** - MD004, MD005, MD006, MD007, MD030, MD032
|
2015-04-14 00:01:57 -07:00
|
|
|
* **url** - MD034
|
2015-04-15 18:24:42 -07:00
|
|
|
* **whitespace** - MD009, MD010, MD012, MD027, MD028, MD030, MD037, MD038, MD039
|
2015-03-16 22:31:18 -07:00
|
|
|
|
2015-03-15 23:39:17 -07:00
|
|
|
## API
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Standard asynchronous interface:
|
|
|
|
|
2015-03-15 23:39:17 -07:00
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* Lint specified Markdown files according to configurable rules.
|
|
|
|
*
|
|
|
|
* @param {Object} options Configuration options.
|
|
|
|
* @param {Function} callback Callback (err, result) function.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function markdownlint(options, callback) { ... }
|
|
|
|
```
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Synchronous interface (for build scripts, etc.):
|
|
|
|
|
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* Lint specified Markdown files according to configurable rules.
|
|
|
|
*
|
|
|
|
* @param {Object} options Configuration options.
|
|
|
|
* @returns {Object} Result object.
|
|
|
|
*/
|
|
|
|
function markdownlint.sync(options) { ... }
|
|
|
|
```
|
|
|
|
|
2015-03-15 23:39:17 -07:00
|
|
|
### options
|
|
|
|
|
|
|
|
Type: `Object`
|
|
|
|
|
|
|
|
Configures the function.
|
|
|
|
|
|
|
|
#### options.files
|
|
|
|
|
|
|
|
Type: `Array` of `String`
|
|
|
|
|
|
|
|
List of files to lint.
|
|
|
|
|
|
|
|
Each array element should be a single file (via relative or absolute path);
|
|
|
|
[globbing](http://en.wikipedia.org/wiki/Glob_%28programming%29) is the caller's
|
|
|
|
responsibility.
|
|
|
|
|
|
|
|
Example: `[ "one.md", "dir/two.md" ]`
|
|
|
|
|
2015-04-29 18:46:52 -07:00
|
|
|
#### options.strings
|
|
|
|
|
|
|
|
Type: `Object` mapping `String` to `String`
|
|
|
|
|
|
|
|
Map of identifiers to strings for linting.
|
|
|
|
|
|
|
|
When Markdown content is not available as files, it can be passed as strings.
|
|
|
|
The keys of the `strings` object are used to identify each input value in the
|
|
|
|
`result` summary.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"readme": "# README\n...",
|
|
|
|
"changelog": "# CHANGELOG\n..."
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-03-15 23:39:17 -07:00
|
|
|
#### options.config
|
|
|
|
|
2015-03-16 22:31:18 -07:00
|
|
|
Type: `Object` mapping `String` to `Boolean | Object`
|
2015-03-15 23:39:17 -07:00
|
|
|
|
|
|
|
Configures the rules to use.
|
|
|
|
|
|
|
|
Object keys are rule names and values are the rule's configuration.
|
|
|
|
The value `false` disables a rule, `true` enables its default configuration,
|
|
|
|
and passing an object customizes its settings. Setting the special `default`
|
2015-03-18 09:38:32 -07:00
|
|
|
rule to `true` or `false` includes/excludes all rules by default. Enabling or
|
|
|
|
disabling a tag name (ex: `whitespace`) affects all rules having that tag.
|
|
|
|
|
|
|
|
The `default` rule is applied first, then keys are processed in order from top
|
|
|
|
to bottom with later values overriding earlier ones.
|
2015-03-15 23:39:17 -07:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"default": true,
|
2015-03-18 09:38:32 -07:00
|
|
|
"MD003": { "style": "atx_closed" },
|
|
|
|
"MD007": { "indent": 4 },
|
2015-03-18 09:40:01 -07:00
|
|
|
"MD009": false,
|
|
|
|
"whitespace": false
|
2015-03-15 23:39:17 -07:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-03-18 09:38:32 -07:00
|
|
|
Sets of rules (known as a "style") can be stored separately and loaded as
|
|
|
|
[JSON](http://en.wikipedia.org/wiki/JSON).
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```js
|
|
|
|
var options = {
|
|
|
|
"files": [ "..." ],
|
|
|
|
"config": require("style/relaxed.json")
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
See the [style](style) directory for more samples.
|
|
|
|
|
2015-03-15 23:39:17 -07:00
|
|
|
### callback
|
|
|
|
|
|
|
|
Type: `Function` taking (`Error`, `Object`)
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Standard completion callback.
|
|
|
|
|
|
|
|
### result
|
|
|
|
|
|
|
|
Type: `Object`
|
2015-03-15 23:39:17 -07:00
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Call `result.toString()` for convenience or see below for an example of the
|
|
|
|
structure of the `result` object.
|
2015-03-15 23:39:17 -07:00
|
|
|
|
2015-03-12 23:42:06 -07:00
|
|
|
## Usage
|
|
|
|
|
2015-03-14 22:34:28 -07:00
|
|
|
Invoke `markdownlint` and use the `result` object's `toString` method:
|
2015-03-12 23:42:06 -07:00
|
|
|
|
|
|
|
```js
|
2015-03-14 23:47:34 -07:00
|
|
|
var markdownlint = require("markdownlint");
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
var options = {
|
2015-04-29 18:46:52 -07:00
|
|
|
"files": [ "good.md", "bad.md" ],
|
|
|
|
"strings": {
|
|
|
|
"good.string": "# good.string\n\nThis string passes all rules.",
|
|
|
|
"bad.string": "#bad.string\n\n#This string fails\tsome rules."
|
|
|
|
}
|
2015-03-14 22:34:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
markdownlint(options, function callback(err, result) {
|
|
|
|
if (!err) {
|
|
|
|
console.log(result.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Or invoke `markdownlint.sync` for a synchronous call:
|
|
|
|
|
|
|
|
```js
|
|
|
|
var result = markdownlint.sync(options);
|
|
|
|
console.log(result.toString());
|
|
|
|
```
|
|
|
|
|
|
|
|
Output of both calls:
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
```text
|
2015-04-29 18:46:52 -07:00
|
|
|
bad.string: 3: MD010 Hard tabs
|
|
|
|
bad.string: 1: MD018 No space after hash on atx style header
|
|
|
|
bad.string: 3: MD018 No space after hash on atx style header
|
2015-03-14 22:34:28 -07:00
|
|
|
bad.md: 3: MD010 Hard tabs
|
|
|
|
bad.md: 1: MD018 No space after hash on atx style header
|
|
|
|
bad.md: 3: MD018 No space after hash on atx style header
|
|
|
|
```
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
To examine the `result` object directly:
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
markdownlint(options, function callback(err, result) {
|
|
|
|
if (!err) {
|
|
|
|
console.dir(result, { "colors": true });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Output:
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2015-04-29 18:46:52 -07:00
|
|
|
"good.string": {},
|
|
|
|
"bad.string": {
|
|
|
|
"MD010": [ 3 ],
|
|
|
|
"MD018": [ 1, 3 ]
|
|
|
|
},
|
2015-03-16 22:31:18 -07:00
|
|
|
"good.md": {},
|
|
|
|
"bad.md": {
|
|
|
|
"MD010": [ 3 ],
|
|
|
|
"MD018": [ 1, 3 ]
|
2015-03-14 22:34:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Integration with the [gulp](http://gulpjs.com/) build system is straightforward:
|
|
|
|
|
|
|
|
```js
|
|
|
|
var gulp = require("gulp");
|
|
|
|
var through2 = require("through2");
|
2015-03-14 23:47:34 -07:00
|
|
|
var markdownlint = require("markdownlint");
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
gulp.task("markdownlint", function task() {
|
|
|
|
return gulp.src("*.md", { "read": false })
|
|
|
|
.pipe(through2.obj(function obj(file, enc, next) {
|
|
|
|
markdownlint(
|
|
|
|
{ "files": [ file.relative ] },
|
|
|
|
function callback(err, result) {
|
|
|
|
var resultString = (result || "").toString();
|
|
|
|
if (resultString) {
|
|
|
|
console.log(resultString);
|
|
|
|
}
|
|
|
|
next(err, file);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Output:
|
2015-03-14 22:34:28 -07:00
|
|
|
|
|
|
|
```text
|
|
|
|
[00:00:00] Starting 'markdownlint'...
|
|
|
|
bad.md: 3: MD010 Hard tabs
|
|
|
|
bad.md: 1: MD018 No space after hash on atx style header
|
|
|
|
bad.md: 3: MD018 No space after hash on atx style header
|
|
|
|
[00:00:00] Finished 'markdownlint' after 10 ms
|
2015-03-12 23:42:06 -07:00
|
|
|
```
|
|
|
|
|
2015-03-14 23:47:34 -07:00
|
|
|
Integration with the [Grunt](http://gruntjs.com/) build system is similar:
|
|
|
|
|
|
|
|
```js
|
|
|
|
var markdownlint = require("markdownlint");
|
|
|
|
|
|
|
|
module.exports = function wrapper(grunt) {
|
|
|
|
grunt.initConfig({
|
|
|
|
"markdownlint": {
|
|
|
|
"example": {
|
|
|
|
"src": [ "*.md" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.registerMultiTask("markdownlint", function task() {
|
|
|
|
var done = this.async();
|
|
|
|
markdownlint(
|
|
|
|
{ "files": this.filesSrc },
|
|
|
|
function callback(err, result) {
|
|
|
|
var resultString = err || ((result || "").toString());
|
|
|
|
if (resultString) {
|
|
|
|
grunt.fail.warn("\n" + resultString + "\n");
|
|
|
|
}
|
|
|
|
done(!err || !resultString);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
Output:
|
2015-03-14 23:47:34 -07:00
|
|
|
|
|
|
|
```text
|
|
|
|
Running "markdownlint:example" (markdownlint) task
|
|
|
|
Warning:
|
|
|
|
bad.md: 3: MD010 Hard tabs
|
|
|
|
bad.md: 1: MD018 No space after hash on atx style header
|
|
|
|
bad.md: 3: MD018 No space after hash on atx style header
|
|
|
|
Use --force to continue.
|
|
|
|
```
|
|
|
|
|
2015-04-17 21:57:10 -07:00
|
|
|
## History
|
2015-03-12 23:42:06 -07:00
|
|
|
|
2015-04-17 22:04:45 -07:00
|
|
|
* 0.0.1 - Initial release, includes tests MD001-MD032.
|
2015-03-17 23:05:37 -07:00
|
|
|
* 0.0.2 - Improve documentation, tests, and code.
|
2015-03-20 00:29:36 -07:00
|
|
|
* 0.0.3 - Add synchronous API, improve documentation and code.
|
2015-04-17 22:04:45 -07:00
|
|
|
* 0.0.4 - Add tests MD033-MD040, update dependencies.
|
2015-04-29 18:46:52 -07:00
|
|
|
* *PENDING* - Add `strings` option to enable file-less scenarios.
|
2015-03-17 22:58:26 -07:00
|
|
|
|
|
|
|
[npm-image]: https://img.shields.io/npm/v/markdownlint.svg
|
|
|
|
[npm-url]: https://www.npmjs.com/package/markdownlint
|
|
|
|
[github-tag-image]: https://img.shields.io/github/tag/DavidAnson/markdownlint.svg
|
|
|
|
[github-tag-url]: https://github.com/DavidAnson/markdownlint
|
|
|
|
[travis-image]: https://img.shields.io/travis/DavidAnson/markdownlint.svg
|
|
|
|
[travis-url]: https://travis-ci.org/DavidAnson/markdownlint
|
|
|
|
[coveralls-image]: https://img.shields.io/coveralls/DavidAnson/markdownlint.svg
|
|
|
|
[coveralls-url]: https://coveralls.io/r/DavidAnson/markdownlint
|
|
|
|
[license-image]: https://img.shields.io/npm/l/markdownlint.svg
|
|
|
|
[license-url]: http://opensource.org/licenses/MIT
|