Skip to content

Commit

Permalink
Update dependencies, docs updated for webpack2, drop Node 0.12 suppor…
Browse files Browse the repository at this point in the history
…t, update deps
  • Loading branch information
meaku committed Feb 3, 2017
1 parent c12e82d commit e81f866
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.idea
node_modules
node_modules
77 changes: 40 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,71 @@ markdown-loader

markdown-loader for webpack using [marked](https://github.com/chjj/marked).


## Setup

[![npm status](https://nodei.co/npm/markdown-loader.svg?downloads=true&stars=true)](https://npmjs.org/package/markdown-loader)

[![dependencies](https://david-dm.org/peerigon/batch-replace.svg)](http://david-dm.org/peerigon/markdown-loader)
[![devDependency Status](https://david-dm.org/peerigon/batch-replace/dev-status.svg)](https://david-dm.org/peerigon/markdown-loader#info=devDependencies)

## Usage
## Usage

```javascript
var html = require("html!markdown!./README.md");
```
Since marked's output is HTML, it's best served in conjunction with the [html-loader](https://github.com/webpack/html-loader).

### Recommended Configuration

Since marked's output is HTML, it's best served in conjunction with the [html-loader](https://github.com/webpack/html-loader).
### Webpack 2

```javascript
{
module: {
loaders: [
{ test: /\.md$/, loader: "html!markdown" },
]
rules: [{
test: /\.md$/,
use: [
{
loader: "html-loader"
},
{
loader: "markdown-loader",
options: {
/* your options here */
}
}
]
}]
}
}
```

## Options

[marked](https://github.com/chjj/marked)-options are passed via query params:
### Options


```javascript
{
module: {
loaders: {
{ test: /\.md$/, loader: "html!markdown?gfm=false" },
]
}
}
```
### Custom renderer
In order to specify [custom renderers](https://github.com/peerigon/markdown-loader/issues/5), simply set the `markdownLoader.renderer`-option on your webpack options. You can also change the options' key
with a query parameter: `"markdown?config=markdownLoaderCustomConfig"`.
Simply pass your marked
In order to specify [custom renderers](https://github.com/peerigon/markdown-loader/issues/5), simply set the `options.renderer`-option on your webpack options.

```javascript
// webpack.config.js

var marked = require("marked");
var renderer = new marked.Renderer();
const marked = require("marked");
const renderer = new marked.Renderer();

module.exports = {
...
markdownLoader: {
renderer: renderer
return {
module: {
rules: [{
test: /\.md$/,
use: [
{
loader: "html-loader"
},
{
loader: "markdown-loader",
options: {
pedantic: true,
renderer
}
}
]
}]
}
};
}
```
## License

MIT (http://www.opensource.org/licenses/mit-license.php)
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"use strict";

var marked = require("marked");
var loaderUtils = require("loader-utils");
var assign = require("object-assign");
const marked = require("marked");
const loaderUtils = require("loader-utils");

// default option
var options = {
const DEFAULT_OPTIONS = {
renderer: new marked.Renderer(),
gfm: true,
tables: true,
Expand All @@ -18,9 +16,7 @@ var options = {

module.exports = function (markdown) {
// merge params and default config
var query = loaderUtils.parseQuery(this.query);
var configKey = query.config || "markdownLoader";
var options = assign({}, options, query, this.options[configKey]);
const options = Object.assign(DEFAULT_OPTIONS, loaderUtils.parseQuery(this.query));

this.cacheable();

Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "markdown-loader",
"version": "0.1.7",
"version": "0.2.0",
"description": "markdown-loader for webpack",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "ava test/*.test.js"
},
"repository": {
"type": "git",
Expand All @@ -23,8 +23,13 @@
},
"homepage": "https://github.com/peerigon/markdown-loader",
"dependencies": {
"marked": "^0.3.2",
"loader-utils": "^0.2.7",
"object-assign": "^2.0.0"
"loader-utils": "^0.2.16",
"marked": "^0.3.6"
},
"devDependencies": {
"ava": "^0.18.0",
"highlight.js": "^9.9.0",
"html-loader": "^0.4.4",
"webpack": "^2.2.1"
}
}
1 change: 1 addition & 0 deletions test/assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./markdown.md");
11 changes: 11 additions & 0 deletions test/assets/markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# heading 1

- buy pineapple

## heading 2

_italic_ is the new __bold__

```javascript
const i = 100;
```
50 changes: 50 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";

import test from "ava";
import webpack from "webpack";
import path from "path";
import fs from "fs";
import marked from "marked";
import markdownOptions from "./markdown-options";

test.cb(t => {
webpack({
entry: path.resolve(__dirname, "./assets/markdown.md"),
module: {
rules: [{
test: /\.md$/,
use: [
{
loader: "html-loader"
},
{
loader: require.resolve("../index.js"),
options: markdownOptions
}
]
}]
},
output: {
libraryTarget: "commonjs2",
path: __dirname + "/output",
filename: "bundle.js"
}
}, function onCompilationFinished(err, stats) {
if (err) {
return t.end(err);
}
if (stats.hasErrors()) {
return t.end(stats.compilation.errors[0]);
}
if (stats.hasWarnings()) {
return t.end(stats.compilation.warnings[0]);
}

const bundle = require("./output/bundle");
t.is(bundle, '<h1 id=\"heading-1\">heading 1</h1>\n<ul>\n<li>buy pineapple</li>\n</ul>\n<h2 id=\"heading-2\">heading 2</h2>\n<p><em>italic</em> is the new <strong>bold</strong></p>\n<pre><code class=\"lang-javascript\"><span class=\"hljs-attribute\">const i</span> = 100;\n</code></pre>\n');

t.end();
});
});


7 changes: 7 additions & 0 deletions test/markdown-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
renderer: require("./markdown-renderer"),
highlight: function(code) {
return require("highlight.js").highlightAuto(code).value;
},
sanitize: false
};
5 changes: 5 additions & 0 deletions test/markdown-renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* globals escape */
var marked = require("marked");
var renderer = new marked.Renderer();

module.exports = renderer;

0 comments on commit e81f866

Please sign in to comment.