Skip to content

Commit

Permalink
Preserve XHTML formatting in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
gakimball committed Mar 21, 2016
1 parent b8f7a97 commit 9bbed08
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var html = cheerio.load(input)
// Now unleash the fury
var convertedHtml = i.releaseTheKraken(html);

// The return value is a Cheerio object. Get the string value with .html()
convertedHtml.html();
// The return value is a Cheerio object. Get the string value with .xml()
// Note that we use .xml() and not .html(), because HTML emails should be written as XHTML
convertedHtml.xml();
```
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function(opts, cb) {
function transform() {
return through.obj(function(file, enc, callback) {
var html = cheerio.load(file.contents.toString());
var convertedHtml = inky.releaseTheKraken(html).html();
var convertedHtml = inky.releaseTheKraken(html).xml();

file.contents = new Buffer(convertedHtml);

Expand Down
2 changes: 1 addition & 1 deletion lib/componentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var $ = require('cheerio');
* @returns {string} HTML converted from a custom element to table syntax.
*/
module.exports = function(element) {
var inner = element.html();
var inner = element.xml();

switch (element[0].name) {
// <column>
Expand Down
7 changes: 7 additions & 0 deletions test/inky.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ describe('Inky', () => {

compare(input, expected);
});

it.only('preserves self-closing tags', () => {
var input = '<br/>';
var expected = '<br/>';

compare(input, expected);
});
});

describe('Inky wrappers', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var htmlEqual = require('assert-html-equal');
module.exports = function compare(input, expected) {
var inky = new Inky();
var $ = cheerio.load(input);
var output = inky.releaseTheKraken($).html();
var output = inky.releaseTheKraken($).xml();

htmlEqual(output, expected);
}

0 comments on commit 9bbed08

Please sign in to comment.