-;;;###autoload
-(defun org-export-as-html-and-open (arg)
- "Export the outline as HTML and immediately open it with a browser.
-If there is an active region, export only the region.
-The prefix ARG specifies how many levels of the outline should become
-headlines. The default is 3. Lower levels will become bulleted lists."
- (interactive "P")
- (org-export-as-html arg 'hidden)
- (org-open-file buffer-file-name))
-
-;;;###autoload
-(defun org-export-as-html-batch ()
- "Call `org-export-as-html', may be used in batch processing as
-emacs --batch
- --load=$HOME/lib/emacs/org.el
- --eval \"(setq org-export-headline-levels 2)\"
- --visit=MyFile --funcall org-export-as-html-batch"
- (org-export-as-html org-export-headline-levels 'hidden))
-
-;;;###autoload
-(defun org-export-as-html-to-buffer (arg)
- "Call `org-export-as-html` with output to a temporary buffer.
-No file is created. The prefix ARG is passed through to `org-export-as-html'."
- (interactive "P")
- (org-export-as-html arg nil nil "*Org HTML Export*")
- (switch-to-buffer-other-window "*Org HTML Export*"))
-
-;;;###autoload
-(defun org-replace-region-by-html (beg end)
- "Assume the current region has org-mode syntax, and convert it to HTML.
-This can be used in any buffer. For example, you could write an
-itemized list in org-mode syntax in an HTML buffer and then use this
-command to convert it."
- (interactive "r")
- (let (reg html buf pop-up-frames)
- (save-window-excursion
- (if (org-mode-p)
- (setq html (org-export-region-as-html
- beg end t 'string))
- (setq reg (buffer-substring beg end)
- buf (get-buffer-create "*Org tmp*"))
- (with-current-buffer buf
- (erase-buffer)
- (insert reg)
- (org-mode)
- (setq html (org-export-region-as-html
- (point-min) (point-max) t 'string)))
- (kill-buffer buf)))
- (delete-region beg end)
- (insert html)))
-
-;;;###autoload
-(defun org-export-region-as-html (beg end &optional body-only buffer)
- "Convert region from BEG to END in org-mode buffer to HTML.
-If prefix arg BODY-ONLY is set, omit file header, footer, and table of
-contents, and only produce the region of converted text, useful for
-cut-and-paste operations.
-If BUFFER is a buffer or a string, use/create that buffer as a target
-of the converted HTML. If BUFFER is the symbol `string', return the
-produced HTML as a string and leave not buffer behind. For example,
-a Lisp program could call this function in the following way:
-
- (setq html (org-export-region-as-html beg end t 'string))
-
-When called interactively, the output buffer is selected, and shown
-in a window. A non-interactive call will only return the buffer."
- (interactive "r\nP")
- (when (interactive-p)
- (setq buffer "*Org HTML Export*"))
- (let ((transient-mark-mode t) (zmacs-regions t)
- ext-plist rtn)
- (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
- (goto-char end)
- (set-mark (point)) ;; to activate the region
- (goto-char beg)
- (setq rtn (org-export-as-html
- nil nil ext-plist
- buffer body-only))
- (if (fboundp 'deactivate-mark) (deactivate-mark))
- (if (and (interactive-p) (bufferp rtn))
- (switch-to-buffer-other-window rtn)
- rtn)))
-
-(defvar html-table-tag nil) ; dynamically scoped into this.
-(defvar org-par-open nil)
-;;;###autoload
-(defun org-export-as-html (arg &optional hidden ext-plist
- to-buffer body-only pub-dir)
- "Export the outline as a pretty HTML file.
-If there is an active region, export only the region. The prefix
-ARG specifies how many levels of the outline should become
-headlines. The default is 3. Lower levels will become bulleted
-lists. When HIDDEN is non-nil, don't display the HTML buffer.
-EXT-PLIST is a property list with external parameters overriding
-org-mode's default settings, but still inferior to file-local
-settings. When TO-BUFFER is non-nil, create a buffer with that
-name and export to that buffer. If TO-BUFFER is the symbol
-`string', don't leave any buffer behind but just return the
-resulting HTML as a string. When BODY-ONLY is set, don't produce
-the file header and footer, simply return the content of
-<body>...</body>, without even the body tags themselves. When
-PUB-DIR is set, use this as the publishing directory."
- (interactive "P")
-
- ;; Make sure we have a file name when we need it.
- (when (and (not (or to-buffer body-only))
- (not buffer-file-name))
- (if (buffer-base-buffer)
- (org-set-local 'buffer-file-name
- (with-current-buffer (buffer-base-buffer)
- buffer-file-name))
- (error "Need a file name to be able to export.")))
-
- (message "Exporting...")
- (setq-default org-todo-line-regexp org-todo-line-regexp)
- (setq-default org-deadline-line-regexp org-deadline-line-regexp)
- (setq-default org-done-keywords org-done-keywords)
- (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
- (let* ((opt-plist
- (org-export-process-option-filters
- (org-combine-plists (org-default-export-plist)
- ext-plist
- (org-infile-export-plist))))
- (style (concat (if (plist-get opt-plist :style-include-default)
- org-export-html-style-default)
- (plist-get opt-plist :style)
- (plist-get opt-plist :style-extra)
- "\n" org-export-html-scripts))
- (html-extension (plist-get opt-plist :html-extension))
- (link-validate (plist-get opt-plist :link-validation-function))
- valid thetoc have-headings first-heading-pos
- (odd org-odd-levels-only)
- (region-p (org-region-active-p))
- (rbeg (and region-p (region-beginning)))
- (rend (and region-p (region-end)))
- (subtree-p
- (if (plist-get opt-plist :ignore-subree-p)
- nil
- (when region-p
- (save-excursion
- (goto-char rbeg)
- (and (org-at-heading-p)
- (>= (org-end-of-subtree t t) rend))))))
- (opt-plist (if subtree-p
- (org-export-add-subtree-options opt-plist rbeg)
- opt-plist))
- ;; The following two are dynamically scoped into other
- ;; routines below.
- (org-current-export-dir
- (or pub-dir (org-export-directory :html opt-plist)))
- (org-current-export-file buffer-file-name)
- (level 0) (line "") (origline "") txt todo
- (umax nil)
- (umax-toc nil)
- (filename (if to-buffer nil
- (expand-file-name
- (concat
- (file-name-sans-extension
- (or (and subtree-p
- (org-entry-get (region-beginning)
- "EXPORT_FILE_NAME" t))
- (file-name-nondirectory buffer-file-name)))
- "." html-extension)
- (file-name-as-directory
- (or pub-dir (org-export-directory :html opt-plist))))))
- (current-dir (if buffer-file-name
- (file-name-directory buffer-file-name)
- default-directory))
- (buffer (if to-buffer
- (cond
- ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
- (t (get-buffer-create to-buffer)))
- (find-file-noselect filename)))
- (org-levels-open (make-vector org-level-max nil))
- (date (plist-get opt-plist :date))
- (author (plist-get opt-plist :author))
- (title (or (and subtree-p (org-export-get-title-from-subtree))
- (plist-get opt-plist :title)
- (and (not
- (plist-get opt-plist :skip-before-1st-heading))
- (org-export-grab-title-from-buffer))
- (and buffer-file-name
- (file-name-sans-extension
- (file-name-nondirectory buffer-file-name)))
- "UNTITLED"))
- (html-table-tag (plist-get opt-plist :html-table-tag))
- (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
- (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
- (inquote nil)
- (infixed nil)
- (inverse nil)
- (in-local-list nil)
- (local-list-type nil)
- (local-list-indent nil)
- (llt org-plain-list-ordered-item-terminator)
- (email (plist-get opt-plist :email))
- (language (plist-get opt-plist :language))
- (lang-words nil)
- (head-count 0) cnt
- (start 0)
- (coding-system (and (boundp 'buffer-file-coding-system)
- buffer-file-coding-system))
- (coding-system-for-write (or org-export-html-coding-system
- coding-system))
- (save-buffer-coding-system (or org-export-html-coding-system
- coding-system))
- (charset (and coding-system-for-write
- (fboundp 'coding-system-get)
- (coding-system-get coding-system-for-write
- 'mime-charset)))
- (region
- (buffer-substring
- (if region-p (region-beginning) (point-min))
- (if region-p (region-end) (point-max))))
- (lines
- (org-split-string
- (org-export-preprocess-string
- region
- :emph-multiline t
- :for-html t
- :skip-before-1st-heading
- (plist-get opt-plist :skip-before-1st-heading)
- :drawers (plist-get opt-plist :drawers)
- :todo-keywords (plist-get opt-plist :todo-keywords)
- :tags (plist-get opt-plist :tags)
- :priority (plist-get opt-plist :priority)
- :footnotes (plist-get opt-plist :footnotes)
- :timestamps (plist-get opt-plist :timestamps)
- :archived-trees
- (plist-get opt-plist :archived-trees)
- :select-tags (plist-get opt-plist :select-tags)
- :exclude-tags (plist-get opt-plist :exclude-tags)
- :add-text
- (plist-get opt-plist :text)
- :LaTeX-fragments
- (plist-get opt-plist :LaTeX-fragments))
- "[\r\n]"))
- table-open type
- table-buffer table-orig-buffer
- ind item-type starter didclose
- rpl path attr desc descp desc1 desc2 link
- snumber fnc item-tag
- footnotes footref-seen
- id-file
- )
-
- (let ((inhibit-read-only t))
- (org-unmodified
- (remove-text-properties (point-min) (point-max)
- '(:org-license-to-kill t))))
-
- (message "Exporting...")
-
- (setq org-min-level (org-get-min-level lines))
- (setq org-last-level org-min-level)
- (org-init-section-numbers)
-
- (cond
- ((and date (string-match "%" date))
- (setq date (format-time-string date)))
- (date)
- (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
-
- ;; Get the language-dependent settings
- (setq lang-words (or (assoc language org-export-language-setup)
- (assoc "en" org-export-language-setup)))
-
- ;; Switch to the output buffer
- (set-buffer buffer)
- (let ((inhibit-read-only t)) (erase-buffer))
- (fundamental-mode)
-
- (and (fboundp 'set-buffer-file-coding-system)
- (set-buffer-file-coding-system coding-system-for-write))
-
- (let ((case-fold-search nil)
- (org-odd-levels-only odd))
- ;; create local variables for all options, to make sure all called
- ;; functions get the correct information
- (mapc (lambda (x)
- (set (make-local-variable (nth 2 x))
- (plist-get opt-plist (car x))))
- org-export-plist-vars)
- (setq umax (if arg (prefix-numeric-value arg)
- org-export-headline-levels))
- (setq umax-toc (if (integerp org-export-with-toc)
- (min org-export-with-toc umax)
- umax))
- (unless body-only
- ;; File header
- (insert (format
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
- \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
-<html xmlns=\"http://www.w3.org/1999/xhtml\"
-lang=\"%s\" xml:lang=\"%s\">
-<head>
-<title>%s</title>
-<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
-<meta name=\"generator\" content=\"Org-mode\"/>
-<meta name=\"generated\" content=\"%s\"/>
-<meta name=\"author\" content=\"%s\"/>
-%s
-</head><body>
-"
- language language (org-html-expand title)
- (or charset "iso-8859-1") date author style))
-
- (insert (or (plist-get opt-plist :preamble) ""))
-
- (when (plist-get opt-plist :auto-preamble)
- (if title (insert (format org-export-html-title-format
- (org-html-expand title))))))
-
- (if (and org-export-with-toc (not body-only))
- (progn
- (push (format "<h%d>%s</h%d>\n"
- org-export-html-toplevel-hlevel
- (nth 3 lang-words)
- org-export-html-toplevel-hlevel)
- thetoc)
- (push "<div id=\"text-table-of-contents\">\n" thetoc)
- (push "<ul>\n<li>" thetoc)
- (setq lines
- (mapcar '(lambda (line)
- (if (string-match org-todo-line-regexp line)
- ;; This is a headline
- (progn
- (setq have-headings t)
- (setq level (- (match-end 1) (match-beginning 1))
- 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 " <span class=\"tag\"> \\1</span>" t nil txt)))
- (if (string-match quote-re0 txt)
- (setq txt (replace-match "" t t txt)))
- (setq snumber (org-section-number level))
- (if org-export-with-section-numbers
- (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<ul>\n<li>" thetoc))
- (push "\n" thetoc)))
- (if (< level org-last-level)
- (progn
- (setq cnt (- org-last-level level))
- (while (>= (setq cnt (1- cnt)) 0)
- (push "</li>\n</ul>" thetoc))
- (push "\n" thetoc)))
- ;; Check for targets
- (while (string-match org-any-target-regexp line)
- (setq line (replace-match
- (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
- t t line)))
- (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt)
- (setq txt (replace-match "" t t txt)))
- (push
- (format
- (if todo
- "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
- "</li>\n<li><a href=\"#sec-%s\">%s</a>")
- snumber 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 "</li>\n</ul>\n" thetoc))
- (push "</div>\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 "</pre>\n")
- (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 "<pre class=\"example\">\n"))
- (insert (org-html-protect (match-string 3 line)) "\n")
- (when (or (not lines)
- (not (string-match "^[ \t]*\\(:.*\\)"
- (car lines))))
- (setq infixed nil)
- (insert "</pre>\n"))
- (throw 'nextline nil))
-
- ;; Protected HTML
- (when (get-text-property 0 'org-protected line)
- (let (par)
- (when (re-search-backward
- "\\(<p>\\)\\([ \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)
- (get-text-property 0 'org-protected (car lines))))
- (insert (pop lines) "\n"))
- (and par (insert "<p>\n")))
- (throw 'nextline nil))
-
- ;; Horizontal line
- (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
- (if org-par-open
- (insert "\n</p>\n<hr/>\n<p>\n")
- (insert "\n<hr/>\n"))
- (throw 'nextline nil))
-
- ;; Blockquotes and verse
- (when (equal "ORG-BLOCKQUOTE-START" line)
- (org-close-par-maybe)
- (insert "<blockquote>\n<p>\n")
- (throw 'nextline nil))
- (when (equal "ORG-BLOCKQUOTE-END" line)
- (insert "</p>\n</blockquote>\n")
- (throw 'nextline nil))
- (when (equal "ORG-VERSE-START" line)
- (org-close-par-maybe)
- (insert "\n<p class=\"verse\">\n")
- (setq inverse t)
- (throw 'nextline nil))
- (when (equal "ORG-VERSE-END" line)
- (insert "</p>\n")
- (setq inverse nil)
- (throw 'nextline nil))
- (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))))
- (setq line (concat line "\\\\"))))
-
- ;; make targets to anchors
- (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
- (cond
- ((match-end 2)
- (setq line (replace-match
- (format
- "@<a name=\"%s\" id=\"%s\">@</a>"
- (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 "@<span class=\"target\">" (match-string 1 line) "@</span> ")
-; (concat "@<i>" (match-string 1 line) "@</i> ")
- t t line)))
- (t
- (setq line (replace-match
- (concat "@<a name=\""
- (org-solidify-link-text (match-string 1 line))
- "\" class=\"target\">" (match-string 1 line) "@</a> ")
- 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 start 0)
- (while (string-match org-bracket-link-analytic-regexp++ line start)
- (setq start (match-beginning 0))
- (setq path (save-match-data (org-link-unescape
- (match-string 3 line))))
- (setq type (cond
- ((match-end 2) (match-string 2 line))
- ((save-match-data
- (or (file-name-absolute-p path)
- (string-match "^\\.\\.?/" path)))
- "file")
- (t "internal")))
- (setq path (org-extract-attributes (org-link-unescape path)))
- (setq attr (get-text-property 0 'org-attributes path))
- (setq desc1 (if (match-end 5) (match-string 5 line))
- desc2 (if (match-end 2) (concat type ":" path) path)
- descp (and desc1 (not (equal desc1 desc2)))
- desc (or desc1 desc2))
- ;; Make an image out of the description if that is so wanted
- (when (and descp (org-file-image-p
- desc org-export-html-inline-image-extensions))
- (save-match-data
- (if (string-match "^file:" desc)
- (setq desc (substring desc (match-end 0)))))
- (setq desc (org-add-props
- (concat "<img src=\"" desc "\"/>")
- '(org-protected t))))
- ;; FIXME: do we need to unescape here somewhere?
- (cond
- ((equal type "internal")
- (setq rpl
- (concat
- "<a href=\"#"
- (org-solidify-link-text
- (save-match-data (org-link-unescape path)) nil)
- "\"" attr ">"
- (org-export-html-format-desc desc)
- "</a>")))
- ((and (equal type "id")
- (setq id-file (org-id-find-id-file path)))
- ;; This is an id: link to another file (if it was the same file,
- ;; it would have become an internal link...)
- (setq id-file (file-relative-name
- id-file (file-name-directory org-current-export-file)))
- (setq id-file (concat (file-name-sans-extension id-file)
- "." html-extension))
- (setq rpl (concat "<a href=\"" id-file "#" path "\""
- attr ">"
- (org-export-html-format-desc desc)
- "</a>")))
- ((member type '("http" "https"))
- ;; standard URL, just check if we need to inline an image
- (if (and (or (eq t org-export-html-inline-images)
- (and org-export-html-inline-images (not descp)))
- (org-file-image-p
- path org-export-html-inline-image-extensions))
- (setq rpl (org-export-html-format-image
- (concat type ":" path)))
- (setq link (concat type ":" path))
- (setq rpl (concat "<a href=\""
- (org-export-html-format-href link)
- "\"" attr ">"
- (org-export-html-format-desc desc)
- "</a>"))))
- ((member type '("ftp" "mailto" "news"))
- ;; standard URL
- (setq link (concat type ":" path))
- (setq rpl (concat "<a href=\""
- (org-export-html-format-href link)
- "\"" attr ">"
- (org-export-html-format-desc desc)
- "</a>")))
-
- ((string= type "coderef")
-
- (setq rpl (format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
- path path path
- (format (org-export-get-coderef-format path (and descp desc))
- (cdr (assoc path org-export-code-refs))))))
-
- ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
- ;; The link protocol has a function for format the link
- (setq rpl
- (save-match-data
- (funcall fnc (org-link-unescape path) desc1 'html))))
-
- ((string= type "file")
- ;; FILE link
- (let* ((filename path)
- (abs-p (file-name-absolute-p filename))
- thefile file-is-image-p search)
- (save-match-data
- (if (string-match "::\\(.*\\)" filename)
- (setq search (match-string 1 filename)
- filename (replace-match "" t nil filename)))
- (setq valid
- (if (functionp link-validate)
- (funcall link-validate filename current-dir)
- t))
- (setq file-is-image-p
- (org-file-image-p
- filename org-export-html-inline-image-extensions))
- (setq thefile (if abs-p (expand-file-name filename) filename))
- (when (and org-export-html-link-org-files-as-html
- (string-match "\\.org$" thefile))
- (setq thefile (concat (substring thefile 0
- (match-beginning 0))
- "." html-extension))
- (if (and search
- ;; make sure this is can be used as target search
- (not (string-match "^[0-9]*$" search))
- (not (string-match "^\\*" search))
- (not (string-match "^/.*/$" search)))
- (setq thefile (concat thefile "#"
- (org-solidify-link-text
- (org-link-unescape search)))))
- (when (string-match "^file:" desc)
- (setq desc (replace-match "" t t desc))
- (if (string-match "\\.org$" desc)
- (setq desc (replace-match "" t t desc))))))
- (setq rpl (if (and file-is-image-p
- (or (eq t org-export-html-inline-images)
- (and org-export-html-inline-images
- (not descp))))
- (org-export-html-format-image thefile)
- (concat "<a href=\"" thefile "\"" attr ">"
- (org-export-html-format-desc desc)
- "</a>")))
- (if (not valid) (setq rpl desc))))
-
- (t
- ;; just publish the path, as default
- (setq rpl (concat "<i><" type ":"
- (save-match-data (org-link-unescape path))
- "></i>"))))
- (setq line (replace-match rpl t t line)
- start (+ start (length rpl))))
-
- ;; TODO items
- (if (and (string-match org-todo-line-regexp line)
- (match-beginning 2))
-
- (setq line
- (concat (substring line 0 (match-beginning 2))
- "<span class=\""
- (if (member (match-string 2 line)
- org-done-keywords)
- "done" "todo")
- "\">" (match-string 2 line)
- "</span>" (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
- "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
- (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)))
- 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)))
- (when in-local-list
- ;; Close any local lists before inserting a new header line
- (while local-list-type
- (org-close-li (car local-list-type))
- (insert (format "</%sl>\n" (car local-list-type)))
- (pop local-list-type))
- (setq local-list-indent nil
- in-local-list nil))
- (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)
- ;; QUOTES
- (when (string-match quote-re line)
- (org-close-par-maybe)
- (insert "<pre>")
- (setq inquote t)))
-
- ((and org-export-with-tables
- (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
- (if (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))))
- (t
- ;; Normal lines
- (when (string-match
- (cond
- ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
- ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
- ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
- (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
- line)
- (setq ind (org-get-string-indentation line)
- item-type (if (match-beginning 4) "o" "u")
- starter (if (match-beginning 2)
- (substring (match-string 2 line) 0 -1))
- line (substring line (match-beginning 5))
- item-tag nil)
- (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
- (setq item-type "d"
- item-tag (match-string 1 line)
- line (substring line (match-end 0))))
- (when (and (not (equal item-type "d"))
- (not (string-match "[^ \t]" line)))
- ;; empty line. Pretend indentation is large.
- (setq ind (if org-empty-line-terminates-plain-lists
- 0
- (1+ (or (car local-list-indent) 1)))))
- (setq didclose nil)
- (while (and in-local-list
- (or (and (= ind (car local-list-indent))
- (not starter))
- (< ind (car local-list-indent))))
- (setq didclose t)
- (org-close-li (car local-list-type))
- (insert (format "</%sl>\n" (car local-list-type)))
- (pop local-list-type) (pop local-list-indent)
- (setq in-local-list local-list-indent))
- (cond
- ((and starter
- (or (not in-local-list)
- (> ind (car local-list-indent))))
- ;; Start new (level of) list
- (org-close-par-maybe)
- (insert (cond
- ((equal item-type "u") "<ul>\n<li>\n")
- ((equal item-type "o") "<ol>\n<li>\n")
- ((equal item-type "d")
- (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
- (push item-type local-list-type)
- (push ind local-list-indent)
- (setq in-local-list t))
- (starter
- ;; continue current list
- (org-close-li (car local-list-type))
- (insert (cond
- ((equal (car local-list-type) "d")
- (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
- (t "<li>\n"))))
- (didclose
- ;; we did close a list, normal text follows: need <p>
- (org-open-par)))
- (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
- (setq line
- (replace-match
- (if (equal (match-string 1 line) "X")
- "<b>[X]</b>"
- "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
- t t line))))
-
- ;; 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 "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
-
- ;; Check if the line break needs to be conserved
- (cond
- ((string-match "\\\\\\\\[ \t]*$" line)
- (setq line (replace-match "<br/>" t t line)))
- (org-export-preserve-breaks
- (setq line (concat line "<br/>"))))
-
- ;; Check if a paragraph should be started
- (let ((start 0))
- (while (and org-par-open
- (string-match "\\\\par\\>" line start))
- ;; Leave a space in the </p> so that the footnote matcher
- ;; does not see this.
- (if (not (get-text-property (match-beginning 0)
- 'org-protected line))
- (setq line (replace-match "</p ><p >" t t line)))
- (setq start (match-end 0))))
-
- (insert line "\n")))))
-
- ;; Properly close all local lists and other lists
- (when inquote
- (insert "</pre>\n")
- (org-open-par))
- (when in-local-list
- ;; Close any local lists before inserting a new header line
- (while local-list-type
- (org-close-li (car local-list-type))
- (insert (format "</%sl>\n" (car local-list-type)))
- (pop local-list-type))
- (setq local-list-indent nil
- in-local-list nil))
- (org-html-level-start 1 nil umax
- (and org-export-with-toc (<= level umax))
- head-count)
- ;; the </div> to close the last text-... div.
- (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
-
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
- (push (match-string 0) footnotes)
- (replace-match "" t t)))
- (when footnotes
- (insert (format org-export-html-footnotes-section
- (or (nth 4 lang-words) "Footnotes")
- (mapconcat 'identity (nreverse footnotes) "\n"))
- "\n"))
- (unless body-only
- (when (plist-get opt-plist :auto-postamble)
- (insert "<div id=\"postamble\">")
- (when (and org-export-author-info author)
- (insert "<p class=\"author\"> "
- (nth 1 lang-words) ": " author "\n")
- (when email
- (if (listp (split-string email ",+ *"))
- (mapc (lambda(e)
- (insert "<a href=\"mailto:" e "\"><"
- e "></a>\n"))
- (split-string email ",+ *"))
- (insert "<a href=\"mailto:" email "\"><"
- email "></a>\n")))
- (insert "</p>\n"))
- (when (and date org-export-time-stamp-file)
- (insert "<p class=\"date\"> "
- (nth 2 lang-words) ": "
- date "</p>\n"))
- (when org-export-creator-info
- (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
- org-version emacs-major-version)))
- (insert "</div>"))
-
- (if org-export-html-with-timestamp
- (insert org-export-html-html-helper-timestamp))
- (insert (or (plist-get opt-plist :postamble) ""))
- (insert "</body>\n</html>\n"))
-
- (unless (plist-get opt-plist :buffer-will-be-killed)
- (normal-mode)
- (if (eq major-mode default-major-mode) (html-mode)))
-
- ;; insert the table of contents
- (goto-char (point-min))
- (when thetoc
- (if (or (re-search-forward
- "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
- (re-search-forward
- "\\[TABLE-OF-CONTENTS\\]" nil t))
- (progn
- (goto-char (match-beginning 0))
- (replace-match ""))
- (goto-char first-heading-pos)
- (when (looking-at "\\s-*</p>")
- (goto-char (match-end 0))
- (insert "\n")))
- (insert "<div id=\"table-of-contents\">\n")
- (mapc 'insert thetoc)
- (insert "</div>\n"))
- ;; remove empty paragraphs and lists
- (goto-char (point-min))
- (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
- (replace-match ""))
- (goto-char (point-min))
- (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
- (replace-match ""))
- (goto-char (point-min))
- (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
- (replace-match ""))
- ;; Convert whitespace place holders
- (goto-char (point-min))
- (let (beg end n)
- (while (setq beg (next-single-property-change (point) 'org-whitespace))
- (setq n (get-text-property beg 'org-whitespace)
- end (next-single-property-change beg 'org-whitespace))
- (goto-char beg)
- (delete-region beg end)
- (insert (format "<span style=\"visibility:hidden;\">%s</span>"
- (make-string n ?x)))))
- (or to-buffer (save-buffer))
- (goto-char (point-min))
- (message "Exporting... done")
- (if (eq to-buffer 'string)
- (prog1 (buffer-substring (point-min) (point-max))
- (kill-buffer (current-buffer)))
- (current-buffer)))))
-
-(defun org-export-get-coderef-format (path desc)
- (save-match-data
- (if (and desc (string-match
- (regexp-quote (concat "(" path ")"))
- desc))
- (replace-match "%s" t t desc)
- "%s")))
-
-
-(defun org-export-html-format-href (s)
- "Make sure the S is valid as a href reference in an XHTML document."
- (save-match-data
- (let ((start 0))
- (while (string-match "&" s start)
- (setq start (+ (match-beginning 0) 3)
- s (replace-match "&" t t s)))))
- s)
-
-(defun org-export-html-format-desc (s)
- "Make sure the S is valid as a description in a link."
- (if (and s (not (get-text-property 1 'org-protected s)))
- (save-match-data
- (org-html-do-expand s))
- s))
-
-(defun org-export-html-format-image (src)
- "Create image tag with source and attributes."
- (save-match-data
- (if (string-match "^ltxpng/" src)
- (format "<img src=\"%s\"/>" src)
- (let* ((caption (org-find-text-property-in-string 'org-caption src))
- (attr (org-find-text-property-in-string 'org-attributes src))
- (label (org-find-text-property-in-string 'org-label src)))
- (format "<div %sclass=\"figure\">
-<p><img src=\"%s\"%s /></p>%s
-</div>"
- (if label (format "id=\"%s\" " label) "")
- src
- (if (string-match "\\<alt=" (or attr ""))
- (concat " " attr )
- (concat " " attr " alt=\"" src "\""))
- (if caption (concat "\n<p>" caption "</p>") ""))))))
-