hexo-renderer-markdown-it
Advanced tools
Comparing version
29
index.js
@@ -0,4 +1,31 @@ | ||
/* global hexo */ | ||
'use strict'; | ||
var renderer = require('./lib/renderer'); | ||
hexo.config.markdown = Object.assign({ | ||
render: {}, | ||
anchors: {} | ||
}, hexo.config.markdown); | ||
hexo.config.markdown.render = Object.assign({ | ||
html: true, | ||
xhtmlOut: false, | ||
breaks: true, | ||
linkify: true, | ||
typographer: true, | ||
quotes: '“”‘’' | ||
}, hexo.config.markdown.render); | ||
hexo.config.markdown.anchors = Object.assign({ | ||
level: 2, | ||
collisionSuffix: '', | ||
permalink: false, | ||
permalinkClass: 'header-anchor', | ||
permalinkSymbol: '¶', | ||
case: 0, | ||
separator: '' | ||
}, hexo.config.markdown.anchors); | ||
const renderer = require('./lib/renderer'); | ||
hexo.extend.renderer.register('md', 'html', renderer, true); | ||
@@ -5,0 +32,0 @@ hexo.extend.renderer.register('markdown', 'html', renderer, true); |
'use strict'; | ||
var assign = require('lodash.assign'); | ||
var Token = require('markdown-it/lib/token'); | ||
var sluggo = require('sluggo'); | ||
const Token = require('markdown-it/lib/token'); | ||
const { slugize } = require('hexo-util'); | ||
var renderPermalink = function (slug, opts, tokens, idx) { | ||
return tokens[idx + 1].children.unshift(assign(new Token('link_open', 'a', 1), { | ||
const renderPermalink = function(slug, opts, tokens, idx) { | ||
return tokens[idx + 1].children.unshift(Object.assign(new Token('link_open', 'a', 1), { | ||
attrs: [['class', opts.permalinkClass], ['href', '#' + slug]] | ||
}), assign(new Token('text', '', 0), { | ||
}), Object.assign(new Token('text', '', 0), { | ||
content: opts.permalinkSymbol | ||
}), new Token('link_close', 'a', -1), assign(new Token('text', '', 0), { | ||
}), new Token('link_close', 'a', -1), Object.assign(new Token('text', '', 0), { | ||
content: '' | ||
@@ -17,23 +16,22 @@ })); | ||
var anchor = function (md, opts) { | ||
opts = assign({}, anchor.defaults, opts); | ||
const anchor = function(md, opts) { | ||
Object.assign(opts, { renderPermalink }); | ||
var titleStore = {}; | ||
var originalHeadingOpen = md.renderer.rules.heading_open; | ||
const titleStore = {}; | ||
const originalHeadingOpen = md.renderer.rules.heading_open; | ||
const slugOpts = { transform: opts.case, ...opts }; | ||
md.renderer.rules.heading_open = function (tokens, idx, something, somethingelse, self) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
md.renderer.rules.heading_open = function(...args) { | ||
const [tokens, idx, something, somethingelse, self] = args; // eslint-disable-line no-unused-vars | ||
if (tokens[idx].tag.substr(1) >= opts.level) { | ||
var _tokens$idx; | ||
let _tokens$idx; | ||
var title = tokens[idx + 1].children.reduce(function (acc, t) { | ||
const title = tokens[idx + 1].children.reduce((acc, t) => { | ||
return acc + t.content; | ||
}, ''); | ||
var slug = sluggo(title); | ||
let slug = slugize(title, slugOpts); | ||
if (titleStore.hasOwnProperty(slug)) { | ||
if (Object.prototype.hasOwnProperty.call(titleStore, slug)) { | ||
titleStore[slug] = titleStore[slug] + 1; | ||
@@ -47,3 +45,3 @@ slug = slug + '-' + opts.collisionSuffix + titleStore[slug].toString(); | ||
(_tokens$idx = tokens[idx], !_tokens$idx.attrs && (_tokens$idx.attrs = []), _tokens$idx.attrs) | ||
.push(['id', slug]); | ||
.push(['id', slug]); | ||
@@ -55,17 +53,8 @@ if (opts.permalink) { | ||
return (originalHeadingOpen) ? | ||
originalHeadingOpen.apply(this, args) : | ||
self.renderToken.apply(self, args); | ||
return originalHeadingOpen | ||
? originalHeadingOpen.apply(this, args) | ||
: self.renderToken.apply(self, args); | ||
}; | ||
}; | ||
anchor.defaults = { | ||
level: 1, | ||
collisionSuffix: 'v', | ||
permalink: false, | ||
renderPermalink: renderPermalink, | ||
permalinkClass: 'header-anchor', | ||
permalinkSymbol: '¶' | ||
}; | ||
module.exports = anchor; |
'use strict'; | ||
module.exports = function (data, options) { | ||
var MdIt = require('markdown-it'); | ||
var cfg = this.config.markdown; | ||
var opt = (cfg) ? cfg : 'default'; | ||
var parser = (opt === 'default' || opt === 'commonmark' || opt === 'zero') ? | ||
new MdIt(opt) : | ||
new MdIt(opt.render); | ||
module.exports = function(data, options) { | ||
const MdIt = require('markdown-it'); | ||
const cfg = this.config.markdown; | ||
const opt = cfg ? cfg : 'default'; | ||
let parser = opt === 'default' || opt === 'commonmark' || opt === 'zero' | ||
? new MdIt(opt) | ||
: new MdIt(opt.render); | ||
if (opt.plugins) { | ||
parser = opt.plugins.reduce(function (parser, pugs) { | ||
parser = opt.plugins.reduce((parser, pugs) => { | ||
if (pugs instanceof Object && pugs.name) { | ||
return parser.use(require(pugs.name), pugs.options); | ||
} | ||
return parser.use(require(pugs)); | ||
}, parser); | ||
@@ -15,0 +19,0 @@ } |
{ | ||
"name": "hexo-renderer-markdown-it", | ||
"version": "3.4.1", | ||
"version": "4.0.0", | ||
"description": "Markdown-it is a Markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.", | ||
"main": "index", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "gulp test" | ||
"eslint": "eslint .", | ||
"test": "mocha test/index.js", | ||
"test-cov": "nyc npm run test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/celsomiranda/hexo-renderer-markdown-it.git" | ||
"url": "git://github.com/hexojs/hexo-renderer-markdown-it.git" | ||
}, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"keywords": [ | ||
@@ -23,33 +22,39 @@ "hexo", | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"lib/" | ||
], | ||
"author": "Celso Miranda <contacto@celsomiranda.net> (http://celsomiranda.net/)", | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://raw.github.com/celsomiranda/hexo-renderer-markdown-it/master/LICENSE" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/celsomiranda/hexo-renderer-markdown-it/issues" | ||
"url": "https://github.com/hexojs/hexo-renderer-markdown-it/issues" | ||
}, | ||
"homepage": "https://github.com/celsomiranda/hexo-renderer-markdown-it", | ||
"homepage": "https://github.com/hexojs/hexo-renderer-markdown-it", | ||
"dependencies": { | ||
"lodash.assign": "^3.2.0", | ||
"markdown-it": "^5.0.1", | ||
"markdown-it-abbr": "^1.0.0", | ||
"markdown-it-footnote": "^2.0.0", | ||
"markdown-it-ins": "^2.0.0", | ||
"hexo-util": "^1.7.0", | ||
"markdown-it": "^10.0.0", | ||
"markdown-it-abbr": "^1.0.4", | ||
"markdown-it-cjk-breaks": "^1.1.2", | ||
"markdown-it-container": "^2.0.0", | ||
"markdown-it-deflist": "^2.0.3", | ||
"markdown-it-emoji": "^1.4.0", | ||
"markdown-it-footnote": "^3.0.1", | ||
"markdown-it-ins": "^3.0.0", | ||
"markdown-it-mark": "^3.0.0", | ||
"markdown-it-sub": "^1.0.0", | ||
"markdown-it-sup": "^1.0.0", | ||
"sluggo": "^0.2.0" | ||
"markdown-it-sup": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.2.0", | ||
"coveralls": "^2.11.4", | ||
"del": "^2.1.0", | ||
"gulp": "^3.9.0", | ||
"gulp-istanbul": "^0.10.0", | ||
"gulp-jshint": "^1.11.2", | ||
"gulp-load-plugins": "^1.0.0-rc.1", | ||
"gulp-mocha": "^2.1.3", | ||
"jshint-stylish": "^2.0.1", | ||
"mocha": "^2.2.5" | ||
"chai": "^4.0.0", | ||
"eslint": "^6.0.1", | ||
"eslint-config-hexo": "^4.0.0", | ||
"mocha": "^6.0.2", | ||
"nyc": "^14.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.6.0" | ||
} | ||
} |
# hexo-renderer-markdown-it | ||
[](https://travis-ci.org/celsomiranda/hexo-renderer-markdown-it) | ||
[](http://badge.fury.io/js/hexo-renderer-markdown-it) [](https://www.npmjs.com/package/hexo-renderer-markdown-it) | ||
[](https://coveralls.io/r/celsomiranda/hexo-renderer-markdown-it) | ||
[](https://travis-ci.org/hexojs/hexo-renderer-markdown-it) | ||
[](https://www.npmjs.com/package/hexo-renderer-markdown-it) | ||
[](https://david-dm.org/hexojs/hexo-renderer-markdown-it) | ||
[](https://coveralls.io/github/hexojs/hexo-renderer-markdown-it?branch=master) | ||
This renderer plugin uses [Markdown-it] as a render engine on [Hexo]. Adds support for [Markdown] and [CommonMark]. | ||
## Documentation | ||
This `README` was getting too messy for my taste, so it was time to fire up the github wiki in the repo and [move the documentation over there](https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki). | ||
## Main Features | ||
@@ -24,8 +22,30 @@ - Support for [Markdown], [GFM] and [CommonMark] | ||
## Installation | ||
You can install `hexo-renderer-markdown-it` by following [these steps in the documentation](https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki/Getting-Started). | ||
Follow the [installation guide](https://github.com/hexojs/hexo-renderer-markdown-it/wiki/Getting-Started). | ||
It's also the place to go if you want to know more about how `hexo-renderer-markdown-it` works. | ||
## Options | ||
``` yml | ||
markdown: | ||
render: | ||
html: true | ||
xhtmlOut: false | ||
breaks: true | ||
linkify: true | ||
typographer: true | ||
quotes: '“”‘’' | ||
plugins: | ||
anchors: | ||
level: 2 | ||
collisionSuffix: '' | ||
permalink: false, | ||
permalinkClass: 'header-anchor' | ||
permalinkSymbol: '¶' | ||
case: 0 | ||
separator: '' | ||
``` | ||
Refer to [the wiki](https://github.com/hexojs/hexo-renderer-markdown-it/wiki) for more details. | ||
## Requests and bug reports | ||
If you have any feature requests or bugs to report, [you're welcome to file an issue](https://github.com/celsomiranda/hexo-renderer-markdown-it/issues). | ||
If you have any feature requests or bugs to report, you're welcome to [file an issue](https://github.com/hexojs/hexo-renderer-markdown-it/issues). | ||
@@ -32,0 +52,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
8083
2.52%5
-50%95
18.75%57
54.05%12
50%6
-25%2
100%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated