hexo-util
Advanced tools
Comparing version 1.3.1 to 1.4.0
'use strict'; | ||
const unescapeHTML = require('./unescape_html'); | ||
const htmlEntityMap = { | ||
@@ -15,2 +17,4 @@ '&': '&', | ||
str = unescapeHTML(str); | ||
// http://stackoverflow.com/a/12034334 | ||
@@ -17,0 +21,0 @@ return str.replace(/[&<>"'/]/g, a => htmlEntityMap[a]); |
@@ -27,2 +27,3 @@ 'use strict'; | ||
if (i.match(regexUrl)) result += ` ${escapeHTML(i)}="${encodeURL(attrs[i])}"`; | ||
else if (attrs[i] === true || i === attrs[i]) result += ` ${escapeHTML(i)}`; | ||
else if (i.match(/srcset$/i)) result += ` ${escapeHTML(i)}="${encSrcset(attrs[i])}"`; | ||
@@ -29,0 +30,0 @@ else result += ` ${escapeHTML(i)}="${escapeHTML(String(attrs[i]))}"`; |
@@ -27,3 +27,4 @@ 'use strict'; | ||
exports.truncate = require('./truncate'); | ||
exports.unescapeHTML = require('./unescape_html'); | ||
exports.url_for = require('./url_for'); | ||
exports.wordWrap = require('./word_wrap'); |
{ | ||
"name": "hexo-util", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Utilities for Hexo.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
@@ -102,2 +102,11 @@ # hexo-util | ||
``` js | ||
escapeHTML('<p>Hello "world".</p>') | ||
// <p>Hello "world".</p> | ||
/* support escaped characters */ | ||
escapeHTML('<foo>bar</foo>') | ||
// <foo>bar</foo> | ||
``` | ||
### escapeRegex(str) | ||
@@ -211,2 +220,6 @@ | ||
// <style>p { content: "<"; background: url("b%C3%A1r.jpg"); }</style> | ||
/* support script tag with async/defer */ | ||
htmlTag('script', {src: '/foo.js', async: true}, '') | ||
// <script src="/foo.js" async></script> | ||
``` | ||
@@ -356,2 +369,11 @@ | ||
### unescapeHTML(str) | ||
Unescapes HTML entities in a string. | ||
``` js | ||
unescapeHTML('<p>Hello "world".</p>') | ||
// <p>Hello "world".</p> | ||
``` | ||
### url_for(path, [option]) | ||
@@ -397,3 +419,3 @@ | ||
Following utilities require `bind(hexo)` / `bind(this)` to parse the user config when initializing: | ||
Following utilities require `bind(hexo)` / `bind(this)` / `call(hexo, input)` / `call(this, input)` to parse the user config when initializing: | ||
- [`full_url_for()`](#full_url_forpath) | ||
@@ -403,3 +425,3 @@ - [`url_for()`](#url_forpath) | ||
Below examples demonstrate four approaches of creating a [helper](https://hexo.io/api/helper) (each example is separated by `/******/`), | ||
Below examples demonstrate different approaches to creating a [helper](https://hexo.io/api/helper) (each example is separated by `/******/`), | ||
@@ -439,2 +461,12 @@ ``` js | ||
/******/ | ||
// Function.call() approach also works | ||
const {url_for} = require('hexo-util'); | ||
module.exports = function(str) { | ||
return url_for.call(this, str); | ||
} | ||
hexo.extend.helper.register('test_url', require('./test_url')); | ||
/******/ | ||
// Separating functions into individual files | ||
@@ -441,0 +473,0 @@ // Each file has multiple functions |
69524
30
1288
487