@ridi/epub-parser
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -6,2 +6,7 @@ 'use strict'; | ||
}); | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
exports.default = cssLoader; | ||
@@ -30,2 +35,16 @@ | ||
function getUnwrappingTagList(namespace, options) { | ||
if ((0, _parserCore.isExists)(namespace)) { | ||
var extractBody = options.extractBody; | ||
if (extractBody === true) { | ||
return ['html']; | ||
} | ||
if ((0, _parserCore.isFunc)(extractBody)) { | ||
return ['html', 'body']; | ||
} | ||
} | ||
return []; | ||
} | ||
function handleRulePrelude(selectorList, options, cssItem) { | ||
@@ -36,5 +55,9 @@ if (!(0, _parserCore.isExists)(selectorList.children)) { | ||
var namespace = cssItem.namespace; | ||
var unwrappingTagList = getUnwrappingTagList(namespace, options); | ||
selectorList.children.each(function (selector, item, list) { | ||
// eslint-disable-line | ||
var shouldRemove = false; | ||
var shouldUnwrap = false; | ||
_cssTree2.default.walk(selector, function (node) { | ||
@@ -58,2 +81,4 @@ // eslint-disable-line | ||
shouldRemove = true; | ||
} else if ((0, _parserCore.stringContains)(unwrappingTagList, name)) { | ||
shouldUnwrap = true; | ||
} | ||
@@ -73,5 +98,22 @@ } else if (type === Types.ID_SELECTOR) { | ||
list.remove(item); | ||
} else if ((0, _parserCore.isExists)(cssItem.namespace)) { | ||
} else if ((0, _parserCore.isExists)(namespace)) { | ||
var namespaceData = { type: Types.CLASS_SELECTOR, name: namespace }; | ||
if (shouldUnwrap) { | ||
var array = selector.children.toArray(); | ||
if (array.length > 1) { | ||
var _array = (0, _slicedToArray3.default)(array, 1), | ||
head = _array[0]; | ||
if ((0, _parserCore.stringContains)(unwrappingTagList, head.name)) { | ||
selector.children.shift(); | ||
selector.children.prependData(namespaceData); | ||
return; | ||
} | ||
} else { | ||
selector.children = new _cssTree.List().fromArray([namespaceData]); | ||
return; | ||
} | ||
} | ||
selector.children.prependData({ type: Types.WHITE_SPACE, value: ' ' }); | ||
selector.children.prependData({ type: Types.CLASS_SELECTOR, name: cssItem.namespace }); | ||
selector.children.prependData(namespaceData); | ||
} | ||
@@ -78,0 +120,0 @@ }); |
{ | ||
"name": "@ridi/epub-parser", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Common EPUB2 data parser for Ridibooks services", | ||
@@ -31,3 +31,3 @@ "author": { | ||
"dependencies": { | ||
"@ridi/parser-core": "^0.6.0", | ||
"@ridi/parser-core": "^0.6.1", | ||
"css-tree": "^1.0.0-alpha.29", | ||
@@ -34,0 +34,0 @@ "fast-xml-parser": "^3.12.17", |
@@ -9,3 +9,2 @@ # @ridi/epub-parser | ||
[![NPM total downloads](https://img.shields.io/npm/dt/%40ridi%2Fepub-parser.svg)](https://npm.im/%40ridi%2Fepub-parser) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/ridi/content-parser.svg)](https://greenkeeper.io/) | ||
@@ -12,0 +11,0 @@ ## Features |
Sorry, the diff of this file is not supported yet
118488
2443
728
Updated@ridi/parser-core@^0.6.1