Skip to content

Commit

Permalink
Supports format blockquote (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
wong2 authored and Malte Legenhausen committed Mar 7, 2018
1 parent 1a3d878 commit 655a754
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/formatter.js
Expand Up @@ -250,6 +250,10 @@ function formatTable(elem, fn, options) {
}
}

function formatBlockquote(elem, fn, options) {
return '> ' + fn(elem.children, options) + '\n';
}

exports.text = formatText;
exports.image = formatImage;
exports.lineBreak = formatLineBreak;
Expand All @@ -261,3 +265,4 @@ exports.orderedList = formatOrderedList;
exports.unorderedList = formatUnorderedList;
exports.listItem = formatListItem;
exports.horizontalLine = formatHorizontalLine;
exports.blockquote = formatBlockquote;
3 changes: 3 additions & 0 deletions lib/html-to-text.js
Expand Up @@ -160,6 +160,9 @@ function walk(dom, options, result) {
? result + format.table(elem, walk, options)
: walk(elem.children || [], options, result);
break;
case 'blockquote':
result += format.blockquote(elem, walk, options)
break;
default:
result = walk(elem.children || [], options, result);
}
Expand Down
9 changes: 9 additions & 0 deletions test/html-to-text.js
Expand Up @@ -601,5 +601,14 @@ describe('html-to-text', function() {
testString += "</body></html>";
expect(htmlToText.fromString(testString)).to.equal(expectedResult);
});
});

describe('blockquote', function() {
it('should handle format blockquote', function() {
var testString = 'foo<blockquote>test</blockquote>bar';
var expectedResult = 'foo> test\nbar';
expect(htmlToText.fromString(testString)).to.equal(expectedResult);
})
})

});

0 comments on commit 655a754

Please sign in to comment.