Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: metalsmith/markdown
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf34d5a657a7503dcbdb980a3ebf8c7f6d9f90d4
Choose a base ref
...
head repository: metalsmith/markdown
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64dce322cf471715d5007faf566c245fcdac9ec5
Choose a head ref

Commits on Dec 17, 2014

  1. Copy the full SHA
    77dd49d View commit details

Commits on Jan 21, 2015

  1. made key markdown replacement more robust

    Stefan Henze committed Jan 21, 2015
    Copy the full SHA
    5c746c3 View commit details

Commits on Jan 30, 2015

  1. Match of extension name of the markdown files with precise regex.

    The current code also considers files like `foo.md~` valid markdown files. The patch prevents accidental matches of these files.
    haohui committed Jan 30, 2015
    Copy the full SHA
    2e049f1 View commit details

Commits on Nov 8, 2015

  1. Replace backslash with slash in directory path.

    On Windows the directory path can include backslash (\) and thats what
    path.dirname returns. The file path is then added with a slash (/).
    
    This will result in paths like "services\marketing/email.html"
    
    This commit replace backslash with slash in the directory path when its
    concatenated with the filename.
    martinvehmas committed Nov 8, 2015
    Copy the full SHA
    2ad15cc View commit details

Commits on Nov 9, 2015

  1. Join the path as a file path with path.join

    The path is not a url so the hard coded separator / should not be used.
    
    Its still file paths even if its .html files.
    
    path.join is used to join the dir and the file.
    martinvehmas committed Nov 9, 2015
    Copy the full SHA
    491edbb View commit details

Commits on May 16, 2017

  1. key to string to string before converting

    sometimes other keys will be buffers
    datesss committed May 16, 2017
    Copy the full SHA
    b7eddfa View commit details

Commits on May 27, 2018

  1. Copy the full SHA
    fa09481 View commit details

Commits on May 28, 2018

  1. Copy the full SHA
    1f14938 View commit details

Commits on Jun 4, 2018

  1. Copy the full SHA
    dcfde68 View commit details

Commits on Jul 17, 2018

  1. Merge pull request #32 from ilyaigpetrov/master

    Upgrade marked to 0.4.0, #31
    woodyrew authored Jul 17, 2018
    Copy the full SHA
    baacb43 View commit details
  2. Merge pull request #6 from blakeembrey/patch-1

    Show usage with syntax highlighting
    woodyrew authored Jul 17, 2018
    Copy the full SHA
    245dbb3 View commit details
  3. Merge pull request #30 from Zearin/fix/Buffer

    Fix #29: Use `Buffer.from` wherever supported
    woodyrew authored Jul 17, 2018
    Copy the full SHA
    a67fed1 View commit details
  4. Merge pull request #16 from martinvehmas/master

    Use the right separator in file path.
    woodyrew authored Jul 17, 2018
    Copy the full SHA
    7c40a6a View commit details
  5. Merge pull request #24 from datesss/master

    key to string to string before converting
    woodyrew authored Jul 17, 2018
    Copy the full SHA
    7bd82f9 View commit details
  6. Copy the full SHA
    e960bfd View commit details
  7. Copy the full SHA
    2685861 View commit details
  8. Merge pull request #10 from haohui/haohui-precise-match-extname

    Match of extension name of the markdown files with precise regex.
    woodyrew authored Jul 17, 2018
    Copy the full SHA
    c232a98 View commit details
  9. Packages Updated

    woodyrew committed Jul 17, 2018
    Copy the full SHA
    2a0c309 View commit details
  10. History file: updated

    woodyrew committed Jul 17, 2018
    Copy the full SHA
    8136dea View commit details
  11. 1.0.0

    woodyrew committed Jul 17, 2018
    Copy the full SHA
    77d81e7 View commit details

Commits on Jul 19, 2018

  1. Added Prettier and ESLint

    woodyrew committed Jul 19, 2018
    Copy the full SHA
    4f90b65 View commit details
  2. Updated badge

    woodyrew committed Jul 19, 2018
    Copy the full SHA
    fdb9b16 View commit details
  3. relocated badges

    woodyrew committed Jul 19, 2018
    Copy the full SHA
    6189068 View commit details

Commits on Sep 14, 2018

  1. Package - Debug: upgraded

    woodyrew committed Sep 14, 2018
    Copy the full SHA
    902f1f8 View commit details
  2. Copy the full SHA
    9303875 View commit details
  3. 1.0.1

    woodyrew committed Sep 14, 2018
    Copy the full SHA
    64dce32 View commit details
Showing with 1,851 additions and 68 deletions.
  1. +12 −0 .editorconfig
  2. +26 −0 .eslintrc
  3. +2 −0 .prettierignore
  4. +2 −0 .prettierrc
  5. +22 −9 History.md
  6. +0 −8 Makefile
  7. +44 −9 Readme.md
  8. +25 −22 lib/index.js
  9. +1,686 −0 package-lock.json
  10. +14 −7 package.json
  11. +18 −13 test/index.js
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root: true

env:
node: true
es6: true

parserOptions:
ecmaVersion: 2018
sourceType: module
ecmaFeatures:
globalReturn: true
impliedStrict: true

extends:
- "eslint:recommended"
- prettier

