2013-01-14 20 views
1

的結構我初學這個很抱歉,如果我忽略了一些東西簡單...的Emacs組織模式和HTML發佈:如何更改生成的HTML

我想使用emacs組織模式爲我的HTML頁面。 '默認'設置很好,但我想使用其中一個免費網頁模板,例如http://www.freecsstemplates.org/preview/goodlife/

這些模板提供了CSS文件,但僅僅在組織模式的HTML導出中使用CSS似乎還不夠。看來,爲了正確使用這些模板,我還需要維護如此類模板中所示的HTML結構。

如何強制org模式生成我喜歡的HTML結構(即幀分割)?

看來,有些選項是由'org-export-generic.el'提供的。即使我說服泛型導出爲我提供單個HTML頁面,它仍然不會完全解析HTML導出....

回答

0

我同意。由org的內置導出生成的HTML很好,但不是我想要的。看來,通用出口基於elisp,而我更喜歡XSLT。

我寫了下面的代碼將一個org文件轉換爲XML,但我還沒有寫出發佈轉換。無論如何,這可能有助於您的參考,特別是它顯示組織文檔內部表示的結構。

(require 'org-element) 

(defvar xml-content-encode-map 
    '((?& . "&") 
    (?< . "&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")))) 
+0

這似乎是一個有趣的選擇:出口數據轉換成XML,並使用一個解析器會把數據進入畝選擇結構(如蟒蛇):) –

1

的組織模式手冊的這一節提供了一些指導導出到HTML和使用CSS http://orgmode.org/manual/CSS-support.html#CSS-support這包括默認類的描述組織模式的使用,所以你可以修改你的CSS。

如果要修改組織模式導出以匹配CSS類和ID,請使用組織標題中的HTML_CONTAINER_CLASS:屬性和用於創建ID的CUSTOM_ID:屬性。

而不是設置每個文件的東西我使用org模式的發佈能力輸出許多組織文件到一個單一的網站。您可以在這裏找到一個教程http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html

我的組織,發佈項目,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")) 
+1

這不是我真正關心的。問題在於,組織模式不允許您將組織數據放入HTML結構中。 CSS可以改變字體的格式,但它不能改變生成HTML的方式 –