Socket
Socket
Sign inDemoInstall

htmlprocessor

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlprocessor - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

68

lib/blocktypes.js

@@ -15,10 +15,70 @@ /*

var utils = require('./utils');
var url = require('url');
function obtainStyles(block, html, baseDir) {
var hrefRegEx = /.*href=[\'"]([^\'"]*)[\'"].*/gi;
return obtainAssets(hrefRegEx, block, html, baseDir);
}
function obtainScripts(block, html, baseDir) {
var srcRegEx = /.*src=[\'"]([^\'"]*)[\'"].*/gi;
return obtainAssets(srcRegEx, block, html, baseDir);
}
function obtainAssets(assetPathRegEx, block, html, baseDir) {
var assetpath,
fileContent,
match,
assets = [];
if (block.asset) {
assetpath = path.join(baseDir, block.asset);
fileContent = fs.readFileSync(assetpath).toString();
return [fileContent];
}
while ((match = assetPathRegEx.exec(html)) !== null) {
assetpath = path.join(baseDir, match[1]);
fileContent = fs.readFileSync(assetpath).toString();
assets.push(fileContent);
}
return assets;
}
// Define default block types
module.exports = {
css: function (content, block, blockLine, blockContent) {
css: function (content, block, blockLine, blockContent, filepath) {
var replacement,
styles = [];
if (block.inline) {
styles = obtainStyles(block, blockContent, this.options.includeBase || path.dirname(filepath));
replacement = block.indent + '<style>' + this.linefeed +
styles.join(this.linefeed) +
block.indent + '</style>';
return content.split(blockLine).join(replacement);
}
return content.replace(blockLine, block.indent + '<link rel="stylesheet" href="' + block.asset + '">');
},
js: function (content, block, blockLine, blockContent) {
js: function (content, block, blockLine, blockContent, filepath) {
var replacement,
scripts = [];
if (block.inline) {
scripts = obtainScripts(block, blockContent, this.options.includeBase || path.dirname(filepath));
replacement = block.indent + '<script>' + this.linefeed +
scripts.join(this.linefeed) +
block.indent + '</script>';
return content.split(blockLine).join(replacement);
}
return content.replace(blockLine, block.indent + '<script src="' + block.asset + '"><\/script>');

@@ -35,3 +95,3 @@ },

// Check if only the path was provided to leave the original asset name intact
asset = (!path.extname(block.asset) && /\//.test(block.asset)) ? path.join(block.asset, path.basename(asset)) : block.asset;
asset = (!path.extname(block.asset) && /\//.test(block.asset)) ? url.resolve(block.asset, path.basename(asset)) : block.asset;

@@ -83,3 +143,3 @@ replaced = true;

// Add indentation and remove any last new line
fileContent = block.indent + fileContent.replace(/\n$/, '');
fileContent = block.indent + fileContent.replace(/\r\n$/, '');

@@ -86,0 +146,0 @@ while ((i = content.indexOf(blockLine)) !== -1) {

7

lib/htmlprocessor.js

@@ -24,3 +24,3 @@ /*

*/
var regStart = new RegExp('<!--\\s*' + marker + ':(\\[?[\\w-]+\\]?)(?::([\\w,]+))?(?:\\s*([^\\s]+)\\s*-->)*');
var regStart = new RegExp('<!--\\s*' + marker + ':(\\[?[\\w-]+\\]?)(?::([\\w,]+))?(?:\\s*(inline)\\s)?(?:\\s*([^\\s]+)\\s*-->)*');

@@ -48,3 +48,4 @@ // <!-- /build -->

targets: !!build[2] ? build[2].split(',') : null,
asset: build[3],
inline: !!build[3],
asset: build[4],
indent: /^\s*/.exec(line)[0],

@@ -124,3 +125,3 @@ raw: []

var blockRegExp = utils.blockToRegExp(blockLine);
var result = content.replace(blockRegExp, '\n\n' + blockContent);
var result = content.replace(blockRegExp, '\r\n\r\n' + blockContent);

@@ -127,0 +128,0 @@ return result;

@@ -34,3 +34,3 @@ /*

}
return contents;
return contents.replace(/\r\n|\r/g, '\n');
};

@@ -37,0 +37,0 @@

{
"name": "htmlprocessor",
"description": "Process html file using special comments",
"version": "0.1.8",
"version": "0.1.9",
"author": {

@@ -6,0 +6,0 @@ "name": "Denis Ciccale",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc