style-data
Advanced tools
Comparing version 1.1.4 to 1.2.0
@@ -11,3 +11,3 @@ { | ||
"complexity": [ | ||
1, | ||
0, | ||
5 | ||
@@ -102,2 +102,3 @@ ], | ||
], | ||
"keyword-spacing": 1, | ||
"linebreak-style": [ | ||
@@ -123,3 +124,3 @@ 1, | ||
"max-statements": [ | ||
1, | ||
0, | ||
10 | ||
@@ -173,3 +174,2 @@ ], | ||
], | ||
"space-after-keywords": 1, | ||
"space-before-blocks": [ | ||
@@ -180,3 +180,2 @@ 1, | ||
"space-before-function-paren": [1, { "anonymous": "always", "named": "never" }], | ||
"space-before-keywords": [1, "always"], | ||
"space-in-parens": [1, "never"], | ||
@@ -183,0 +182,0 @@ "space-infix-ops": 1, |
67
index.js
@@ -8,17 +8,58 @@ 'use strict'; | ||
function replaceCodeBlock(html, re, block) { | ||
return html.replace(re, function () { | ||
return block; | ||
}); | ||
} | ||
module.exports = function (html, options, callback) { | ||
var results = {}, | ||
$ = cheerio.load(html, extend({ | ||
decodeEntities: false | ||
}, pick(options, [ | ||
'xmlMode', | ||
'decodeEntities', | ||
'lowerCaseTags', | ||
'lowerCaseAttributeNames', | ||
'recognizeCDATA', | ||
'recognizeSelfClosing' | ||
]))), | ||
styleDataList, | ||
styleData; | ||
codeBlocks = { | ||
EJS: { start: '<%', end: '%>' }, | ||
HBS: { start: '{{', end: '}}' } | ||
}, | ||
codeBlockLookup = [], | ||
encodeCodeBlocks = function (_html) { | ||
var __html = _html, | ||
blocks = options.codeBlocks || codeBlocks; | ||
Object.keys(blocks).forEach(function (key) { | ||
var re = new RegExp(blocks[key].start + '([\\S\\s]*?)' + blocks[key].end, 'g'); | ||
__html = __html.replace(re, function (match) { | ||
codeBlockLookup.push(match); | ||
return 'EXCS_CODE_BLOCK_' + (codeBlockLookup.length - 1) + '_'; | ||
}); | ||
}); | ||
return __html; | ||
}, | ||
decodeCodeBlocks = function (_html) { | ||
var index, re, | ||
__html = _html; | ||
for (index = 0; index < codeBlockLookup.length; index++) { | ||
re = new RegExp('EXCS_CODE_BLOCK_' + index + '_(="")?', 'gi'); | ||
__html = replaceCodeBlock(__html, re, codeBlockLookup[index]); | ||
} | ||
return __html; | ||
}, | ||
encodeEntities = function (_html) { | ||
return encodeCodeBlocks(_html); | ||
}, | ||
decodeEntities = function (_html) { | ||
return decodeCodeBlocks(_html); | ||
}, | ||
$, styleDataList, styleData; | ||
$ = cheerio.load(encodeEntities(html), extend({ | ||
decodeEntities: false | ||
}, pick(options, [ | ||
'xmlMode', | ||
'decodeEntities', | ||
'lowerCaseTags', | ||
'lowerCaseAttributeNames', | ||
'recognizeCDATA', | ||
'recognizeSelfClosing' | ||
]))); | ||
results.css = []; | ||
@@ -49,5 +90,5 @@ | ||
results.html = $.html(); | ||
results.html = decodeEntities($.html()); | ||
callback(null, results); | ||
}; |
{ | ||
"name": "style-data", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "Get the content of style tags.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -51,2 +51,9 @@ # style-data [![Build Status](https://travis-ci.org/jonkemp/style-data.svg?branch=master)](https://travis-ci.org/jonkemp/style-data) [![Coverage Status](https://coveralls.io/repos/jonkemp/style-data/badge.svg?branch=master&service=github)](https://coveralls.io/github/jonkemp/style-data?branch=master) | ||
#### options.codeBlocks | ||
Type: `Object` | ||
Default: `{ EJS: { start: '<%', end: '%>' }, HBS: { start: '{{', end: '}}' } }` | ||
An object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during parsing. For example, Handlebars (hbs) templates are `HBS: {start: '{{', end: '}}'}`. Note that `codeBlocks` is a dictionary which can contain many different code blocks, so don't do `codeBlocks: {...}` do `codeBlocks.myBlock = {...}`. | ||
### cheerio options | ||
@@ -53,0 +60,0 @@ |
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
10147
257
69