Skip to content

Commit

Permalink
Add render function for Inky html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
snics committed May 22, 2018
1 parent b6ac9c9 commit 6ee48d5
Show file tree
Hide file tree
Showing 4 changed files with 708 additions and 182 deletions.
24 changes: 24 additions & 0 deletions lib/__tests__/render.test.js
@@ -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));
});
});
});
22 changes: 22 additions & 0 deletions lib/render.js
@@ -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
};

0 comments on commit 6ee48d5

Please sign in to comment.