diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..77e0f8c --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +attic diff --git a/lib/html2jade.js b/lib/html2jade.js index de29439..2673f41 100644 --- a/lib/html2jade.js +++ b/lib/html2jade.js @@ -3,7 +3,9 @@ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; Parser = (function() { function Parser(options) { - this.options = options != null ? options : {}; + if (options == null) { + options = {}; + } this.jsdom = require('jsdom'); } Parser.prototype.parse = function(arg, cb) { @@ -23,9 +25,13 @@ })(); Helper = (function() { function Helper(options) { - var _base, _ref; - this.options = options != null ? options : {}; - (_ref = (_base = this.options).wrapLength) != null ? _ref : _base.wrapLength = 80; + var _ref, _ref2; + if (options == null) { + options = {}; + } + this.wrapLength = (_ref = options.wrapLength) != null ? _ref : 80; + this.scalate = (_ref2 = options.scalate) != null ? _ref2 : false; + this.attrSep = this.scalate ? ' ' : ', '; } Helper.prototype.tagHead = function(node) { var classes, result; @@ -59,7 +65,7 @@ } } if (result.length > 0) { - return '(' + result.join(', ') + ')'; + return '(' + result.join(this.attrSep) + ')'; } else { return ''; } @@ -73,7 +79,7 @@ return null; } else { data = node.firstChild.data; - if (data.length > this.options.wrapLength || data.match(/\r|\n/)) { + if (data.length > this.wrapLength || data.match(/\r|\n/)) { return null; } else { return data; @@ -145,7 +151,7 @@ line = line ? line.trim() : ''; } if (line && line.length > 0) { - if (!wrap || line.length <= this.options.wrapLength) { + if (!wrap || line.length <= this.wrapLength) { return output.writeln(prefix + line); } else { lines = this.breakLine(line); @@ -167,7 +173,7 @@ line = ''; while (words.length) { word = words.shift(); - if (line.length + word.length > this.options.wrapLength) { + if (line.length + word.length > this.wrapLength) { lines.push(line); line = word; } else if (line.length) { @@ -204,9 +210,12 @@ }; Converter = (function() { function Converter(options) { - var _base, _ref; - this.options = options != null ? options : {}; - this.helper = (_ref = (_base = this.options).helper) != null ? _ref : _base.helper = new Helper(this.options); + var _ref, _ref2; + if (options == null) { + options = {}; + } + this.scalate = (_ref = options.scalate) != null ? _ref : false; + this.helper = (_ref2 = options.helper) != null ? _ref2 : new Helper(options); } Converter.prototype.document = function(document, output) { var docTypeName, doctype, publicId, systemId; @@ -230,13 +239,22 @@ }; Converter.prototype.element = function(node, output) { var firstline, tagAttr, tagHead, tagName, tagText; + if (!(node != null ? node.tagName : void 0)) { + return; + } + console.log("tag: " + node.tagName); tagName = node.tagName.toLowerCase(); tagHead = this.helper.tagHead(node); tagAttr = this.helper.tagAttr(node); tagText = this.helper.tagText(node); - if (['script', 'style'].indexOf(tagName) !== -1) { - output.writeln(tagHead + tagAttr); - return this.helper.writeTextContent(node, output, false, false, false); + if (tagName === 'script' || tagName === 'style') { + if (!this.scalate || node.hasAttribute('src')) { + output.writeln(tagHead + tagAttr); + return this.helper.writeTextContent(node, output, false, false, false); + } else { + output.writeln(tagName === 'script' ? ':javascript' : ':css'); + return this.helper.writeTextContent(node, output, false, false, false); + } } else if (['pre'].indexOf(tagName) !== -1) { output.writeln(tagHead + tagAttr + '.'); output.enter(); @@ -262,6 +280,9 @@ output.writeln(); return output.leave(); } else if (tagText) { + if (tagText.length > 0 && tagText.charAt(0) === '=') { + tagText = '\\' + tagText; + } return output.writeln(tagHead + tagAttr + ' ' + tagText); } else { output.writeln(tagHead + tagAttr); @@ -286,6 +307,7 @@ return output.leave(); }; Converter.prototype.text = function(node, output) { + console.log("text: " + node.data); node.normalize(); return this.helper.writeText(node, output); }; @@ -328,7 +350,9 @@ if (indent == null) { indent = true; } - data != null ? data : data = ''; + if (data == null) { + data = ''; + } if (indent) { return this.stream.write(this.indents + data); } else { @@ -339,7 +363,9 @@ if (indent == null) { indent = true; } - data != null ? data : data = ''; + if (data == null) { + data = ''; + } if (indent) { return this.stream.write(this.indents + data + '\n'); } else { @@ -354,15 +380,23 @@ exports.Helper = Helper; exports.convert = function(input, output, options) { var _ref; - options != null ? options : options = {}; - (_ref = options.parser) != null ? _ref : options.parser = new Parser(options); + if (options == null) { + options = {}; + } + if ((_ref = options.parser) == null) { + options.parser = new Parser(options); + } return options.parser.parse(input, function(errors, window) { - var _ref; + var _ref2; if (errors != null ? errors.length : void 0) { return errors; } else { - output != null ? output : output = new Output(process.stdout); - (_ref = options.converter) != null ? _ref : options.converter = new Converter(options); + if (output == null) { + output = new Output(process.stdout); + } + if ((_ref2 = options.converter) == null) { + options.converter = new Converter(options); + } options.converter.document(window.document, output); return null; } diff --git a/package.json b/package.json index 05a1cff..184c80a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "html2jade", "description": "HTML to Jade conversion tool", - "version": "0.0.5", + "version": "0.0.6", "author": "Don Park ", "repository": "git://github.com/donpark/html2jade.git", "main": "./lib/html2jade.js",