Comparing version 1.2.0 to 1.3.0
@@ -1,1 +0,1 @@ | ||
{"languages":["1c","abnf","accesslog","actionscript","ada","angelscript","apache","applescript","arcade","cpp","arduino","armasm","xml","asciidoc","aspectj","autohotkey","autoit","avrasm","awk","axapta","bash","basic","bnf","brainfuck","cal","capnproto","ceylon","clean","clojure","clojure-repl","cmake","coffeescript","coq","cos","crmsh","crystal","cs","csp","css","d","markdown","dart","delphi","diff","django","dns","dockerfile","dos","dsconfig","dts","dust","ebnf","elixir","elm","ruby","erb","erlang-repl","erlang","excel","fix","flix","fortran","fsharp","gams","gauss","gcode","gherkin","glsl","gml","go","golo","gradle","groovy","haml","handlebars","haskell","haxe","hsp","htmlbars","http","hy","inform7","ini","irpf90","isbl","java","javascript","jboss-cli","json","julia","julia-repl","kotlin","lasso","ldif","leaf","less","lisp","livecodeserver","livescript","llvm","lsl","lua","makefile","mathematica","matlab","maxima","mel","mercury","mipsasm","mizar","perl","mojolicious","monkey","moonscript","n1ql","nginx","nimrod","nix","nsis","objectivec","ocaml","openscad","oxygene","parser3","pf","pgsql","php","plaintext","pony","powershell","processing","profile","prolog","properties","protobuf","puppet","purebasic","python","q","qml","r","reasonml","rib","roboconf","routeros","rsl","ruleslanguage","rust","sas","scala","scheme","scilab","scss","shell","smali","smalltalk","sml","sqf","sql","stan","stata","step21","stylus","subunit","swift","taggerscript","yaml","tap","tcl","tex","thrift","tp","twig","typescript","vala","vbnet","vbscript","vbscript-html","verilog","vhdl","vim","x86asm","xl","xquery","zephir"],"aliases":{"1c":"1c","abnf":"abnf","accesslog":"accesslog","actionscript":"actionscript","as":"actionscript","ada":"ada","angelscript":"angelscript","asc":"angelscript","apache":"apache","apacheconf":"apache","applescript":"applescript","osascript":"applescript","arcade":"arcade","cpp":"cpp","c":"cpp","cc":"cpp","h":"cpp","c++":"cpp","h++":"cpp","hpp":"cpp","hh":"cpp","hxx":"cpp","cxx":"cpp","arduino":"arduino","armasm":"armasm","arm":"armasm","xml":"xml","html":"xml","xhtml":"xml","rss":"xml","atom":"xml","xjb":"xml","xsd":"xml","xsl":"xml","plist":"xml","asciidoc":"asciidoc","adoc":"asciidoc","aspectj":"aspectj","autohotkey":"autohotkey","ahk":"autohotkey","autoit":"autoit","avrasm":"avrasm","awk":"awk","axapta":"axapta","bash":"bash","sh":"bash","zsh":"bash","basic":"basic","bnf":"bnf","brainfuck":"brainfuck","bf":"brainfuck","cal":"cal","capnproto":"capnproto","capnp":"capnproto","ceylon":"ceylon","clean":"clean","icl":"clean","dcl":"clean","clojure":"clojure","clj":"clojure","clojure-repl":"clojure-repl","cmake":"cmake","cmake.in":"cmake","coffeescript":"coffeescript","coffee":"coffeescript","cson":"coffeescript","iced":"coffeescript","coq":"coq","cos":"cos","cls":"cos","crmsh":"crmsh","crm":"crmsh","pcmk":"crmsh","crystal":"crystal","cr":"crystal","cs":"cs","csharp":"cs","c#":"cs","csp":"csp","css":"css","d":"d","markdown":"markdown","md":"markdown","mkdown":"markdown","mkd":"markdown","dart":"dart","delphi":"delphi","dpr":"delphi","dfm":"delphi","pas":"delphi","pascal":"delphi","freepascal":"delphi","lazarus":"delphi","lpr":"delphi","lfm":"delphi","diff":"diff","patch":"diff","django":"django","jinja":"django","dns":"dns","bind":"dns","zone":"dns","dockerfile":"dockerfile","docker":"dockerfile","dos":"dos","bat":"dos","cmd":"dos","dsconfig":"dsconfig","dts":"dts","dust":"dust","dst":"dust","ebnf":"ebnf","elixir":"elixir","elm":"elm","ruby":"ruby","rb":"ruby","gemspec":"ruby","podspec":"ruby","thor":"ruby","irb":"ruby","erb":"erb","erlang-repl":"erlang-repl","erlang":"erlang","erl":"erlang","excel":"excel","xlsx":"excel","xls":"excel","fix":"fix","flix":"flix","fortran":"fortran","f90":"fortran","f95":"fortran","fsharp":"fsharp","fs":"fsharp","gams":"gams","gms":"gams","gauss":"gauss","gss":"gauss","gcode":"gcode","nc":"gcode","gherkin":"gherkin","feature":"gherkin","glsl":"glsl","gml":"gml","GML":"gml","go":"go","golang":"go","golo":"golo","gradle":"gradle","groovy":"groovy","haml":"haml","handlebars":"handlebars","hbs":"handlebars","html.hbs":"handlebars","html.handlebars":"handlebars","haskell":"haskell","hs":"haskell","haxe":"haxe","hx":"haxe","hsp":"hsp","htmlbars":"htmlbars","http":"http","https":"http","hy":"hy","hylang":"hy","inform7":"inform7","i7":"inform7","ini":"ini","toml":"ini","irpf90":"irpf90","isbl":"isbl","java":"java","jsp":"java","javascript":"javascript","js":"javascript","jsx":"javascript","jboss-cli":"jboss-cli","wildfly-cli":"jboss-cli","json":"json","julia":"julia","julia-repl":"julia-repl","kotlin":"kotlin","kt":"kotlin","lasso":"lasso","ls":"livescript","lassoscript":"lasso","ldif":"ldif","leaf":"leaf","less":"less","lisp":"lisp","livecodeserver":"livecodeserver","livescript":"livescript","llvm":"llvm","lsl":"lsl","lua":"lua","makefile":"makefile","mk":"makefile","mak":"makefile","mathematica":"mathematica","mma":"mathematica","matlab":"matlab","maxima":"maxima","mel":"mel","mercury":"mercury","m":"mercury","moo":"mercury","mipsasm":"mipsasm","mips":"mipsasm","mizar":"mizar","perl":"perl","pl":"perl","pm":"perl","mojolicious":"mojolicious","monkey":"monkey","moonscript":"moonscript","moon":"moonscript","n1ql":"n1ql","nginx":"nginx","nginxconf":"nginx","nimrod":"nimrod","nim":"nimrod","nix":"nix","nixos":"nix","nsis":"nsis","objectivec":"objectivec","mm":"objectivec","objc":"objectivec","obj-c":"objectivec","ocaml":"ocaml","ml":"sml","openscad":"openscad","scad":"openscad","oxygene":"oxygene","parser3":"parser3","pf":"pf","pf.conf":"pf","pgsql":"pgsql","postgres":"pgsql","postgresql":"pgsql","php":"php","php3":"php","php4":"php","php5":"php","php6":"php","php7":"php","plaintext":"plaintext","pony":"pony","powershell":"powershell","ps":"powershell","processing":"processing","profile":"profile","prolog":"prolog","properties":"properties","protobuf":"protobuf","puppet":"puppet","pp":"puppet","purebasic":"purebasic","pb":"purebasic","pbi":"purebasic","python":"python","py":"python","gyp":"python","ipython":"python","q":"q","k":"q","kdb":"q","qml":"qml","qt":"qml","r":"r","reasonml":"reasonml","re":"reasonml","rib":"rib","roboconf":"roboconf","graph":"roboconf","instances":"roboconf","routeros":"routeros","mikrotik":"routeros","rsl":"rsl","ruleslanguage":"ruleslanguage","rust":"rust","rs":"rust","sas":"sas","SAS":"sas","scala":"scala","scheme":"scheme","scilab":"scilab","sci":"scilab","scss":"scss","shell":"shell","console":"shell","smali":"smali","smalltalk":"smalltalk","st":"smalltalk","sml":"sml","sqf":"sqf","sql":"sql","stan":"stan","stata":"stata","do":"stata","ado":"stata","step21":"step21","p21":"step21","step":"step21","stp":"step21","stylus":"stylus","styl":"stylus","subunit":"subunit","swift":"swift","taggerscript":"taggerscript","yaml":"yaml","yml":"yaml","YAML":"yaml","tap":"tap","tcl":"tcl","tk":"tcl","tex":"tex","thrift":"thrift","tp":"tp","twig":"twig","craftcms":"twig","typescript":"typescript","ts":"typescript","vala":"vala","vbnet":"vbnet","vb":"vbnet","vbscript":"vbscript","vbs":"vbscript","vbscript-html":"vbscript-html","verilog":"verilog","v":"verilog","sv":"verilog","svh":"verilog","vhdl":"vhdl","vim":"vim","x86asm":"x86asm","xl":"xl","tao":"xl","xquery":"xquery","xpath":"xquery","xq":"xquery","zephir":"zephir","zep":"zephir"}} | ||
{"languages":["1c","abnf","accesslog","actionscript","ada","angelscript","apache","applescript","arcade","cpp","arduino","armasm","xml","asciidoc","aspectj","autohotkey","autoit","avrasm","awk","axapta","bash","basic","bnf","brainfuck","cal","capnproto","ceylon","clean","clojure","clojure-repl","cmake","coffeescript","coq","cos","crmsh","crystal","cs","csp","css","d","markdown","dart","delphi","diff","django","dns","dockerfile","dos","dsconfig","dts","dust","ebnf","elixir","elm","ruby","erb","erlang-repl","erlang","excel","fix","flix","fortran","fsharp","gams","gauss","gcode","gherkin","glsl","gml","go","golo","gradle","groovy","haml","handlebars","haskell","haxe","hsp","htmlbars","http","hy","inform7","ini","irpf90","isbl","java","javascript","jboss-cli","json","julia","julia-repl","kotlin","lasso","ldif","leaf","less","lisp","livecodeserver","livescript","llvm","lsl","lua","makefile","mathematica","matlab","maxima","mel","mercury","mipsasm","mizar","perl","mojolicious","monkey","moonscript","n1ql","nginx","nimrod","nix","nsis","objectivec","ocaml","openscad","oxygene","parser3","pf","pgsql","php","plaintext","pony","powershell","processing","profile","prolog","properties","protobuf","puppet","purebasic","python","q","qml","r","reasonml","rib","roboconf","routeros","rsl","ruleslanguage","rust","sas","scala","scheme","scilab","scss","shell","smali","smalltalk","sml","sqf","sql","stan","stata","step21","stylus","subunit","swift","taggerscript","yaml","tap","tcl","tex","thrift","tp","twig","typescript","vala","vbnet","vbscript","vbscript-html","verilog","vhdl","vim","x86asm","xl","xquery","zephir"],"aliases":{"1c":"1c","abnf":"abnf","accesslog":"accesslog","actionscript":"actionscript","as":"actionscript","ada":"ada","angelscript":"angelscript","asc":"angelscript","apache":"apache","apacheconf":"apache","applescript":"applescript","osascript":"applescript","arcade":"arcade","cpp":"cpp","c":"cpp","cc":"cpp","h":"cpp","c++":"cpp","h++":"cpp","hpp":"cpp","hh":"cpp","hxx":"cpp","cxx":"cpp","arduino":"arduino","armasm":"armasm","arm":"armasm","xml":"xml","html":"xml","xhtml":"xml","rss":"xml","atom":"xml","xjb":"xml","xsd":"xml","xsl":"xml","plist":"xml","wsf":"xml","asciidoc":"asciidoc","adoc":"asciidoc","aspectj":"aspectj","autohotkey":"autohotkey","ahk":"autohotkey","autoit":"autoit","avrasm":"avrasm","awk":"awk","axapta":"axapta","bash":"bash","sh":"bash","zsh":"bash","basic":"basic","bnf":"bnf","brainfuck":"brainfuck","bf":"brainfuck","cal":"cal","capnproto":"capnproto","capnp":"capnproto","ceylon":"ceylon","clean":"clean","icl":"clean","dcl":"clean","clojure":"clojure","clj":"clojure","clojure-repl":"clojure-repl","cmake":"cmake","cmake.in":"cmake","coffeescript":"coffeescript","coffee":"coffeescript","cson":"coffeescript","iced":"coffeescript","coq":"coq","cos":"cos","cls":"cos","crmsh":"crmsh","crm":"crmsh","pcmk":"crmsh","crystal":"crystal","cr":"crystal","cs":"cs","csharp":"cs","c#":"cs","csp":"csp","css":"css","d":"d","markdown":"markdown","md":"markdown","mkdown":"markdown","mkd":"markdown","dart":"dart","delphi":"delphi","dpr":"delphi","dfm":"delphi","pas":"delphi","pascal":"delphi","freepascal":"delphi","lazarus":"delphi","lpr":"delphi","lfm":"delphi","diff":"diff","patch":"diff","django":"django","jinja":"django","dns":"dns","bind":"dns","zone":"dns","dockerfile":"dockerfile","docker":"dockerfile","dos":"dos","bat":"dos","cmd":"dos","dsconfig":"dsconfig","dts":"dts","dust":"dust","dst":"dust","ebnf":"ebnf","elixir":"elixir","elm":"elm","ruby":"ruby","rb":"ruby","gemspec":"ruby","podspec":"ruby","thor":"ruby","irb":"ruby","erb":"erb","erlang-repl":"erlang-repl","erlang":"erlang","erl":"erlang","excel":"excel","xlsx":"excel","xls":"excel","fix":"fix","flix":"flix","fortran":"fortran","f90":"fortran","f95":"fortran","fsharp":"fsharp","fs":"fsharp","gams":"gams","gms":"gams","gauss":"gauss","gss":"gauss","gcode":"gcode","nc":"gcode","gherkin":"gherkin","feature":"gherkin","glsl":"glsl","gml":"gml","GML":"gml","go":"go","golang":"go","golo":"golo","gradle":"gradle","groovy":"groovy","haml":"haml","handlebars":"handlebars","hbs":"handlebars","html.hbs":"handlebars","html.handlebars":"handlebars","haskell":"haskell","hs":"haskell","haxe":"haxe","hx":"haxe","hsp":"hsp","htmlbars":"htmlbars","http":"http","https":"http","hy":"hy","hylang":"hy","inform7":"inform7","i7":"inform7","ini":"ini","toml":"ini","irpf90":"irpf90","isbl":"isbl","java":"java","jsp":"java","javascript":"javascript","js":"javascript","jsx":"javascript","jboss-cli":"jboss-cli","wildfly-cli":"jboss-cli","json":"json","julia":"julia","julia-repl":"julia-repl","kotlin":"kotlin","kt":"kotlin","lasso":"lasso","ls":"livescript","lassoscript":"lasso","ldif":"ldif","leaf":"leaf","less":"less","lisp":"lisp","livecodeserver":"livecodeserver","livescript":"livescript","llvm":"llvm","lsl":"lsl","lua":"lua","makefile":"makefile","mk":"makefile","mak":"makefile","mathematica":"mathematica","mma":"mathematica","wl":"mathematica","matlab":"matlab","maxima":"maxima","mel":"mel","mercury":"mercury","m":"mercury","moo":"mercury","mipsasm":"mipsasm","mips":"mipsasm","mizar":"mizar","perl":"perl","pl":"perl","pm":"perl","mojolicious":"mojolicious","monkey":"monkey","moonscript":"moonscript","moon":"moonscript","n1ql":"n1ql","nginx":"nginx","nginxconf":"nginx","nimrod":"nimrod","nim":"nimrod","nix":"nix","nixos":"nix","nsis":"nsis","objectivec":"objectivec","mm":"objectivec","objc":"objectivec","obj-c":"objectivec","ocaml":"ocaml","ml":"sml","openscad":"openscad","scad":"openscad","oxygene":"oxygene","parser3":"parser3","pf":"pf","pf.conf":"pf","pgsql":"pgsql","postgres":"pgsql","postgresql":"pgsql","php":"php","php3":"php","php4":"php","php5":"php","php6":"php","php7":"php","plaintext":"plaintext","pony":"pony","powershell":"powershell","ps":"powershell","processing":"processing","profile":"profile","prolog":"prolog","properties":"properties","protobuf":"protobuf","puppet":"puppet","pp":"puppet","purebasic":"purebasic","pb":"purebasic","pbi":"purebasic","python":"python","py":"python","gyp":"python","ipython":"python","q":"q","k":"q","kdb":"q","qml":"qml","qt":"qml","r":"r","reasonml":"reasonml","re":"reasonml","rib":"rib","roboconf":"roboconf","graph":"roboconf","instances":"roboconf","routeros":"routeros","mikrotik":"routeros","rsl":"rsl","ruleslanguage":"ruleslanguage","rust":"rust","rs":"rust","sas":"sas","SAS":"sas","scala":"scala","scheme":"scheme","scilab":"scilab","sci":"scilab","scss":"scss","shell":"shell","console":"shell","smali":"smali","smalltalk":"smalltalk","st":"smalltalk","sml":"sml","sqf":"sqf","sql":"sql","stan":"stan","stata":"stata","do":"stata","ado":"stata","step21":"step21","p21":"step21","step":"step21","stp":"step21","stylus":"stylus","styl":"stylus","subunit":"subunit","swift":"swift","taggerscript":"taggerscript","yaml":"yaml","yml":"yaml","YAML":"yaml","tap":"tap","tcl":"tcl","tk":"tcl","tex":"tex","thrift":"thrift","tp":"tp","twig":"twig","craftcms":"twig","typescript":"typescript","ts":"typescript","vala":"vala","vbnet":"vbnet","vb":"vbnet","vbscript":"vbscript","vbs":"vbscript","vbscript-html":"vbscript-html","verilog":"verilog","v":"verilog","sv":"verilog","svh":"verilog","vhdl":"vhdl","vim":"vim","x86asm":"x86asm","xl":"xl","tao":"xl","xquery":"xquery","xpath":"xquery","xq":"xquery","zephir":"zephir","zep":"zephir"}} |
@@ -6,16 +6,17 @@ 'use strict'; | ||
function encodeURL(str) { | ||
if (parse(str).protocol) { | ||
const parsed = parse(str); | ||
if (parsed.protocol) { | ||
const obj = Object.assign({}, { | ||
auth: parse(str).auth, | ||
protocol: parse(str).protocol, | ||
host: parse(str).host, | ||
pathname: encodeURI(decodeURI(parse(str).pathname)) | ||
auth: parsed.auth, | ||
protocol: parsed.protocol, | ||
host: parsed.host, | ||
pathname: encodeURI(safeDecodeURI(parsed.pathname)) | ||
}); | ||
if (parse(str).hash) { | ||
Object.assign(obj, { hash: encodeURI(decodeURI(parse(str).hash)) }); | ||
if (parsed.hash) { | ||
Object.assign(obj, { hash: encodeURI(safeDecodeURI(parsed.hash)) }); | ||
} | ||
if (parse(str).search) { | ||
Object.assign(obj, { search: encodeURI(decodeURI(parse(str).search)) }); | ||
if (parsed.search) { | ||
Object.assign(obj, { search: encodeURI(safeDecodeURI(parsed.search)) }); | ||
} | ||
@@ -26,5 +27,13 @@ | ||
return encodeURI(str); | ||
return encodeURI(safeDecodeURI(str)); | ||
} | ||
function safeDecodeURI(str) { | ||
try { | ||
return decodeURI(str); | ||
} catch (err) { | ||
return str; | ||
} | ||
} | ||
module.exports = encodeURL; |
'use strict'; | ||
function htmlTag(tag, attrs, text) { | ||
const encodeURL = require('./encode_url'); | ||
const escapeHTML = require('./escape_html'); | ||
const regexUrl = /(cite|download|href|src|url)$/; | ||
function encSrcset(str) { | ||
str.split(' ') | ||
.forEach(subStr => { | ||
if (subStr.match(/\S/)) { | ||
subStr = subStr.trim(); | ||
str = str.replace(subStr, encodeURI(subStr)); | ||
} | ||
}); | ||
return str; | ||
} | ||
function htmlTag(tag, attrs, text, escape = true) { | ||
if (!tag) throw new TypeError('tag is required!'); | ||
let result = `<${tag}`; | ||
let result = `<${escapeHTML(tag)}`; | ||
for (const i in attrs) { | ||
if (attrs[i] != null) result += ` ${i}="${attrs[i]}"`; | ||
if (attrs[i] === null || typeof attrs[i] === 'undefined') result += ''; | ||
else { | ||
if (i.match(regexUrl)) result += ` ${escapeHTML(i)}="${encodeURL(attrs[i])}"`; | ||
else if (i.endsWith('srcset')) result += ` ${escapeHTML(i)}="${encSrcset(attrs[i])}"`; | ||
else result += ` ${escapeHTML(i)}="${escapeHTML(String(attrs[i]))}"`; | ||
} | ||
} | ||
result += text == null ? '>' : `>${text}</${tag}>`; | ||
if (escape && text && tag !== 'style') text = escapeHTML(String(text)); | ||
if (text && tag === 'style') { | ||
text = text.replace(/url\(['"](.*?)['"]\)/gi, (urlAttr, url) => { | ||
return `url("${encodeURL(url)}")`; | ||
}); | ||
} | ||
if (text === null || typeof text === 'undefined') result += '>'; | ||
else result += `>${text}</${escapeHTML(tag)}>`; | ||
return result; | ||
@@ -15,0 +43,0 @@ } |
@@ -9,2 +9,3 @@ 'use strict'; | ||
exports.createSha1Hash = hash.createSha1Hash; | ||
exports.decodeURL = require('./decode_url'); | ||
exports.encodeURL = require('./encode_url'); | ||
@@ -11,0 +12,0 @@ exports.escapeDiacritic = require('./escape_diacritic'); |
{ | ||
"name": "hexo-util", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Utilities for Hexo.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
@@ -64,2 +64,17 @@ # hexo-util | ||
### decodeURL(str) | ||
Decode [encoded](https://en.wikipedia.org/wiki/Percent-encoding) URL or path. An alternative to the native [`decodeURI()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI) function, with added ability to decode [punycoded](https://en.wikipedia.org/wiki/Punycode) domain. | ||
``` js | ||
decodeURL('http://foo.com/b%C3%A1r') | ||
// http://foo.com/bár | ||
decodeURL('http://xn--br-mia.com/baz') | ||
// http://bár.com/baz | ||
decodeURL('/foo/b%C3%A1r/') | ||
// /foo/bár/ | ||
``` | ||
### encodeURL(str) | ||
@@ -169,6 +184,13 @@ | ||
### htmlTag(tag, attrs, text) | ||
### htmlTag(tag, attrs, text, escape) | ||
Creates a html tag. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`tag` | Tag / element name | | ||
`attrs` | Attribute(s) and its value.<br>Value is always [escaped](#escapehtmlstr), URL is always [encoded](#encodeurlstr). | | ||
`text` | Text, the value is always escaped<br>_(except for `<style>` tag)_ | | ||
`escape` | Whether to escape the text | true | ||
``` js | ||
@@ -180,2 +202,12 @@ htmlTag('img', {src: 'example.png'}) | ||
// <a href="http://hexo.io/">Hexo</a> | ||
htmlTag('link', {href: 'http://foo.com/'}, '<a>bar</a>') | ||
// <a href="http://foo.com/"><bar></a> | ||
htmlTag('a', {href: 'http://foo.com/'}, '<b>bold</b>', false) | ||
// <a href="http://foo.com/"><b>bold</b></a> | ||
/* text value of <style> won't be escaped, url is still encoded */ | ||
htmlTag('style', {}, 'p { content: "<"; background: url("bár.jpg"); }') | ||
// <style>p { content: "<"; background: url("b%C3%A1r.jpg"); }</style> | ||
``` | ||
@@ -356,4 +388,4 @@ | ||
/* Override option | ||
* you could also enable it to output a relative link, | ||
* even when `relative_link` is disabled and vice versa. | ||
* you could also disable it to output a non-relative link, | ||
* even when `relative_link` is enabled and vice versa. | ||
*/ | ||
@@ -360,0 +392,0 @@ url_for('/css/style.css', {relative: false}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68020
29
1267
455