%s
"
(format
(or (and (stringp org-export-html-xml-declaration)
org-export-html-xml-declaration)
(cdr (assoc html-extension org-export-html-xml-declaration))
(cdr (assoc "html" org-export-html-xml-declaration))
"")
(or charset "iso-8859-1"))
language language
title
(or charset "iso-8859-1")
date author description keywords
style
mathjax
(if (or link-up link-home)
(concat
(format org-export-html-home/up-format
(or link-up link-home)
(or link-home link-up))
"\n")
"")))
;; insert html preamble
(when (plist-get opt-plist :html-preamble)
(let ((html-pre (plist-get opt-plist :html-preamble)))
(cond ((stringp html-pre)
(insert
(format-spec html-pre `((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email)))))
((functionp html-pre)
(funcall html-pre opt-plist))
(t
(insert
(format-spec
(or (cadr (assoc (nth 0 lang-words)
org-export-html-preamble-format))
(cadr (assoc "en" org-export-html-preamble-format)))
`((?t . ,title) (?a . ,author)
(?d . ,date) (?e . ,email)))))))))
(if (and org-export-with-toc (not body-only))
(progn
(push (format "
%s\n"
org-export-html-toplevel-hlevel
(nth 3 lang-words)
org-export-html-toplevel-hlevel)
thetoc)
(push "
\n" thetoc)
(push "
\n- " thetoc)
(setq lines
(mapcar '(lambda (line)
(if (and (string-match org-todo-line-regexp line)
(not (get-text-property 0 'org-protected line)))
;; This is a headline
(progn
(setq have-headings t)
(setq level (- (match-end 1) (match-beginning 1)
level-offset)
level (org-tr-level level)
txt (save-match-data
(org-html-expand
(org-export-cleanup-toc-line
(match-string 3 line))))
todo
(or (and org-export-mark-todo-in-toc
(match-beginning 2)
(not (member (match-string 2 line)
org-done-keywords)))
; TODO, not DONE
(and org-export-mark-todo-in-toc
(= level umax-toc)
(org-search-todo-below
line lines level))))
(if (string-match
(org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
(setq txt (replace-match " \\1" t nil txt)))
(if (string-match quote-re0 txt)
(setq txt (replace-match "" t t txt)))
(setq snumber (org-section-number level))
(if (and num (integerp num) (>= num level))
(setq txt (concat snumber " " txt)))
(if (<= level (max umax umax-toc))
(setq head-count (+ head-count 1)))
(if (<= level umax-toc)
(progn
(if (> level org-last-level)
(progn
(setq cnt (- level org-last-level))
(while (>= (setq cnt (1- cnt)) 0)
(push "\n
\n- " thetoc))
(push "\n" thetoc)))
(if (< level org-last-level)
(progn
(setq cnt (- org-last-level level))
(while (>= (setq cnt (1- cnt)) 0)
(push "
\n
" thetoc))
(push "\n" thetoc)))
;; Check for targets
(while (string-match org-any-target-regexp line)
(setq line (replace-match
(concat "@" (match-string 1 line) "@ ")
t t line)))
(while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt)
(setq txt (replace-match "" t t txt)))
(setq href
(replace-regexp-in-string
"\\." "_" (format "sec-%s" snumber)))
(setq href (org-solidify-link-text (or (cdr (assoc href org-export-preferred-target-alist)) href)))
(push
(format
(if todo
" \n- %s"
"
\n- %s")
href txt) thetoc)
(setq org-last-level level))
)))
line)
lines))
(while (> org-last-level (1- org-min-level))
(setq org-last-level (1- org-last-level))
(push "
\n
\n" thetoc))
(push "
\n" thetoc)
(setq thetoc (if have-headings (nreverse thetoc) nil))))
(setq head-count 0)
(org-init-section-numbers)
(org-open-par)
(while (setq line (pop lines) origline line)
(catch 'nextline
;; end of quote section?
(when (and inquote (string-match "^\\*+ " line))
(insert "\n")
(org-open-par)
(setq inquote nil))
;; inside a quote section?
(when inquote
(insert (org-html-protect line) "\n")
(throw 'nextline nil))
;; Fixed-width, verbatim lines (examples)
(when (and org-export-with-fixed-width
(string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
(when (not infixed)
(setq infixed t)
(org-close-par-maybe)
(insert "
\n"))
(insert (org-html-protect (match-string 3 line)) "\n")
(when (or (not lines)
(not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
(car lines))))
(setq infixed nil)
(insert "
\n")
(org-open-par))
(throw 'nextline nil))
;; Protected HTML
(when (and (get-text-property 0 'org-protected line)
;; Make sure it is the entire line that is protected
(not (< (or (next-single-property-change
0 'org-protected line) 10000)
(length line))))
(let (par (ind (get-text-property 0 'original-indentation line)))
(when (re-search-backward
"\\(
\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
(setq par (match-string 1))
(replace-match "\\2\n"))
(insert line "\n")
(while (and lines
(or (= (length (car lines)) 0)
(not ind)
(equal ind (get-text-property 0 'original-indentation (car lines))))
(or (= (length (car lines)) 0)
(get-text-property 0 'org-protected (car lines))))
(insert (pop lines) "\n"))
(and par (insert "
\n")))
(throw 'nextline nil))
;; Blockquotes, verse, and center
(when (equal "ORG-BLOCKQUOTE-START" line)
(org-close-par-maybe)
(insert "
\n")
(org-open-par)
(throw 'nextline nil))
(when (equal "ORG-BLOCKQUOTE-END" line)
(org-close-par-maybe)
(insert "\n
\n")
(org-open-par)
(throw 'nextline nil))
(when (equal "ORG-VERSE-START" line)
(org-close-par-maybe)
(insert "\n
\n")
(setq org-par-open t)
(setq inverse t)
(throw 'nextline nil))
(when (equal "ORG-VERSE-END" line)
(insert "
\n")
(setq org-par-open nil)
(org-open-par)
(setq inverse nil)
(throw 'nextline nil))
(when (equal "ORG-CENTER-START" line)
(org-close-par-maybe)
(insert "\n
")
(org-open-par)
(throw 'nextline nil))
(when (equal "ORG-CENTER-END" line)
(org-close-par-maybe)
(insert "\n
")
(org-open-par)
(throw 'nextline nil))
(run-hooks 'org-export-html-after-blockquotes-hook)
(when inverse
(let ((i (org-get-string-indentation line)))
(if (> i 0)
(setq line (concat (mapconcat 'identity
(make-list (* 2 i) "\\nbsp") "")
" " (org-trim line))))
(unless (string-match "\\\\\\\\[ \t]*$" line)
(setq line (concat line "\\\\")))))
;; make targets to anchors
(setq start 0)
(while (string-match
"<<\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
(cond
((get-text-property (match-beginning 1) 'org-protected line)
(setq start (match-end 1)))
((match-end 2)
(setq line (replace-match
(format
"@
@"
(org-solidify-link-text (match-string 1 line))
(org-solidify-link-text (match-string 1 line)))
t t line)))
((and org-export-with-toc (equal (string-to-char line) ?*))
;; FIXME: NOT DEPENDENT on TOC?????????????????????
(setq line (replace-match
(concat "@
"
(match-string 1 line) "@ ")
;; (concat "@
" (match-string 1 line) "@ ")
t t line)))
(t
(setq line (replace-match
(concat "@
" (match-string 1 line)
"@ ")
t t line)))))
(setq line (org-html-handle-time-stamps line))
;; replace "&" by "&", "<" and ">" by "<" and ">"
;; handle @<..> HTML tags (replace "@>..<" by "<..>")
;; Also handle sub_superscripts and checkboxes
(or (string-match org-table-hline-regexp line)
(setq line (org-html-expand line)))
;; Format the links
(setq line (org-html-handle-links line opt-plist))
;; TODO items
(if (and (string-match org-todo-line-regexp line)
(match-beginning 2))
(setq line
(concat (substring line 0 (match-beginning 2))
"
" (org-export-html-get-todo-kwd-class-name
(match-string 2 line))
"" (substring line (match-end 2)))))
;; Does this contain a reference to a footnote?
(when org-export-with-footnotes
(setq start 0)
(while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
(if (get-text-property (match-beginning 2) 'org-protected line)
(setq start (match-end 2))
(let ((n (match-string 2 line)) extra a)
(if (setq a (assoc n footref-seen))
(progn
(setcdr a (1+ (cdr a)))
(setq extra (format ".%d" (cdr a))))
(setq extra "")
(push (cons n 1) footref-seen))
(setq line
(replace-match
(format
(concat "%s"
(format org-export-html-footnote-format
""))
(or (match-string 1 line) "") n extra n n)
t t line))))))
(cond
((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
;; This is a headline
(setq level (org-tr-level (- (match-end 1) (match-beginning 1)
level-offset))
txt (match-string 2 line))
(if (string-match quote-re0 txt)
(setq txt (replace-match "" t t txt)))
(if (<= level (max umax umax-toc))
(setq head-count (+ head-count 1)))
(setq first-heading-pos (or first-heading-pos (point)))
(org-html-level-start level txt umax
(and org-export-with-toc (<= level umax))
head-count opt-plist)
;; QUOTES
(when (string-match quote-re line)
(org-close-par-maybe)
(insert "
")
(setq inquote t)))
((and org-export-with-tables
(string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
(when (not table-open)
;; New table starts
(setq table-open t table-buffer nil table-orig-buffer nil))
;; Accumulate lines
(setq table-buffer (cons line table-buffer)
table-orig-buffer (cons origline table-orig-buffer))
(when (or (not lines)
(not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
(car lines))))
(setq table-open nil
table-buffer (nreverse table-buffer)
table-orig-buffer (nreverse table-orig-buffer))
(org-close-par-maybe)
(insert (org-format-table-html table-buffer table-orig-buffer))))
;; Normal lines
(t
;; This line either is list item or end a list.
(when (get-text-property 0 'list-item line)
(setq line (org-html-export-list-line
line
(get-text-property 0 'list-item line)
(get-text-property 0 'list-struct line)
(get-text-property 0 'list-prevs line))))
;; Horizontal line
(when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
(if org-par-open
(insert "\n\n
\n\n")
(insert "\n
\n"))
(throw 'nextline nil))
;; Empty lines start a new paragraph. If hand-formatted lists
;; are not fully interpreted, lines starting with "-", "+", "*"
;; also start a new paragraph.
(if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
;; Is this the start of a footnote?
(when org-export-with-footnotes
(when (and (boundp 'footnote-section-tag-regexp)
(string-match (concat "^" footnote-section-tag-regexp)
line))
;; ignore this line
(throw 'nextline nil))
(when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
(org-close-par-maybe)
(let ((n (match-string 1 line)))
(setq org-par-open t
line (replace-match
(format
(concat " so that the footnote matcher
;; does not see this.
(if (not (get-text-property (match-beginning 0)
'org-protected line))
(setq line (replace-match "" t t line)))
(setq start (match-end 0))))
(insert line "\n")))))
;; Properly close all local lists and other lists
(when inquote
(insert "
\n")
(org-open-par))
(org-html-level-start 1 nil umax
(and org-export-with-toc (<= level umax))
head-count opt-plist)
;; the
to close the last text-... div.
(when (and (> umax 0) first-heading-pos) (insert "\n"))
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\\|\\'\\)" nil t)
(push (match-string 0) footnotes)
(replace-match "" t t)))
(when footnotes
(insert (format org-export-html-footnotes-section
(nth 4 lang-words)
(mapconcat 'identity (nreverse footnotes) "\n"))
"\n"))
(let ((bib (org-export-html-get-bibliography)))
(when bib
(insert "\n" bib "\n")))
;; export html postamble
(unless body-only
(let ((html-post (plist-get opt-plist :html-postamble))
(email
(mapconcat (lambda(e)
(format "\n")
(insert (format-spec html-post
`((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link))))
(insert "
"))
((functionp html-post)
(funcall html-post opt-plist))
((eq html-post 'auto)
;; fall back on default postamble
(insert "\n")
(when (plist-get opt-plist :time-stamp-file)
(insert "
" (nth 2 lang-words) ": " date "
\n"))
(when (and (plist-get opt-plist :author-info) author)
(insert "
" (nth 1 lang-words) ": " author "
\n"))
(when (and (plist-get opt-plist :email-info) email)
(insert "
" email "
\n"))
(when (plist-get opt-plist :creator-info)
(insert "
"
(concat "Org version " org-version " with Emacs version "
(number-to-string emacs-major-version) "
\n")))
(insert html-validation-link "\n
"))
(t
(insert "\n")
(insert (format-spec
(or (cadr (assoc (nth 0 lang-words)
org-export-html-postamble-format))
(cadr (assoc "en" org-export-html-postamble-format)))
`((?a . ,author) (?e . ,email)
(?d . ,date) (?c . ,creator-info)
(?v . ,html-validation-link))))
(insert "
"))))))
(if org-export-html-with-timestamp
(insert org-export-html-html-helper-timestamp))
(unless body-only (insert "\n\n\n\n"))
(unless (plist-get opt-plist :buffer-will-be-killed)
(normal-mode)
(if (eq major-mode (default-value 'major-mode))
(html-mode)))
;; insert the table of contents
(goto-char (point-min))
(when thetoc
(if (or (re-search-forward
"" ""))))))))
(defun org-export-html-get-bibliography ()
"Find bibliography, cut it out and return it."
(catch 'exit
(let (beg end (cnt 1) bib)
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^[ \t]*
" nil t)
(setq cnt (+ cnt (if (string= (match-string 0) "
") (forward-char 1))
(setq bib (buffer-substring beg (point)))
(delete-region beg (point))
(throw 'exit bib))))
nil))))
(defvar org-table-number-regexp) ; defined in org-table.el
(defun org-format-table-html (lines olines &optional no-css)
"Find out which HTML converter to use and return the HTML code.
NO-CSS is passed to the exporter."
(if (stringp lines)
(setq lines (org-split-string lines "\n")))
(if (string-match "^[ \t]*|" (car lines))
;; A normal org table
(org-format-org-table-html lines nil no-css)
;; Table made by table.el - test for spanning
(let* ((hlines (delq nil (mapcar
(lambda (x)
(if (string-match "^[ \t]*\\+-" x) x
nil))
lines)))
(first (car hlines))
(ll (and (string-match "\\S-+" first)
(match-string 0 first)))
(re (concat "^[ \t]*" (regexp-quote ll)))
(spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
hlines))))
(if (and (not spanning)
(not org-export-prefer-native-exporter-for-tables))
;; We can use my own converter with HTML conversions
(org-format-table-table-html lines)
;; Need to use the code generator in table.el, with the original text.
(org-format-table-table-html-using-table-generate-source olines)))))
(defvar org-table-number-fraction) ; defined in org-table.el
(defun org-format-org-table-html (lines &optional splice no-css)
"Format a table into HTML.
LINES is a list of lines. Optional argument SPLICE means, do not
insert header and surrounding
tags, just format the lines.
Optional argument NO-CSS means use XHTML attributes instead of CSS
for formatting. This is required for the DocBook exporter."
(require 'org-table)
;; Get rid of hlines at beginning and end
(if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
(setq lines (nreverse lines))
(if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
(setq lines (nreverse lines))
(when org-export-table-remove-special-lines
;; Check if the table has a marking column. If yes remove the
;; column and the special lines
(setq lines (org-table-clean-before-export lines)))
(let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
(label (org-find-text-property-in-string 'org-label (car lines)))
(forced-aligns (org-find-text-property-in-string 'org-forced-aligns
(car lines)))
(attributes (org-find-text-property-in-string 'org-attributes
(car lines)))
(html-table-tag (org-export-splice-attributes
html-table-tag attributes))
(head (and org-export-highlight-first-table-line
(delq nil (mapcar
(lambda (x) (string-match "^[ \t]*|-" x))
(cdr lines)))))
(nline 0) fnum nfields i (cnt 0)
tbopen line fields html gr colgropen rowstart rowend
ali align aligns n)
(setq caption (and caption (org-html-do-expand caption)))
(when (and forced-aligns org-table-clean-did-remove-column)
(setq forced-aligns
(mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
(if splice (setq head nil))
(unless splice (push (if head "" "") html))
(setq tbopen t)
(while (setq line (pop lines))
(catch 'next-line
(if (string-match "^[ \t]*|-" line)
(progn
(unless splice
(push (if head "" "") html)
(if lines (push "" html) (setq tbopen nil)))
(setq head nil) ;; head ends here, first time around
;; ignore this line
(throw 'next-line t)))
;; Break the line into fields
(setq fields (org-split-string line "[ \t]*|[ \t]*"))
(unless fnum (setq fnum (make-vector (length fields) 0)
nfields (length fnum)))
(setq nline (1+ nline) i -1
rowstart (eval (car org-export-table-row-tags))
rowend (eval (cdr org-export-table-row-tags)))
(push (concat rowstart
(mapconcat
(lambda (x)
(setq i (1+ i) ali (format "@@class%03d@@" i))
(if (and (< i nfields) ; make sure no rogue line causes an error here
(string-match org-table-number-regexp x))
(incf (aref fnum i)))
(cond
(head
(concat
(format (car org-export-table-header-tags)
"col" ali)
x
(cdr org-export-table-header-tags)))
((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
(concat
(format (car org-export-table-header-tags)
"row" ali)
x
(cdr org-export-table-header-tags)))
(t
(concat (format (car org-export-table-data-tags) ali)
x
(cdr org-export-table-data-tags)))))
fields "")
rowend)
html)))
(unless splice (if tbopen (push "" html)))
(unless splice (push "
\n" html))
(setq html (nreverse html))
(unless splice
;; Put in col tags with the alignment (unfortunately often ignored...)
(unless (car org-table-colgroup-info)
(setq org-table-colgroup-info
(cons :start (cdr org-table-colgroup-info))))
(setq i 0)
(push (mapconcat
(lambda (x)
(setq gr (pop org-table-colgroup-info)
i (1+ i)
align (if (assoc i forced-aligns)
(cdr (assoc (cdr (assoc i forced-aligns))
'(("l" . "left") ("r" . "right")
("c" . "center"))))
(if (> (/ (float x) nline)
org-table-number-fraction)
"right" "left")))
(push align aligns)
(format (if no-css
"%s
%s"
"%s
%s")
(if (memq gr '(:start :startend))
(prog1
(if colgropen
"\n
"
"")
(setq colgropen t))
"")
align
(if (memq gr '(:end :startend))
(progn (setq colgropen nil) "")
"")))
fnum "")
html)
(setq aligns (nreverse aligns))
(if colgropen (setq html (cons (car html)
(cons "" (cdr html)))))
;; Since the output of HTML table formatter can also be used in
;; DocBook document, we want to always include the caption to make
;; DocBook XML file valid.
(push (format "
%s" (or caption "")) html)
(when label
(setq html-table-tag (org-export-splice-attributes html-table-tag (format "id=\"%s\"" (org-solidify-link-text label)))))
(push html-table-tag html))
(setq html (mapcar
(lambda (x)
(replace-regexp-in-string
"@@class\\([0-9]+\\)@@"
(lambda (txt)
(if (not org-export-html-table-align-individual-fields)
""
(setq n (string-to-number (match-string 1 txt)))
(format (if no-css " align=\"%s\"" " class=\"%s\"")
(or (nth n aligns) "left"))))
x))
html))
(concat (mapconcat 'identity html "\n") "\n")))
(defun org-export-splice-attributes (tag attributes)
"Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
(if (not attributes)
tag
(let (oldatt newatt)
(setq oldatt (org-extract-attributes-from-string tag)
tag (pop oldatt)
newatt (cdr (org-extract-attributes-from-string attributes)))
(while newatt
(setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
(if (string-match ">" tag)
(setq tag
(replace-match (concat (org-attributes-to-string oldatt) ">")
t t tag)))
tag)))
(defun org-format-table-table-html (lines)
"Format a table generated by table.el into HTML.
This conversion does *not* use `table-generate-source' from table.el.
This has the advantage that Org-mode's HTML conversions can be used.
But it has the disadvantage, that no cell- or row-spanning is allowed."
(let (line field-buffer
(head org-export-highlight-first-table-line)
fields html empty i)
(setq html (concat html-table-tag "\n"))
(while (setq line (pop lines))
(setq empty " ")
(catch 'next-line
(if (string-match "^[ \t]*\\+-" line)
(progn
(if field-buffer
(progn
(setq
html
(concat
html
"
"
(mapconcat
(lambda (x)
(if (equal x "") (setq x empty))
(if head
(concat
(format (car org-export-table-header-tags) "col" "")
x
(cdr org-export-table-header-tags))
(concat (format (car org-export-table-data-tags) "") x
(cdr org-export-table-data-tags))))
field-buffer "\n")
"
\n"))
(setq head nil)
(setq field-buffer nil)))
;; Ignore this line
(throw 'next-line t)))
;; Break the line into fields and store the fields
(setq fields (org-split-string line "[ \t]*|[ \t]*"))
(if field-buffer
(setq field-buffer (mapcar
(lambda (x)
(concat x "
" (pop fields)))
field-buffer))
(setq field-buffer fields))))
(setq html (concat html "