2
votes

I'm beginner to this so sorry if I overlook something simple...

I'd like to use emacs org-mode for my HTML pages. The 'default' setup is nice and working, however I'd like to use one of the free web templates, e.g. http://www.freecsstemplates.org/preview/goodlife/

These templates provide CSS files, however just usage of CSS in org-mode's HTML export seem not to be enough. It seems that to use these templates correctly I need as well to maintain HTML structure as shown in such template.

How can I force org-mode to generate HTML structure I like (i.e. frame division)?

It seems, that some options are offered by 'org-export-generic.el'. Even if I would persuade generic export to provide me with a single HTML page, it still does not resolve completely the HTML export....

2

2 Answers

1
votes

This section of the org-mode manual provides some guidance on exporting to html and using css http://orgmode.org/manual/CSS-support.html#CSS-support This includes a description of the default classes org-mode uses so you could modify your CSS.

If you want to modify org mode exports to match your CSS classes and ids use the :HTML_CONTAINER_CLASS: property in an org headline and the :CUSTOM_ID: property for creating ids.

Instead of setting things up per file I use org mode's publishing ability to output many org files into a single website. You can find a tutorial on that here http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html

My org-publish-project-alist looks like:

'(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"))
0
votes

I agree. The HTML generated by org's built-in export is good but not quite what I'd want. It appears that the generic export are based on elisp, whereas I prefer XSLT.

I wrote the following code for turning an org file into XML, but I haven't written the publishing transforms yet. Anyway, this may be helpful for your reference, especially as it shows the structure of an org document's internal representation.

(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"))))