From 5f52f955822deab1fd0d3ee678f499117e9b07d1 Mon Sep 17 00:00:00 2001 From: Ben Ma Date: Wed, 10 Jul 2013 14:17:19 -0700 Subject: [PATCH 1/3] Uppercase tag support added --- lib/html-to-text.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/html-to-text.js b/lib/html-to-text.js index f8329de..2b834e1 100644 --- a/lib/html-to-text.js +++ b/lib/html-to-text.js @@ -70,7 +70,7 @@ function walk(dom, options) { _.each(dom, function(elem) { switch(elem.type) { case 'tag': - switch(elem.name) { + switch(elem.name.toLowerCase()) { case 'a': result += format.anchor(elem, walk, options); break; @@ -127,4 +127,4 @@ exports.fromFile = function(file, options, callback) { exports.fromString = function(str, options) { return htmlToText(str, options || {}); -}; \ No newline at end of file +}; From e439df6f756d7e81310222eb68dfcc6cb27ea21c Mon Sep 17 00:00:00 2001 From: Ben Ma Date: Wed, 10 Jul 2013 15:10:44 -0700 Subject: [PATCH 2/3] Anchor support for id, name added --- lib/formatter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/formatter.js b/lib/formatter.js index 17bf449..73a482f 100644 --- a/lib/formatter.js +++ b/lib/formatter.js @@ -22,7 +22,11 @@ function formatHeading(elem, fn, options) { } function formatAnchor(elem, fn, options) { - return elem.attribs.href.replace(/^mailto\:/, ''); + var href = ''; + if (elem.attribs.href) { + href += elem.attribs.href.replace(/^mailto\:/, ''); + } + return href; }; function formatHorizontalLine(elem, fn, options) { @@ -135,4 +139,4 @@ exports.table = formatTable; exports.orderedList = formatOrderedList; exports.unorderedList = formatUnorderedList; exports.listItem = formatListItem; -exports.horizontalLine = formatHorizontalLine; \ No newline at end of file +exports.horizontalLine = formatHorizontalLine; From e6f252cf53252570a0712e86ad06e173339b340b Mon Sep 17 00:00:00 2001 From: Ben Ma Date: Wed, 10 Jul 2013 15:54:26 -0700 Subject: [PATCH 3/3] Walk anchor element children --- lib/formatter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/formatter.js b/lib/formatter.js index 73a482f..7557f78 100644 --- a/lib/formatter.js +++ b/lib/formatter.js @@ -26,7 +26,7 @@ function formatAnchor(elem, fn, options) { if (elem.attribs.href) { href += elem.attribs.href.replace(/^mailto\:/, ''); } - return href; + return href + fn(elem.children, options); }; function formatHorizontalLine(elem, fn, options) {