From ec7684b95faedef8779d91d88b7ff56f85099bea Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 14 Mar 2015 23:47:34 -0700 Subject: [PATCH] Add Grunt example. --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++-- example/Gruntfile.js | 26 ++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 example/Gruntfile.js diff --git a/README.md b/README.md index f582efd7..59f08e6b 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ See [Rules.md](doc/Rules.md) for more details. Invoke `markdownlint` and use the `result` object's `toString` method: ```js -var markdownlint = require("../lib/markdownlint"); +var markdownlint = require("markdownlint"); var options = { "files": [ "good.md", "bad.md" ] @@ -113,7 +113,7 @@ Integration with the [gulp](http://gulpjs.com/) build system is straightforward: ```js var gulp = require("gulp"); var through2 = require("through2"); -var markdownlint = require("../lib/markdownlint"); +var markdownlint = require("markdownlint"); gulp.task("markdownlint", function task() { return gulp.src("*.md", { "read": false }) @@ -141,6 +141,46 @@ bad.md: 3: MD018 No space after hash on atx style header [00:00:00] Finished 'markdownlint' after 10 ms ``` +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); + }); + }); +}; +``` + +Outputs: + +```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. +``` + ## Release History * 0.0.1 - Initial release. diff --git a/example/Gruntfile.js b/example/Gruntfile.js new file mode 100644 index 00000000..916331c9 --- /dev/null +++ b/example/Gruntfile.js @@ -0,0 +1,26 @@ +"use strict"; + +var markdownlint = require("../lib/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); + }); + }); +}; diff --git a/package.json b/package.json index 49d9b1a5..b056d322 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test-cover": "istanbul cover node_modules/nodeunit/bin/nodeunit", "debug": "node debug node_modules/nodeunit/bin/nodeunit", "lint": "eslint lib test & eslint --rule \"no-console: 0\" example", - "example": "cd example & node standalone.js & gulp markdownlint" + "example": "cd example & node standalone.js & grunt markdownlint & gulp markdownlint" }, "dependencies": { "markdown-it": "^3.0.7"