Skip to content

Commit 4f90b65

Browse files
committedJul 19, 2018
Added Prettier and ESLint
1 parent 77d81e7 commit 4f90b65

11 files changed

+1221
-51
lines changed
 

‎.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

‎.eslintrc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
root: true
2+
3+
env:
4+
node: true
5+
es6: true
6+
7+
parserOptions:
8+
ecmaVersion: 2018
9+
sourceType: module
10+
ecmaFeatures:
11+
globalReturn: true
12+
impliedStrict: true
13+
14+
extends:
15+
- "eslint:recommended"
16+
- prettier
17+
18+
plugins:
19+
- prettier
20+
21+
rules:
22+
"prettier/prettier": error
23+
camelcase: 0
24+
no-console: 1
25+
quotes: [2, "single", "avoid-escape"]
26+
valid-jsdoc: [1, {requireParamDescription: false, requireReturnDescription: false}]

‎.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock.json
2+
package.json

‎.prettierrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
singleQuote: true
2+
printWidth: 120

‎History.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# 1.0.0 / 2018-07-17
1+
# Latest
2+
## 1.0.0 / 2018-07-17
23

34
* Fixed API
45
* Upgraded to Marked 0.4.0 #31
@@ -10,6 +11,8 @@
1011
* Docs: Usage with highlighting lib #6
1112
* Updated all packages
1213

14+
# Previous
15+
1316
## 0.2.2 / 2018-01-09
1417

1518
* update marked dependency to fix security issue

‎Makefile

-8
This file was deleted.

‎Readme.md

+41-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1+
[![npm version][npm-badge]][npm-url]
2+
[![code style: prettier][prettier-badge]][prettier-url]
3+
[![metalsmith: core plugin][metalsmith-badge]][metalsmith-url]
4+
5+
[![Known Vulnerabilities][snyk-badge]][synk-url]
16

27
# metalsmith-markdown
38

4-
A Metalsmith plugin to convert markdown files.
9+
A Metalsmith plugin to convert markdown files.
510

611
## Installation
712

8-
$ npm install metalsmith-markdown
13+
```bash
14+
$ npm install metalsmith-markdown
15+
```
916

1017
## CLI Usage
1118

