Browse Source

Added sugar for curried plugins init

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
d5f06f875e
  1. 21
      README.md
  2. 18
      lib/index.js

21
README.md

@ -33,7 +33,7 @@ bower install remarkable --save
## Usage
```javascript
```js
var Remarkable = require('remarkable');
// This values are default
@ -56,7 +56,7 @@ console.log(md.parse('# Remarkable rulezz!'));
You can define options via `set` method:
```javascript
```js
var Remarkable = require('remarkable');
var md = new Remarkable();
@ -72,7 +72,7 @@ setup each appropriately.
You can also reset parser to strict [CommonMark](http://commonmark.org/) mode:
```javascript
```js
var Remarkable = require('remarkable');
var md = new Remarkable('commonmark');
```
@ -81,7 +81,7 @@ var md = new Remarkable('commonmark');
To highlight content of fenced block, assing function to `highlight` option:
```javascript
```js
var Remarkable = require('remarkable');
var hljs = require('highlight.js') // https://highlightjs.org/
@ -108,7 +108,7 @@ var md = new Remarkable({
Though full weigh typograpic replacements are language specific, `remarkable`
provides the most common and universal case coverage:
```javascript
```js
var Remarkable = require('remarkable');
var md = new Remarkable({ typographer: true });
@ -158,7 +158,7 @@ Parser consists of several responsibilities chains, filled with rules. You can
reconfigure anyone as you wish. Render also can be modified and extended. See
source code to understand details. Pay attention to this properties:
```javascript
```js
Remarkable.block
Remarkable.block.ruler
Remarkable.inline
@ -171,6 +171,15 @@ Remarkable.renderer
Remarkable.renderer.rules
```
To prettify plugins init, we `Remarked` has `.use()` helper for curried calls:
```js
var md = new Remarkable();
md.use(plugin1)
.use(plugin2, opts)
.use(plugin3);
```
## Authors

18
lib/index.js

@ -41,6 +41,8 @@ function Remarkable(options) {
}
// Set options, if you did not passed those to constructor
//
Remarkable.prototype.set = function (options) {
if (String(options).toLowerCase() === 'commonmark') {
assign(this.options, cmmDefaults);
@ -52,6 +54,22 @@ Remarkable.prototype.set = function (options) {
};
// Sugar for curried plugins init:
//
// var md = new Remarkable();
//
// md.use(plugin1)
// .use(plugin2, opts)
// .use(plugin3);
//
Remarkable.prototype.use = function (plugin, opts) {
plugin(this, opts);
return this;
};
// Main method that does all magic :)
//
Remarkable.prototype.render = function (src) {
var tokens, tok, i, l, env = { references: Object.create(null) };

Loading…
Cancel
Save