diff --git a/lib/command.js b/lib/command.js index 3e92548..ebafe2a 100644 --- a/lib/command.js +++ b/lib/command.js @@ -33,7 +33,6 @@ outputPath = function(source, root) { var dir, fileName, srcDir; - fileName = path.basename(source, path.extname(source)) + extension; srcDir = path.dirname(source); dir = program.output ? path.join(program.output, root === '.' ? srcDir : srcDir.slice(root.length)) : srcDir; @@ -57,7 +56,6 @@ if (stats.isDirectory()) { return fs.readdir(source, function(err, files) { var file, index, _i, _len, _results; - if (err) { throw err; } @@ -88,7 +86,6 @@ parseHtml = function(file, input, root) { var absolute, base, debug, err, inline, output; - try { absolute = program.absolute, base = program.base, debug = program.debug, inline = program.inline; output = md(input, { @@ -121,7 +118,6 @@ writeMarkdown = function(source, markdown, root) { var mdDir, mdPath, write; - mdPath = outputPath(source, root); mdDir = path.dirname(mdPath); write = function(err) { @@ -148,7 +144,6 @@ exports.run = function() { var err, source, _i, _len, _results; - if (process.platform !== 'win32') { process.on('SIGTERM', function() { return exit(); diff --git a/lib/md.js b/lib/md.js index c1d3d37..0a6096b 100644 --- a/lib/md.js +++ b/lib/md.js @@ -58,7 +58,6 @@ padLeft = function(str, times, padStr) { var i, _i; - if (str == null) { str = ''; } @@ -91,7 +90,6 @@ HtmlParser = (function() { function HtmlParser(html, options) { var defaultValue, doc; - this.html = html != null ? html : ''; this.options = options != null ? options : {}; this.atLeft = this.atNoWS = this.atP = true; @@ -125,6 +123,12 @@ }); this.win = doc.createWindow(); } + if (this.win.Node == null) { + this.win.Node = { + ELEMENT_NODE: 1, + TEXT_NODE: 3 + }; + } } HtmlParser.prototype.append = function(str) { @@ -136,7 +140,6 @@ HtmlParser.prototype.attr = function(ele, attribute, direct) { var value; - if (direct == null) { direct = true; } @@ -152,7 +155,6 @@ HtmlParser.prototype.code = function() { var old, _this = this; - old = this.inCode; this.inCode = true; return function() { @@ -177,9 +179,8 @@ HtmlParser.prototype.isVisible = function(ele) { var display, err, properties, property, style, visibility, visible, _i, _len; - style = this.attr(ele, 'style', false); - properties = style != null ? style.match(R_HIDDEN_STYLES) : void 0; + properties = style != null ? typeof style.match === "function" ? style.match(R_HIDDEN_STYLES) : void 0 : void 0; visible = true; if (properties != null) { for (_i = 0, _len = properties.length; _i < _len; _i++) { @@ -205,7 +206,6 @@ HtmlParser.prototype.li = function() { var str; - str = this.inOrderedList ? "" + (this.order++) + ". " : '* '; str = padLeft(str, (this.listDepth - 1) * 2); return this.append(str); @@ -213,7 +213,6 @@ HtmlParser.prototype.nonPreProcess = function(str) { var value; - str = str.replace(/\n([ \t]*\n)+/g, '\n'); str = str.replace(/\n[ \t]+/g, '\n'); str = str.replace(/[ \t]+/g, ' '); @@ -228,7 +227,6 @@ HtmlParser.prototype.ol = function() { var inOrderedList, order, _this = this; - if (this.listDepth === 0) { this.p(); } @@ -262,7 +260,6 @@ HtmlParser.prototype.outputLater = function(str) { var _this = this; - return function() { return _this.output(str); }; @@ -282,7 +279,6 @@ HtmlParser.prototype.parse = function() { var container, i, link, tag, unhandledTags, _i, _len, _ref; - this.buffer = ''; if (!this.html) { return this.buffer; @@ -307,7 +303,6 @@ if (this.options.debug) { unhandledTags = ((function() { var _ref1, _results; - _ref1 = this.unhandled; _results = []; for (tag in _ref1) { @@ -326,7 +321,6 @@ HtmlParser.prototype.pre = function() { var old, _this = this; - old = this.inPre; this.inPre = true; return function() { @@ -335,8 +329,7 @@ }; HtmlParser.prototype.process = function(ele) { - var after, after1, after2, childNode, err, href, i, level, skipChildren, src, suffix, summary, title, _base, _i, _len, _ref, _ref1, _ref2; - + var after, after1, after2, childNode, err, href, i, level, skipChildren, src, suffix, summary, title, _base, _i, _len, _ref, _ref1; if (!this.isVisible(ele)) { return; } @@ -350,7 +343,6 @@ this.p(); this.output("" + (((function() { var _i, _results; - _results = []; for (i = _i = 1; 1 <= level ? _i <= level : _i >= level; i = 1 <= level ? ++_i : --_i) { _results.push('#'); @@ -450,7 +442,7 @@ if (title) { href += " \"" + title + "\""; } - suffix = this.options.inline ? "(" + href + ")" : "[" + ((_ref = (_base = this.linkMap)[href]) != null ? _ref : _base[href] = this.links.push(href) - 1) + "]"; + suffix = this.options.inline ? "(" + href + ")" : "[" + ((_base = this.linkMap)[href] != null ? (_base = this.linkMap)[href] : _base[href] = this.links.push(href) - 1) + "]"; this.output('['); this.atNoWS = true; after = this.outputLater("]" + suffix); @@ -467,7 +459,7 @@ case 'IFRAME': skipChildren = true; try { - if ((_ref1 = ele.contentDocument) != null ? _ref1.documentElement : void 0) { + if ((_ref = ele.contentDocument) != null ? _ref.documentElement : void 0) { this.process(ele.contentDocument.documentElement); } } catch (_error) { @@ -489,9 +481,9 @@ this.thrown(err, ele.tagName); } if (!skipChildren) { - _ref2 = ele.childNodes; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - childNode = _ref2[_i]; + _ref1 = ele.childNodes; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + childNode = _ref1[_i]; this.process(childNode); } } @@ -504,7 +496,6 @@ HtmlParser.prototype.pushLeft = function(str) { var old, _this = this; - old = this.left; this.left += str; if (this.atP) { @@ -537,7 +528,6 @@ HtmlParser.prototype.ul = function() { var inOrderedList, order, _this = this; - if (this.listDepth === 0) { this.p(); } diff --git a/src/md.coffee b/src/md.coffee index 40e51de..45a82eb 100644 --- a/src/md.coffee +++ b/src/md.coffee @@ -149,6 +149,12 @@ class HtmlParser url: @options.base @win = doc.createWindow() + # Create the Node constants if Node doesn't exist (i.e. when running in IE < 9). + unless @win.Node? + @win.Node = + ELEMENT_NODE: 1 + TEXT_NODE: 3 + # Append `str` to the buffer string. append: (str) -> @buffer += @last if @last? @@ -190,7 +196,7 @@ class HtmlParser # Determine whether or not the specified element is visible based on its CSS style. isVisible: (ele) -> style = @attr ele, 'style', no - properties = style?.match R_HIDDEN_STYLES + properties = style?.match?(R_HIDDEN_STYLES) visible = yes # Test all relevant CSS properties for possible hiding behaviours.