3

如果我忽略了一些简单的事情,我是初学者,很抱歉......

我想为我的 HTML 页面使用 emacs org-mode。“默认”设置很好并且可以正常工作,但是我想使用其中一个免费的网络模板,例如http://www.freecsstemplates.org/preview/goodlife/

这些模板提供 CSS 文件,但是在 org-mode 的 HTML 导出中仅使用 CSS 似乎还不够。似乎要正确使用这些模板,我还需要维护此类模板中所示的 HTML 结构。

如何强制 org-mode 生成我喜欢的 HTML 结构(即框架分割)?

似乎“org-export-generic.el”提供了一些选项。即使我会说服通用导出为我提供一个 HTML 页面,它仍然不能完全解决 HTML 导出......

4

2 回答 2

2

org-mode 手册的这一部分提供了一些关于导出到 html 和使用 css 的指导http://orgmode.org/manual/CSS-support.html#CSS-support 这包括 org-mode 使用的默认类的描述,所以你可以修改你的CSS。

如果您想修改 org 模式导出以匹配您的 CSS 类和 id,请使用 org 标题中的 :HTML_CONTAINER_CLASS: 属性和用于创建 id 的 :CUSTOM_ID: 属性。

我没有对每个文件进行设置,而是使用 org 模式的发布功能将许多 org 文件输出到单个网站中。你可以在这里找到一个教程http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html

我的 org-publish-project-alist 看起来像:

'(org-publish-project-alist (quote (("requirements" :components ("req-static" "req-org"))
   ("req-static" :base-directory "~/org/requirements" :publishing-directory "~/public_html/requirements/" :base-extension "gif\\|css" :publishing-function org-publish-attachment) 
   ("req-org" :base-directory "~/org/requirements/" :publishing-directory "~/public_html/requirements/" :style "<link rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" />" :section-numbers nil :headline-levels 3 :table-of-contents 2 :auto-sitemap t :sitemap-filename "index.org" :sitemap-title "Requirements for My Software" :link-home "./index.html"))
于 2013-01-14T20:45:19.483 回答
0

我同意。org 的内置导出生成的 HTML 很好,但不是我想要的。似乎通用导出基于 elisp,而我更喜欢 XSLT。

我编写了以下将 org 文件转换为 XML 的代码,但我还没有编写发布转换。无论如何,这可能对您的参考有所帮助,尤其是因为它显示了组织文档内部表示的结构。

(require 'org-element)

(defvar xml-content-encode-map
  '((?& . "&amp;")
    (?< . "&lt;")
    (?> . "&gt;")))

(defvar xml-attribute-encode-map
  (cons '(?\" . "&quot;") xml-content-encode-map))

(defun write-xml (o out parents depth)
  "Writes O as XML to OUT, assuming that lists have a plist as
their second element (for representing attributes).  Skips basic
cycles (elements pointing to ancestor), and compound values for
attributes."
  (if (not (listp o))
      ;; TODO: this expression is repeated below
      (princ o (lambda (charcode)
                 (princ 
                  (or (aget xml-content-encode-map charcode)
                      (char-to-string charcode))
                  out)))

    (unless (member o parents)
      (let ((parents-and-self (cons o parents))
            (attributes (second o)))

        (dotimes (x depth) (princ "\t" out))
        (princ "<" out)
        (princ (car o) out)

        (loop for x on attributes by 'cddr do
              (let ((key (first x))
                    (value (second x)))

                (when (and value (not (listp value)))
                  (princ " " out)
                  (princ (substring (symbol-name key) 1) out)
                  (princ "=\"" out)
                  (princ value  (lambda (charcode)
                                  (princ 
                                   (or (aget xml-attribute-encode-map charcode)
                                       (char-to-string charcode))
                                   out)))
                  (princ "\"" out))))

        (princ ">\n" out)

        (loop for e in (cddr o)  do
              (write-xml e out parents-and-self (+ 1 depth)))

        (dotimes (x depth) (princ "\t" out))
        (princ "</" out)
        (princ (car o) out)
        (princ ">\n" out)))))

(defun org-file-to-xml (orgfile xmlfile)
  "Serialize ORGFILE file as XML to XMLFILE."
  (save-excursion
    (find-file orgfile)
    (let ((org-doc (org-element-parse-buffer)))
      (with-temp-file xmlfile
        (let ((buffer (current-buffer)))
          (princ "<?xml version='1.0'?>\n" buffer)
          (write-xml org-doc buffer () 0)
          (nxml-mode)))))
  (find-file xmlfile)
  (nxml-mode))

(defun org-to-xml ()
  "Export the current org file to XML and open in new buffer.
Does nothing if the current buffer is not in org-mode."
  (interactive)
  (when (eq major-mode 'org-mode)
    (org-file-to-xml
     (buffer-file-name)
     (concat (buffer-file-name) ".xml"))))
于 2013-01-14T18:42:27.697 回答