Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add render function for Inky html tags
- Loading branch information
Showing
4 changed files
with
708 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const _ = require('lodash'); | ||
const render = require('../render'); | ||
|
||
describe('render', () => { | ||
describe('loadFiles', () => { | ||
it('should display an empty array by not found files', () => { | ||
const content = '<h1>Hello Wold</h1>'; | ||
const buildContent = render._renderInky(content); | ||
|
||
expect.assertions(1); | ||
return expect(buildContent).resolves.toBe(content); | ||
}); | ||
|
||
it('should render inky tags', () => { | ||
const input = '<button href="#">Button</button>'; | ||
const output = | ||
'<table class="button"><tr><td><table><tr><td><a href="#">Button</a></td></tr></table></td></tr></table>'; // eslint-disable-line | ||
const buildContent = render._renderInky(input); | ||
|
||
expect.assertions(1); | ||
return expect(buildContent).resolves.toEqual(_.trim(output)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const Promise = require('bluebird'); | ||
const Inky = require('inky').Inky; | ||
const cheerio = require('cheerio'); | ||
|
||
const utils = require('./utils'); | ||
|
||
const _renderInky = function(htmlContent) { | ||
return new Promise(resolve => { | ||
if (!utils.hasInkyCode(htmlContent)) return resolve(htmlContent); | ||
|
||
const i = new Inky(); | ||
const html = cheerio.load(htmlContent, { xmlMode: true }); | ||
const convertedHtml = i.releaseTheKraken(html); | ||
return resolve(convertedHtml); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
_renderInky | ||
}; |
Oops, something went wrong.