How to use the juice.inlineContent function in juice

To help you get started, we’ve selected a few juice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flutter-view / flutter-view / src / watcher.ts View on Github external
const sassFile = `${p.dir}/${p.name}.sass`
		const cssFile = `${p.dir}/${p.name}.css`
		if(fs.existsSync(sassFile)) {
			const cssResult = renderSync({
				file: sassFile,
				includePaths: [process.cwd()+'/lib'],
				outputStyle: 'expanded',
				indentedSyntax: true
			})
			css = cssResult.css.toLocaleString()
		} else if(fs.existsSync(cssFile)) {
			css = fs.readFileSync(cssFile).toString()
		}
		if(css) {
			// merge the css styles into the html
			const mergedHtml = juice.inlineContent(html, css, {
				xmlMode: false,
				webResources: {
					relativeTo: process.cwd()+'/lib'
				}
			})
			return await parse(mergedHtml)
		} else {
			return await parse(html)
		}

		async function parse(htm: string): Promise{
			return await new Promise(function(resolve, reject) {
				const handler = new htmlparser.DefaultHandler(function (error, dom) {
					if (error) reject(error)
					else resolve(dom)
				}, { verbose: false, ignoreWhitespace: true })
github connectivedx / fuzzy-chainsaw / packages / fuzzy-chainsaw-toc / build / compile.js View on Github external
.then((res) => {
    // inject css into raw template
    const inlinedTemplate = juice.inlineContent(template, res.css);

    // compile raw template into function
    const compiledTemplate = dot.template(inlinedTemplate);

    // create dist folder if it doesn't exist
    mkdirp.sync(dest());

    // replace config(varName) in template string
    const configurableTemplate = replaceCssVariables(compiledTemplate.toString());

    // add common js export so we can require it
    const output = `module.exports = ${configurableTemplate}`;

    // save to file
    fs.writeFileSync(dest('template.js'), output);
  })
github flutter-view / flutter-view / dest / test2.js View on Github external
const pug_1 = require("pug");
const node_sass_1 = require("node-sass");
const juice = require("juice");
const compiler_1 = require("./compiler");
const renderer_1 = require("./renderer");
const htmlparser = require("htmlparser");
const html = pug_1.renderFile('test/examples/simple.pug');
console.log('html:', html, '\n');
const cssResult = node_sass_1.renderSync({
    file: 'test/examples/simple.sass',
    outputStyle: 'expanded',
    indentedSyntax: true
});
const css = cssResult.css.toLocaleString();
console.log('css:', css, '\n');
const mergedHtml = juice.inlineContent(html, css, {
    xmlMode: false
});
console.log('merged: ', mergedHtml, '\n');
function parse(htm) {
    return __awaiter(this, void 0, void 0, function* () {
        return yield new Promise(function (resolve, reject) {
            const handler = new htmlparser.DefaultHandler(function (error, dom) {
                if (error)
                    reject(error);
                else
                    resolve(dom);
            }, { verbose: false, ignoreWhitespace: true });
            new htmlparser.Parser(handler).parseComplete(htm);
        });
    });
}
github compoundjs / mailer / lib / mail.js View on Github external
mail.render('.html', function(err, html) {
        if (err) return mail.emit('end', err);
        if (opts.css) {
            html = juice.inlineContent(html, opts.css);
        }
        opts.html = html;
        if (opts.generateTextFromHTML) {
            return cb(opts);
        }
        makeText();
    });
github sumeetdas / Generate-Resume / bin / utils.js View on Github external
async function createDocx (json)
{
	const currentWorkingDirectory = process.cwd();
	
	const resumeFileName = 'resume.html';
	
	const html = await fs.readFileAsync(resumeFileName, 'utf-8');
	
	const css = await fs.readFileAsync( path.join(__dirname, 'styles', json.resume.style, 'word.css'), 'utf-8' );
	
	const inlineCssHtml = juice.inlineContent(html, css);
	
	await fs.writeFileAsync( 'inlineCssHtml.html', inlineCssHtml );
	
	const docx = HtmlDocx.asBlob( inlineCssHtml );

	await fs.writeFileAsync('resume.docx', docx);
	
	console.log("Resume in DOCX format has been generated!");
	
	return json;
}
github RocketChat / Rocket.Chat / packages / rocketchat-mailer / server / api.js View on Github external
export const inlinecss = (html) => juice.inlineContent(html, Settings.get('email_style'));
export const getTemplate = (template, fn, escape = true) => {
github RocketChat / Rocket.Chat / app / mailer / server / api.js View on Github external
export const inlinecss = (html) => juice.inlineContent(html, Settings.get('email_style'));
export const getTemplate = (template, fn, escape = true) => {
github mdnice / markdown-nice / src / utils / converter.js View on Github external
const element = document.getElementById(BOX_ID);
  const inner = element.children[0].children;
  for (const item of inner) {
    item.setAttribute("data-tool", "mdnice编辑器");
  }
  let html = element.innerHTML;
  html = html.replace(/");
  html = html.replace(/\s<span class="inline/g, '&nbsp;<span class=">&lt;\/span&gt;\s/g, "svg&gt;</span>&nbsp;");
  html = html.replace(/mjx-container/g, "section");
  const basicStyle = document.getElementById(BASIC_THEME_ID).innerText;
  const markdownStyle = document.getElementById(MARKDOWN_THEME_ID).innerText;
  const codeStyle = document.getElementById(CODE_THEME_ID).innerText;
  let res = "";
  try {
    res = juice.inlineContent(html, basicStyle + markdownStyle + codeStyle, {
      inlinePseudoElements: true,
      preserveImportant: true,
    });
  } catch (e) {
    message.error("请检查 CSS 文件是否编写正确!");
  }
  return res;
};