12-
Install via npm and then add the `metalsmith-markdown` key to your `metalsmith.json` plugins with any [Marked](https://github.com/chjj/marked) options you want, like so:
19+
Install via npm and then add the `metalsmith-markdown` key to your `metalsmith.json` plugins with any [Marked](https://github.com/markedjs/marked) options you want, like so:
1320

1421
```json
1522
{
1623
"plugins": {
1724
"metalsmith-markdown": {
18-
"smartypants": true,
25+
"pedantic": false,
1926
"gfm": true,
20-
"tables": true
27+
"tables": true,
28+
"breaks": false,
29+
"sanitize": false,
30+
"smartLists": true,
31+
"smartypants": false,
32+
"xhtml": false
2133
}
2234
}
2335
}
@@ -32,13 +44,34 @@ var markdown = require('metalsmith-markdown');
3244
var highlighter = require('highlighter');
3345

3446
metalsmith.use(markdown({
35-
smartypants: true,
47+
renderer: new myMarked.Renderer(),
48+
highlight: function(code) {
49+
return require('highlight.js').highlightAuto(code).value;
50+
},
51+
pedantic: false,
3652
gfm: true,
3753
tables: true,
38-
highlight: highlighter()
54+
breaks: false,
55+
sanitize: false,
56+
smartLists: true,
57+
smartypants: false,
58+
xhtml: false
3959
}));
4060
```
4161

62+
## History
63+
64+
[History](./History.md#Latest)
65+
4266
## License
4367

44-
MIT
68+
MIT
69+
70+
[npm-badge]: https://img.shields.io/npm/v/metalsmith-markdown.svg
71+
[npm-url]: https://www.npmjs.com/package/metalsmith-markdown
72+
[prettier-badge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?longCache=true
73+
[prettier-url]: https://github.com/prettier/prettier
74+
[metalsmith-badge]: https://img.shields.io/badge/metalsmith-core_plugin-green.svg?longCache=true
75+
[metalsmith-url]: http://metalsmith.io
76+
[snyk-badge]: https://snyk.io/test/github/metalsmith/metalsmith-markdown/badge.svg
77+
[synk-url]: https://snyk.io/test/github/metalsmith/metalsmith-markdown

‎lib/index.js

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var basename = require('path').basename;
32
var debug = require('debug')('metalsmith-markdown');
43
var dirname = require('path').dirname;
@@ -7,10 +6,14 @@ var join = require('path').join;
76
var marked = require('marked');
87

98
/**
10-
* Expose `plugin`.
9+
* Check if a `file` is markdown.
10+
*
11+
* @param {String} file
12+
* @return {Boolean}
1113
*/
12-
13-
module.exports = plugin;
14+
var markdown = function(file) {
15+
return /\.md$|\.markdown$/.test(extname(file));
16+
};
1417

1518
/**
1619
* Metalsmith plugin to convert markdown files.
@@ -19,14 +22,13 @@ module.exports = plugin;
1922
* @property {Array} keys
2023
* @return {Function}
2124
*/
22-
23-
function plugin(options){
25+
var plugin = function(options) {
2426
options = options || {};
2527
var keys = options.keys || [];
2628

27-
return function(files, metalsmith, done){
29+
return function(files, metalsmith, done) {
2830
setImmediate(done);
29-
Object.keys(files).forEach(function(file){
31+
Object.keys(files).forEach(function(file) {
3032
debug('checking file: %s', file);
3133
if (!markdown(file)) return;
3234
var data = files[file];
@@ -41,7 +43,7 @@ function plugin(options){
4143
data.contents = Buffer.from(str);
4244
} catch (err) {
4345
// node versions < (5.10 | 6)
44-
data.contents = new Buffer(str);
46+
data.contents = new Buffer(str);
4547
}
4648
keys.forEach(function(key) {
4749
if (data[key]) {
@@ -53,15 +55,7 @@ function plugin(options){
5355
files[html] = data;
5456
});
5557
};
56-
}
58+
};
5759

58-
/**
59-
* Check if a `file` is markdown.
60-
*
61-
* @param {String} file
62-
* @return {Boolean}
63-
*/
64-
65-
function markdown(file){
66-
return /\.md$|\.markdown$/.test(extname(file));
67-
}
60+
// Expose Plugin
61+
module.exports = plugin;

‎package-lock.json

+1,096
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"license": "MIT",
77
"main": "lib/index.js",
88
"scripts": {
9+
"pretest": "eslint --fix .",
910
"test": "mocha test"
1011
},
1112
"dependencies": {
@@ -14,7 +15,11 @@
1415
},
1516
"devDependencies": {
1617
"assert-dir-equal": "^1.1.0",
18+
"eslint": "^5.1.0",
19+
"eslint-config-prettier": "^2.9.0",
20+
"eslint-plugin-prettier": "^2.6.2",
1721
"metalsmith": "^2.3.0",
18-
"mocha": "^5.2.0"
22+
"mocha": "^5.2.0",
23+
"prettier": "^1.13.7"
1924
}
2025
}

‎test/index.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1+
/* eslint-env mocha */
12

23
var assert = require('assert');
34
var equal = require('assert-dir-equal');
45
var Metalsmith = require('metalsmith');
56
var markdown = require('..');
67

7-
describe('metalsmith-markdown', function(){
8-
it('should convert markdown files', function(done){
8+
describe('metalsmith-markdown', function() {
9+
it('should convert markdown files', function(done) {
910
Metalsmith('test/fixtures/basic')
10-
.use(markdown({
11-
smartypants: true
12-
}))
13-
.build(function(err){
11+
.use(
12+
markdown({
13+
smartypants: true
14+
})
15+
)
16+
.build(function(err) {
1417
if (err) return done(err);
1518
equal('test/fixtures/basic/expected', 'test/fixtures/basic/build');
1619
done();
1720
});
1821
});
1922

20-
it('should allow a "keys" option', function(done){
23+
it('should allow a "keys" option', function(done) {
2124
Metalsmith('test/fixtures/keys')
22-
.use(markdown({
23-
keys: ['custom'],
24-
smartypants: true
25-
}))
26-
.build(function(err, files){
25+
.use(
26+
markdown({
27+
keys: ['custom'],
28+
smartypants: true
29+
})
30+
)
31+
.build(function(err, files) {
2732
if (err) return done(err);
2833
assert.equal('<p><em>a</em></p>\n', files['index.html'].custom);
2934
done();
3035
});
3136
});
32-
});
37+
});

0 commit comments

Comments
 (0)
Please sign in to comment.