Costa Costa - 2 years ago 158
Node.js Question

Using jade as a template language for plain text

I'm using jade to craft html emails. You know, personalize the 'to' field, things like that. I'd like to provide a plain text version as well. Is there any way to compile jade to plain text?

Sid Sid
Answer Source

If jade -> html -> plain is an acceptable solution you could do:

var htmlToText = require('html-to-text');
var jade = require('jade');

const jadeTemplate = `doctype html
    title= pageTitle
      if (foo) {
         bar(1 + 5)
    h1 Jade - node template engine
      if youAreUsingJade
        p You are amazing
        p Get on it!
        Jade is a terse and simple
        templating language with a
        strong focus on performance
        and powerful features.`;

var html = jade.compile(jadeTemplate, {})({});
var text = htmlToText.fromString(html, {
    wordwrap: 130

document.getElementById('text').value = text;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download