html-to-article-json
Version:
Converting HTML to article-json
32 lines (24 loc) • 751 B
JavaScript
import generateFunction from 'generate-function';
import getTextFormattings from '../text-formattings';
export default opts => {
const textFormattings = getTextFormattings(opts);
let fn = generateFunction();
const renderTextOpts = textFormattings.reduce((opts, row) => {
opts[row.property] = row.get;
if (row.classProperty) {
opts[row.classProperty] = row.getClass;
}
return opts;
}, {});
fn = fn('function text (opts, elm) {')('return {');
fn = fn(' type: \'text\',');
Object.keys(renderTextOpts).forEach(key => {
fn = fn(
' %s: opts[\'%s\'] || renderTextOpts[\'%s\'](elm),',
key, key, key);
});
fn = fn('};')('}');
return fn.toFunction({
renderTextOpts: renderTextOpts
});
};