html-code-gen
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -6,3 +6,3 @@ /* | ||
var print = reuqire('./lib/print'); | ||
var print = require('./lib/print'); | ||
@@ -9,0 +9,0 @@ module.exports = { |
@@ -34,34 +34,7 @@ /** | ||
var printVoidElementNode = function(info, node, condition){ | ||
var printVoidElementNode = function(info, node, condition, opt){ | ||
return util.format('<${tag}${attributes}>', info); | ||
}; | ||
var printRawTextElementNode = function(info, node, condition){ | ||
var content = node.childNodes[0].textContent.replace(/(^\s*\n)|(\n\s*$)/g, ''); | ||
return [ | ||
info.start, | ||
content, | ||
info.end | ||
].join(info.sep); | ||
}; | ||
var printNormalElementNode = function(info, node, condition){ | ||
// children | ||
var children = array.map.call(node.childNodes, function(childNode, i){ | ||
return print(childNode, newOpt); | ||
}); | ||
// inner content | ||
var content = ( | ||
condition.noFormat ? | ||
children : | ||
children.filter(function(child){ | ||
return child.trim() | ||
}).map(function(child){ | ||
return info.innerIndent + child; | ||
}) | ||
).join(info.sep); | ||
// format & output | ||
var packageElement = function(info, content){ | ||
return ( | ||
@@ -81,2 +54,32 @@ content ? | ||
var removeSpaceAround = function(content){ | ||
return content.replace(/(^\s*\n)|(\n\s*$)/g, ''); | ||
}; | ||
var printRawTextElementNode = function(info, node, condition, opt){ | ||
var formatter = opt.formatter[info.tag] || removeSpaceAround; | ||
var content = node.childNodes.length ? | ||
formatter(node.childNodes[0].textContent, node, opt, { | ||
indent: indent | ||
}) : | ||
''; | ||
return packageElement(info, content); | ||
}; | ||
var printNormalElementNode = function(info, node, condition, opt){ | ||
var content = ( | ||
condition.noFormat ? | ||
info.children : | ||
info.children.filter(function(child){ | ||
return child.trim() | ||
}).map(function(child){ | ||
return info.innerIndent + child; | ||
}) | ||
).join(info.sep); | ||
return packageElement(info, content); | ||
}; | ||
// format method for general element | ||
@@ -95,3 +98,3 @@ var printElementNode = function(node, opt){ | ||
isHtml: tag === 'html', | ||
noFormat: opt['no-format'] || util.isIn(tag, opt['no-format-tag']), | ||
noFormat: opt['no-format'] || util.isIn(tag, opt['no-format-tag']) || !node.childNodes.length, | ||
isRawText: util.isIn(tag, tagTypeMap['raw-text']) | ||
@@ -108,3 +111,3 @@ }; | ||
// void elements | ||
if(condition.isVoid) return printVoidElementNode(info, node, condition); | ||
if(condition.isVoid) return printVoidElementNode(info, node, condition, opt); | ||
@@ -128,7 +131,14 @@ // new opt for next-level (child) nodes | ||
// raw text ( 'script' / 'style' ) | ||
if(condition.isRawText) return printRawTextElementNode(info, node, condition); | ||
if(condition.isRawText) return printRawTextElementNode(info, node, condition, opt); | ||
return printNormalElementNode(info, node, condition); | ||
// children | ||
util.extend(info, { | ||
children: array.map.call(node.childNodes, function(childNode, i){ | ||
return print(childNode, newOpt); | ||
}) | ||
}); | ||
return printNormalElementNode(info, node, condition, opt); | ||
}; | ||
module.exports = printElementNode; |
{ | ||
"name": "html-code-gen", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "", | ||
"main": "index.js", | ||
"browserify": "index.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^8.1.1", | ||
"coveralls": "^2.11.2", | ||
@@ -14,2 +16,3 @@ "htmlcs": "0.0.3", | ||
"scripts": { | ||
"browserify": "browserify -r ./index.js:html-code-gen > browser/html-code-gen.js", | ||
"test": "istanbul cover jasmine-node --captureExceptions test/**/*.spec.js", | ||
@@ -16,0 +19,0 @@ "coveralls": "cat ./coverage/lcov.info | coveralls" |
@@ -14,4 +14,12 @@ html-code-gen | ||
npm install html-code-gen | ||
* nodejs | ||
npm install html-code-gen | ||
* browser | ||
```html | ||
<script src="html-code-gen/browser/html-code-gen.js"></script> | ||
``` | ||
### Usage | ||
@@ -33,5 +41,5 @@ | ||
* `max-char`: max char num in one line | ||
* `max-char`: max char num in one line (TODO) | ||
default: `80` (TODO) | ||
default: `80` | ||
@@ -38,0 +46,0 @@ * `no-format-tag`: tags whose content should not be formatted |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
82615
16
618
59
5
2