hexo-renderer-marked
Advanced tools
Comparing version 1.0.1 to 2.0.0-rc1
@@ -10,4 +10,2 @@ /* global hexo */ | ||
pedantic: false, | ||
sanitize: false, | ||
tables: true, | ||
breaks: true, | ||
@@ -17,3 +15,4 @@ smartLists: true, | ||
modifyAnchors: '', | ||
autolink: true | ||
autolink: true, | ||
sanitizeUrl: false | ||
}, hexo.config.marked); | ||
@@ -20,0 +19,0 @@ |
'use strict'; | ||
var marked = require('marked'); | ||
var stripIndent = require('strip-indent'); | ||
var util = require('hexo-util'); | ||
const marked = require('marked'); | ||
const stripIndent = require('strip-indent'); | ||
const { stripHTML, highlight, slugize } = require('hexo-util'); | ||
const MarkedRenderer = marked.Renderer; | ||
var highlight = util.highlight; | ||
var stripHTML = util.stripHTML; | ||
var MarkedRenderer = marked.Renderer; | ||
function Renderer() { | ||
@@ -21,9 +18,9 @@ MarkedRenderer.apply(this); | ||
Renderer.prototype.heading = function(text, level) { | ||
var transformOption = this.options.modifyAnchors; | ||
var id = anchorId(stripHTML(text), transformOption); | ||
var headingId = this._headingId; | ||
const transformOption = this.options.modifyAnchors; | ||
let id = anchorId(stripHTML(text), transformOption); | ||
const headingId = this._headingId; | ||
// Add a number after id if repeated | ||
if (headingId[id]) { | ||
id += '-' + headingId[id]++; | ||
id += `-${headingId[id]++}`; | ||
} else { | ||
@@ -33,7 +30,7 @@ headingId[id] = 1; | ||
// add headerlink | ||
return '<h' + level + ' id="' + id + '"><a href="#' + id + '" class="headerlink" title="' + stripHTML(text) + '"></a>' + text + '</h' + level + '>'; | ||
return `<h${level} id="${id}"><a href="#${id}" class="headerlink" title="${stripHTML(text)}"></a>${text}</h${level}>`; | ||
}; | ||
function anchorId(str, transformOption) { | ||
return util.slugize(str.trim(), {transform: transformOption}); | ||
return slugize(str.trim(), {transform: transformOption}); | ||
} | ||
@@ -43,5 +40,5 @@ | ||
Renderer.prototype.link = function(href, title, text) { | ||
var prot; | ||
if (this.options.sanitizeUrl) { | ||
let prot; | ||
if (this.options.sanitize) { | ||
try { | ||
@@ -55,3 +52,3 @@ prot = decodeURIComponent(unescape(href)) | ||
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { | ||
if (prot.startsWith('javascript:') || prot.startsWith('vbscript:') || prot.startsWith('data:')) { | ||
return ''; | ||
@@ -65,9 +62,9 @@ } | ||
var out = '<a href="' + href + '"'; | ||
let out = `<a href="${href}"`; | ||
if (title) { | ||
out += ' title="' + title + '"'; | ||
out += ` title="${title}"`; | ||
} | ||
out += '>' + text + '</a>'; | ||
out += `>${text}</a>`; | ||
return out; | ||
@@ -77,19 +74,12 @@ }; | ||
// Support Basic Description Lists | ||
Renderer.prototype.paragraph = function(text) { | ||
var result = ''; | ||
var dlTest = /(^|\s)(\S.+)(<br>:(\s+))(\S.+)/; | ||
Renderer.prototype.paragraph = text => { | ||
const dlTest = /(?:^|\s)(\S.+)<br>:\s+(\S.+)/; | ||
var dl | ||
= '<dl>' | ||
+ '<dt>$2</dt>' | ||
+ '<dd>$5</dd>' | ||
+ '</dl>'; | ||
const dl = '<dl><dt>$1</dt><dd>$2</dd></dl>'; | ||
if (text.match(dlTest)) { | ||
result = text.replace(dlTest, dl); | ||
} else { | ||
result = '<p>' + text + '</p>\n'; | ||
if (dlTest.test(text)) { | ||
return text.replace(dlTest, dl); | ||
} | ||
return result; | ||
return `<p>${text}</p>\n`; | ||
}; | ||
@@ -99,5 +89,5 @@ | ||
langPrefix: '', | ||
highlight: function(code, lang) { | ||
highlight(code, lang) { | ||
return highlight(stripIndent(code), { | ||
lang: lang, | ||
lang, | ||
gutter: false, | ||
@@ -104,0 +94,0 @@ wrap: false |
{ | ||
"name": "hexo-renderer-marked", | ||
"version": "1.0.1", | ||
"version": "2.0.0-rc1", | ||
"description": "Markdown renderer plugin for Hexo", | ||
@@ -9,3 +9,3 @@ "main": "index", | ||
"test": "mocha test/index.js", | ||
"test-cov": "istanbul cover --print both _mocha -- test/index.js" | ||
"test-cov": "nyc npm run test" | ||
}, | ||
@@ -32,17 +32,17 @@ "directories": { | ||
"dependencies": { | ||
"hexo-util": "^0.6.2", | ||
"marked": "^0.6.1", | ||
"strip-indent": "^2.0.0" | ||
"hexo-util": "^0.6.3", | ||
"marked": "^0.7.0", | ||
"strip-indent": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^5.9.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.0.1", | ||
"babel-eslint": "^10.0.1", | ||
"eslint-config-hexo": "^3.0.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^6.0.0" | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": ">=8.6.0" | ||
} | ||
} |
@@ -26,4 +26,2 @@ # hexo-renderer-marked | ||
pedantic: false | ||
sanitize: false | ||
tables: true | ||
breaks: true | ||
@@ -34,2 +32,3 @@ smartLists: true | ||
autolink: true | ||
sanitizeUrl: false | ||
``` | ||
@@ -39,4 +38,2 @@ | ||
- **pedantic** - Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of the original markdown bugs or poor behavior. | ||
- **sanitize** - Sanitize the output. Ignore any HTML that has been input. | ||
- **tables** - Enable GFM [tables](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables). This option requires the `gfm` option to be true. | ||
- **breaks** - Enable GFM [line breaks](https://help.github.com/articles/github-flavored-markdown#newlines). This option requires the `gfm` option to be true. | ||
@@ -47,2 +44,3 @@ - **smartLists** - Use smarter list behavior than the original markdown. | ||
- **autolink** - Enable autolink for URLs. E.g. `https://hexo.io` will become `<a href="https://hexo.io">https://hexo.io</a>`. | ||
- **sanitizeUrl** - Remove URLs that start with `javascript:`, `vbscript:` and `data:`. | ||
@@ -49,0 +47,0 @@ ## Extras |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8269
96
2
89
1
+ Addedmarked@0.7.0(transitive)
+ Addedmin-indent@1.0.1(transitive)
+ Addedstrip-indent@3.0.0(transitive)
- Removedmarked@0.6.3(transitive)
- Removedstrip-indent@2.0.0(transitive)
Updatedhexo-util@^0.6.3
Updatedmarked@^0.7.0
Updatedstrip-indent@^3.0.0