如何运行 Google 的 prettify 来生成静态 HTML(带 CSS)输出?
我正在努力美化一些自动生成的电子邮件,这些电子邮件中通常包含代码片段。我想使用 Google 的 prettify 项目来语法突出显示代码片段。
在发送电子邮件之前,如何在服务器上调用 prettify
,以便用户在邮件查看器 (Outlook) 中禁用 javascript 时仍能看到突出显示的语法。我想我需要某种浏览器模拟器,因为 prettify
正在操纵浏览器 DOM。
I'm working on prettify'ing some auto-generated emails that often have code snippets in them. I want to use Google's prettify project to syntax highlight the code snippets.
How can I invoke prettify
on the server, before sending out the email, such that users will still see the highlighted syntax when javascript is disabled in their mail viewers (Outlook). I'm thinking I need some sort of browser emulator since prettify
is manipulating the browser DOM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Rhino 或 Google v8 解释器可以在服务器上运行纯 JavaScript,但这意味着您必须扫描电子邮件,找到所有代码块,编写一个特殊的 prettify 调用,以便它返回格式化代码而不是在 DOM 上替换它...不太实用,而且您必须拥有服务器的 shell 访问权限才能让 v8 运行。
如果您对此感兴趣,请看这里:
独立运行 V8 Javascript 引擎
现在,另一种方法是使用多种方法之一服务器端荧光笔,例如 Hyperlight (http://code.google.com/p/hyperlight/) 或 Pygments (http://pygments.org/)
最后,您必须包含在通过电子邮件发送上述任何方法使用的主题中的所有 CSS,这并不是太大的麻烦,但会增加电子邮件的大小,即使所有要突出显示的内容只是一个变量名称。
Running the plain JavaScript on the server is possible using Rhino or the Google v8 interpreter, but that would mean you'd have to scan the emails, find all the code blocks, write a special call to prettify so it returns the formatted code instead of replacing it on the DOM... not too practical, plus you'd have to have shell access to your server to get v8 going.
If you are interested in that, look here:
Running V8 Javascript Engine Standalone
Now, the other way would be to use one of the many server-side highlighters like Hyperlight (http://code.google.com/p/hyperlight/) or Pygments (http://pygments.org/)
Lastly, you'd have to include in the emails all the CSS from the themes used by any of the above methods, which isn't too big of a hassle, but increases the size of the email, even if all what was there to highlight was a variable name, for instance.