2016-06-12 61 views
1

我使用翡翠製作html電子郵件。你知道,將'to'字段個性化,就像那樣。我想提供純文本版本。有沒有辦法將玉石編譯成純文本?使用翡翠作爲純文本的模板語言

+1

鑑於教程頁面明確地告誡它,我建議找一個不同的庫(重點煤礦):「它僅用於生成類似XML的文檔(HTML,RSS等),因此不要用它來創建純文本/標記/ CSS /任何文檔。「 - http://jade-lang.com/tutorial/ – mklement0

回答

2

如果玉 - > HTML - >平原是你可以做一個可接受的解決方案:http://requirebin.com/?gist=cbc4d126c842754fd545eff554a7767d

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

const jadeTemplate = `doctype html 
html(lang="en") 
    head 
    title= pageTitle 
    script(type='text/javascript'). 
     if (foo) { 
     bar(1 + 5) 
     } 
    body 
    h1 Jade - node template engine 
    #container.col 
     if youAreUsingJade 
     p You are amazing 
     else 
     p Get on it! 
     p. 
     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;