├── .gitignore
├── .npmignore
├── test
├── fixtures
│ ├── plugins
│ │ ├── src
│ │ │ └── index.md
│ │ ├── build
│ │ │ └── index.html
│ │ └── expected
│ │ │ └── index.html
│ └── basic
│ │ ├── src
│ │ └── index.md
│ │ ├── build
│ │ └── index.html
│ │ └── expected
│ │ └── index.html
└── index.js
├── makefile
├── package.json
├── lib
└── index.js
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 | makefile
3 |
--------------------------------------------------------------------------------
/test/fixtures/plugins/src/index.md:
--------------------------------------------------------------------------------
1 | A paragraph with a class applied. {boring}
2 |
--------------------------------------------------------------------------------
/test/fixtures/plugins/build/index.html:
--------------------------------------------------------------------------------
1 |
A paragraph with a class applied.
2 |
--------------------------------------------------------------------------------
/test/fixtures/plugins/expected/index.html:
--------------------------------------------------------------------------------
1 | A paragraph with a class applied.
2 |
--------------------------------------------------------------------------------
/test/fixtures/basic/src/index.md:
--------------------------------------------------------------------------------
1 | # A Markdown Post
2 |
3 | With some "amazing" _'riveting'_ **coooonnnntent**, and a URL: https://www.npmjs.com/package/remarkable.
4 |
--------------------------------------------------------------------------------
/test/fixtures/basic/build/index.html:
--------------------------------------------------------------------------------
1 | A Markdown Post
2 | With some “amazing” ‘riveting’ coooonnnntent, and a URL: https://www.npmjs.com/package/remarkable.
3 |
--------------------------------------------------------------------------------
/test/fixtures/basic/expected/index.html:
--------------------------------------------------------------------------------
1 | A Markdown Post
2 | With some “amazing” ‘riveting’ coooonnnntent, and a URL: https://www.npmjs.com/package/remarkable.
3 |
--------------------------------------------------------------------------------
/makefile:
--------------------------------------------------------------------------------
1 |
2 | node_modules: package.json
3 | @npm install
4 |
5 | test: node_modules
6 | @./node_modules/.bin/mocha --reporter spec
7 |
8 | test-debug: node_modules
9 | @DEBUG=* ./node_modules/.bin/mocha --reporter spec
10 |
11 | .PHONY: test
12 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "metalsmith-markdown-remarkable",
3 | "version": "2.0.5",
4 | "description": "A Metalsmith plugin to convert markdown files via Remarkable.",
5 | "repository": "git://github.com/attentif/metalsmith-markdown-remarkable.git",
6 | "author": "Simon Goumaz ",
7 | "license": "MIT",
8 | "main": "lib/index.js",
9 | "scripts": {
10 | "test": "mocha --reporter spec"
11 | },
12 | "dependencies": {
13 | "debug": "^4.3.4",
14 | "remarkable": "^2.0.1"
15 | },
16 | "devDependencies": {
17 | "assert-dir-equal": "^1.1.0",
18 | "metalsmith": "^2.5.1",
19 | "mocha": "^10.1.0",
20 | "remarkable-classy": "^0.0.1"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test/index.js:
--------------------------------------------------------------------------------
1 | /* global describe, it */
2 |
3 | const assertDirEqual = require('assert-dir-equal'),
4 | metalsmith = require('metalsmith'),
5 | markdown = require('..');
6 |
7 | describe('metalsmith-markdown-remarkable', function () {
8 |
9 | it('should convert markdown files, passing Remarkable preset and options', function (done) {
10 | metalsmith('test/fixtures/basic')
11 | .use(markdown('full', {
12 | html: true,
13 | langPrefix: '',
14 | typographer: true
15 | }))
16 | .build(function (err) {
17 | if (err) { return done(err); }
18 | assertDirEqual('test/fixtures/basic/expected', 'test/fixtures/basic/build');
19 | done();
20 | });
21 | });
22 |
23 | describe('use()', function () {
24 |
25 | const classy = require('remarkable-classy');
26 |
27 | it('should pass Remarkable plugins', function (done) {
28 | metalsmith('test/fixtures/plugins')
29 | .use(markdown().use(classy))
30 | .build(function (err) {
31 | if (err) { return done(err); }
32 | assertDirEqual('test/fixtures/plugins/expected', 'test/fixtures/plugins/build');
33 | done();
34 | });
35 | });
36 |
37 | });
38 |
39 | });
40 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | const debug = require('debug')('metalsmith-markdown-remarkable'),
2 | path = require('path'),
3 | { Remarkable } = require('remarkable'),
4 | inspect = require('util').inspect;
5 |
6 | module.exports = getPlugin;
7 |
8 | /**
9 | * metalsmith plugin to convert markdown files via Remarkable.
10 | *
11 | * @param {String} Remarkable preset (optional)
12 | * @param {Object} Remarkable options (optional)
13 | * @return {Function}
14 | */
15 | function getPlugin(preset, options) {
16 | debug('plugin initialized with preset %s, options %s', inspect(preset), inspect(options));
17 | const md = new Remarkable(preset, options);
18 |
19 | const run = function (files, metalsmith, done) {
20 | Object.keys(files).forEach(function (file) {
21 | debug('checking file: %s', file);
22 | if (! isMarkdown(file)) {
23 | return;
24 | }
25 |
26 | let data = files[file],
27 | dirName = path.dirname(file),
28 | htmlName = path.basename(file, path.extname(file)) + '.html';
29 | if (dirName !== '.') {
30 | htmlName = dirName + '/' + htmlName;
31 | }
32 |
33 | debug('converting file: %s', file);
34 | const str = md.render(data.contents.toString());
35 | data.contents = new Buffer(str);
36 |
37 | delete files[file];
38 | files[htmlName] = data;
39 | });
40 | done();
41 | };
42 |
43 | run.use = function () {
44 | md.use.apply(md, arguments);
45 | return run;
46 | };
47 |
48 | return run;
49 | }
50 |
51 | /**
52 | * Checks if a `file` is markdown.
53 | *
54 | * @param {String} file
55 | * @return {Boolean}
56 | */
57 | function isMarkdown(file){
58 | return /\.md|\.markdown/.test(path.extname(file));
59 | }
60 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > [!WARNING]
2 | > This repository is no longer maintained.
3 |
4 | # metalsmith-markdown-remarkable
5 |
6 | A Metalsmith plugin to convert markdown files via [Remarkable](https://www.npmjs.com/package/remarkable). Derived from [metalsmith-markdown](https://www.npmjs.com/package/metalsmith-markdown).
7 |
8 | [](https://www.npmjs.com/package/metalsmith-markdown-remarkable)
9 |
10 |
11 | ## Installation
12 |
13 | ```
14 | npm install metalsmith-markdown-remarkable
15 | ```
16 |
17 |
18 | ### Warning: Remarkable version
19 |
20 | If you care about what Remarkable is bundled herein, please note:
21 |
22 | - v1.* of this plugin now use Remarkable 1.*
23 | - v2.* use Remarkable 2.*
24 |
25 | (Remarkable was originally – and carelessly – upgraded to 2.0 in v1.0.1, now deprecated. Thanks to @jja for the heads-up.)
26 |
27 |
28 | ## CLI usage
29 |
30 | Add `metalsmith-markdown-remarkable` to your `metalsmith.json` plugins with any [Remarkable options](https://www.npmjs.com/package/remarkable#options) you want:
31 |
32 | ```json
33 | {
34 | "plugins": {
35 | "metalsmith-markdown-remarkable": {
36 | "breaks": true,
37 | "typographer": true,
38 | "quotes": "«»‘’"
39 | }
40 | }
41 | }
42 | ```
43 |
44 |
45 | ## Javascript usage
46 |
47 | Pass the plugin to Metalsmith via `use()`, optionally setting Remarkable [`preset`](https://www.npmjs.com/package/remarkable#presets) and [`options`](https://www.npmjs.com/package/remarkable#options) (or just the latter):
48 |
49 | ```js
50 | var markdown = require('metalsmith-markdown-remarkable');
51 |
52 | metalsmith.use(markdown('full', {
53 | breaks: true,
54 | typographer: true,
55 | quotes: '«»‘’'
56 | }));
57 | ```
58 |
59 | ### Passing Remarkable plugins
60 |
61 | The plugin also defines a `use()` function, which passes whatever you give it to Remarkable's own `use()`:
62 |
63 | ```js
64 | metalsmith.use(markdown().use(remarkablePlugin));
65 | ```
66 |
67 | If you have multiple Remarkable plugins, just chain calls:
68 |
69 | ```js
70 | metalsmith.use(markdown().use(plugin1).use(plugin2));
71 | ```
72 |
73 |
74 | ## License
75 |
76 | MIT
77 |
--------------------------------------------------------------------------------