plugins:
- prettier

rules:
"prettier/prettier": error
camelcase: 0
no-console: 1
quotes: [2, "single", "avoid-escape"]
valid-jsdoc: [1, {requireParamDescription: false, requireReturnDescription: false}]
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package-lock.json
package.json
2 changes: 2 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
singleQuote: true
printWidth: 120
31 changes: 22 additions & 9 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
# Latest
## 1.0.0 / 2018-07-17

0.2.2 / 2018-01-09
==================
* Fixed API
* Upgraded to Marked 0.4.0 #31
* Fixed security issue with Buffer #29
* Ensure key is string #24
* Cross platform path separators (Windows) #16
* Strict file endings #10
* Allow missing keys #9
* Docs: Usage with highlighting lib #6
* Updated all packages

# Previous

## 0.2.2 / 2018-01-09

* update marked dependency to fix security issue

0.2.1 - February 6, 2013
------------------------
## 0.2.1 - February 6, 2013

* add debug statements

0.2.0 - February 5, 2013
------------------------
## 0.2.0 - February 5, 2013

* update to use buffers for metalsmith 0.1.0

0.1.0 - February 5, 2013
------------------------
## 0.1.0 - February 5, 2013

* add `keys` option

0.0.1 - February 4, 2013
## 0.0.1 - February 4, 2013
------------------------
:sparkles:
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

53 changes: 44 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@

# metalsmith-markdown

A Metalsmith plugin to convert markdown files.
[![npm version][npm-badge]][npm-url]
[![code style: prettier][prettier-badge]][prettier-url]
[![metalsmith: core plugin][metalsmith-badge]][metalsmith-url]

[![Known Vulnerabilities][snyk-badge]][synk-url]

A Metalsmith plugin to convert markdown files.

## Installation

$ npm install metalsmith-markdown
```bash
$ npm install metalsmith-markdown
```

## CLI Usage

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:
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:

```json
{
"plugins": {
"metalsmith-markdown": {
"smartypants": true,
"pedantic": false,
"gfm": true,
"tables": true
"tables": true,
"breaks": false,
"sanitize": false,
"smartLists": true,
"smartypants": false,
"xhtml": false
}
}
}
@@ -29,14 +41,37 @@

```js
var markdown = require('metalsmith-markdown');
var highlighter = require('highlighter');

metalsmith.use(markdown({
smartypants: true,
renderer: new myMarked.Renderer(),
highlight: function(code) {
return require('highlight.js').highlightAuto(code).value;
},
pedantic: false,
gfm: true,
tables: true
tables: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
}));
```

## History

[History](./History.md#Latest)

## License

MIT
MIT

[npm-badge]: https://img.shields.io/npm/v/metalsmith-markdown.svg
[npm-url]: https://www.npmjs.com/package/metalsmith-markdown
[prettier-badge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?longCache=true
[prettier-url]: https://github.com/prettier/prettier
[metalsmith-badge]: https://img.shields.io/badge/metalsmith-core_plugin-green.svg?longCache=true
[metalsmith-url]: http://metalsmith.io
[snyk-badge]: https://snyk.io/test/github/segmentio/metalsmith-markdown/badge.svg?targetFile=package.json
[synk-url]: https://snyk.io/test/github/segmentio/metalsmith-markdown?targetFile=package.json
47 changes: 25 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

var basename = require('path').basename;
var debug = require('debug')('metalsmith-markdown');
var dirname = require('path').dirname;
var extname = require('path').extname;
var join = require('path').join;
var marked = require('marked');

/**
* Expose `plugin`.
* Check if a `file` is markdown.
*
* @param {String} file
* @return {Boolean}
*/

module.exports = plugin;
var markdown = function(file) {
return /\.md$|\.markdown$/.test(extname(file));
};

/**
* Metalsmith plugin to convert markdown files.
@@ -18,41 +22,40 @@ module.exports = plugin;
* @property {Array} keys
* @return {Function}
*/

function plugin(options){
var plugin = function(options) {
options = options || {};
var keys = options.keys || [];

return function(files, metalsmith, done){
return function(files, metalsmith, done) {
setImmediate(done);
Object.keys(files).forEach(function(file){
Object.keys(files).forEach(function(file) {
debug('checking file: %s', file);
if (!markdown(file)) return;
var data = files[file];
var dir = dirname(file);
var html = basename(file, extname(file)) + '.html';
if ('.' != dir) html = dir + '/' + html;
if ('.' != dir) html = join(dir, html);

debug('converting file: %s', file);
var str = marked(data.contents.toString(), options);
data.contents = new Buffer(str);
try {
// preferred
data.contents = Buffer.from(str);
} catch (err) {
// node versions < (5.10 | 6)
data.contents = new Buffer(str);
}
keys.forEach(function(key) {
data[key] = marked(data[key], options);
if (data[key]) {
data[key] = marked(data[key].toString(), options);
}
});

delete files[file];
files[html] = data;
});
};
}
};

/**
* Check if a `file` is markdown.
*
* @param {String} file
* @return {Boolean}
*/

function markdown(file){
return /\.md|\.markdown/.test(extname(file));
}
// Expose Plugin
module.exports = plugin;
Loading