Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-eb committed Sep 1, 2015
0 parents commit 00c8ee5
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
npm-debug.log
tmp
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 'iojs'
- '0.12'
22 changes: 22 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) Ben Briggs <[email protected]> (http://beneb.info)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# [metalsmith][metalsmith]-mdast [![Build Status](https://travis-ci.org/ben-eb/metalsmith-mdast.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/metalsmith-mdast.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/metalsmith-mdast.svg)][deps]

> Convert markdown to html with mdast.
*If you have any issues with the output of this plugin, please use the
[mdast tracker](https://github.com/wooorm/mdast/issues).*

## Install

With [npm](https://npmjs.org/package/metalsmith-mdast) do:

```
npm install metalsmith-mdast --save
```

## Example

The [mdast-html][mdasthtml] plugin is bundled for you automatically:

```js
var mdast = require('metalsmith-mdast'),
Metalsmith = require('metalsmith');

Metalsmith('fixtures')
.use(mdast())
.build(function (err) {
if (err) {
throw err;
}
});
```

Add further plugins by passing an array:

```js
var rmBadges = require('mdast-strip-badges'),
rmParas = require('mdast-squeeze-paragraphs');

Metalsmith('fixtures')
.use(mdast([ rmBadges, rmParas ]))
.build(function (err) {
if (err) {
throw err;
}
});
```

## Contributing

Pull requests are welcome. If you add functionality, then please add unit
tests to cover it.

## License

MIT © [Ben Briggs](http://beneb.info)

[ci]: https://travis-ci.org/ben-eb/metalsmith-mdast
[deps]: https://gemnasium.com/ben-eb/metalsmith-mdast
[mdasthtml]: https://github.com/wooorm/mdast-html
[metalsmith]: https://github.com/segmentio/metalsmith
[npm]: http://badge.fury.io/js/metalsmith-mdast
1 change: 1 addition & 0 deletions fixtures/build/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello, world!</h1>
1 change: 1 addition & 0 deletions fixtures/expected/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello, world!</h1>
3 changes: 3 additions & 0 deletions fixtures/src/hello.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hello, world!

![build](https://img.shields.io/travis/ben-eb/cssnano.svg)
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var mdast = require('mdast'),
html = require('mdast-html'),
extname = require('path').extname;

function plugin (plugins) {
return function (files, metalsmith) {
Object.keys(files).map(function (file) {
var extension = extname(file);
if (extension !== '.md' && extension !== '.markdown') {
return true;
}
var markdown = String(files[file].contents);
var result = mdast.use(plugins).use(html).process(markdown);
files[file].contents = new Buffer(result);
var data = files[file];
delete files[file];
files[file.replace(extension, '.html')] = data;
});
}
}

/**
* Expose `plugin`.
*/

module.exports = plugin;
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "metalsmith-mdast",
"version": "0.0.0",
"description": "Convert markdown to html with mdast",
"license": "MIT",
"homepage": "https://github.com/ben-eb/metalsmith-mdast",
"author": {
"name": "Ben Briggs",
"email": "[email protected]",
"url": "http://beneb.info"
},
"files": [
"LICENSE-MIT",
"index.js"
],
"main": "index.js",
"dependencies": {
"mdast": "^1.1.0",
"mdast-html": "^1.0.0"
},
"devDependencies": {
"assert-dir-equal": "^1.0.1",
"mdast-squeeze-paragraphs": "^1.1.0",
"mdast-strip-badges": "^1.0.0",
"metalsmith": "^1.0.1",
"tap-spec": "^4.1.0",
"tape": "^4.2.0"
},
"keywords": [
"markdown",
"mdast",
"metalsmith"
],
"scripts": {
"test": "tape test.js | tap-spec"
},
"repository": "ben-eb/metalsmith-mdast"
}
21 changes: 21 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

var test = require('tape'),
equal = require('assert-dir-equal'),
mdast = require('./'),
rmBadges = require('mdast-strip-badges'),
rmParas = require('mdast-squeeze-paragraphs'),
Metalsmith = require('metalsmith');

test('should convert svg files', function (t) {
t.plan(2);

Metalsmith('fixtures')
.use(mdast([ rmBadges, rmParas ]))
.build(function (err) {
t.notOk(err, 'should not error');
t.doesNotThrow(function () {
equal('fixtures/build', 'fixtures/expected');
});
});
});

0 comments on commit 00c8ee5

Please sign in to comment.