在Emacs中将语法突出显示的代码转换为HTML

时间:2009-06-03 20:01:10

标签: html emacs syntax-highlighting

在TextMate中有一个名为“从文档创建HTML”的功能,它将显示的代码(包括语法着色)转换为HTML / CSS,以便于在线发布。 我想知道在Emacs中是否隐藏了这样的功能,或者我可以安装这样的扩展程序。

1 个答案:

答案 0 :(得分:19)

Htmlize

在这里,我使用htmlize-region来Html化GNU Emacs欢迎屏幕的一部分:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- Created by htmlize-1.34 in css mode. -->
<html>
  <head>
    <title>*GNU Emacs*</title>
    <style type="text/css">
    <!--
      body {
        color: #000000;
        background-color: #ffffff;
      }
      .ATTRLIST {
      }
      .ATTRLIST-1 {
        /* (:foreground "darkblue") */
        color: #00008b;
      }
      .ATTRLIST-2 {
        /* (:slant oblique) */
        font-style: italic;
      }
      .ATTRLIST-3 {
        /* (:foreground "red") */
        color: #ff0000;
      }
      .default {
        /* default */
        color: #000000;
        background-color: #ffffff;
      }
      .link {
        /* link */
        color: #0000ff;
        text-decoration: underline;
      }
      .variable-pitch {
      }

      a {
        color: inherit;
        background-color: inherit;
        font: inherit;
        text-decoration: inherit;
      }
      a:hover {
        text-decoration: underline;
      }
    -->
    </style>
  </head>
  <body>
    <pre>
<span class="ATTRLIST-3"><span class="variable-pitch">Welcome to </span></span><span class="ATTRLIST"><span class="link">GNU Emacs</span></span><span class="ATTRLIST-3"><span class="variable-pitch">, one component of the </span></span><span class="ATTRLIST"><span class="link">GNU/Linux</span></span><span class="ATTRLIST-3"><span class="variable-pitch"> operating system.
</span></span><span class="variable-pitch">To quit a partially entered command, type </span><span class="default">Control-g</span><span class="variable-pitch">.

</span><span class="variable-pitch"><span class="link">Emacs Tutorial</span></span><span class="variable-pitch">        Learn basic keystroke commands
</span><span class="variable-pitch"><span class="link">Emacs Guided Tour</span></span><span class="variable-pitch">     Overview of Emacs features
</span><span class="variable-pitch"><span class="link">View Emacs Manual</span></span><span class="variable-pitch">     View the Emacs manual using Info
</span><span class="variable-pitch"><span class="link">Absence of Warranty</span></span><span class="variable-pitch">   GNU Emacs comes with </span><span class="ATTRLIST-2"><span class="variable-pitch">ABSOLUTELY NO WARRANTY
</span></span><span class="variable-pitch"><span class="link">Copying Conditions</span></span><span class="variable-pitch">    Conditions for redistributing and changing Emacs
</span><span class="variable-pitch"><span class="link">Ordering Manuals</span></span><span class="variable-pitch">      Purchasing printed copies of manuals</span>
<span class="variable-pitch">
To start...     </span><span class="variable-pitch"><span class="link">Open a File</span></span><span class="variable-pitch">     </span><span class="variable-pitch"><span class="link">Open Home Directory</span></span><span class="variable-pitch">     </span><span class="variable-pitch"><span class="link">Customize Startup</span></span><span class="variable-pitch">
</span><span class="ATTRLIST-1"><span class="variable-pitch">
This is GNU Emacs 22.3.1 (x86_64-pc-linux-gnu, GTK+ Version 2.14.7)
 of 2009-03-31 on nautilus, modified by Debian</span></span></pre>
  </body>
</html>