tag, but you may change the options like
borders and spacing."
:group 'org-export-html
:type 'string)
(defcustom org-export-table-header-tags '("" . " | ")
"The opening tag for table header fields.
This is customizable so that alignment options can be specified.
The first %s will be filled with the scope of the field, either row or col.
The second %s will be replaced by a style entry to align the field.
See also the variable `org-export-html-table-use-header-tags-for-first-column'.
See also the variable `org-export-html-table-align-individual-fields'."
:group 'org-export-tables
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-export-table-data-tags '("" . " | ")
"The opening tag for table data fields.
This is customizable so that alignment options can be specified.
The first %s will be filled with the scope of the field, either row or col.
The second %s will be replaced by a style entry to align the field.
See also the variable `org-export-html-table-align-individual-fields'."
:group 'org-export-tables
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-export-table-row-tags '("" . "
")
"The opening tag for table data fields.
This is customizable so that alignment options can be specified.
Instead of strings, these can be Lisp forms that will be evaluated
for each row in order to construct the table row tags. During evaluation,
the variable `head' will be true when this is a header line, nil when this
is a body line. And the variable `nline' will contain the line number,
starting from 1 in the first header line. For example
(setq org-export-table-row-tags
(cons '(if head
\"\"
(if (= (mod nline 2) 1)
\"
\"
\"
\"))
\"
\"))
will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
:group 'org-export-tables
:type '(cons
(choice :tag "Opening tag"
(string :tag "Specify")
(sexp))
(choice :tag "Closing tag"
(string :tag "Specify")
(sexp))))
(defcustom org-export-html-table-align-individual-fields t
"Non-nil means attach style attributes for alignment to each table field.
When nil, alignment will only be specified in the column tags, but this
is ignored by some browsers (like Firefox, Safari). Opera does it right
though."
:group 'org-export-tables
:type 'boolean)
(defcustom org-export-html-table-use-header-tags-for-first-column nil
"Non-nil means format column one in tables with header tags.
When nil, also column one will use data tags."
:group 'org-export-tables
:type 'boolean)
(defcustom org-export-html-validation-link
"Validate XHTML 1.0"
"Link to HTML validation service."
:group 'org-export-html
:type 'string)
(defcustom org-export-html-with-timestamp nil
"If non-nil, write timestamp into the exported HTML text.
If non-nil, write `org-export-html-html-helper-timestamp' into the
exported HTML text. Otherwise, the buffer will just be saved to
a file."
:group 'org-export-html
:type 'boolean)
(defcustom org-export-html-html-helper-timestamp
"
\n"
"The HTML tag used as timestamp delimiter for HTML-helper-mode."
:group 'org-export-html
:type 'string)
(defcustom org-export-html-protect-char-alist
'(("&" . "&")
("<" . "<")
(">" . ">"))
"Alist of characters to be converted by `org-html-protect'."
:type '(repeat (cons (string :tag "Character")
(string :tag "HTML equivalent"))))
(defgroup org-export-htmlize nil
"Options for processing examples with htmlize.el."
:tag "Org Export Htmlize"
:group 'org-export-html)
(defcustom org-export-htmlize-output-type 'inline-css
"Output type to be used by htmlize when formatting code snippets.
Choices are `css', to export the CSS selectors only, or `inline-css', to
export the CSS attribute values inline in the HTML. We use as default
`inline-css', in order to make the resulting HTML self-containing.
However, this will fail when using Emacs in batch mode for export, because
then no rich font definitions are in place. It will also not be good if
people with different Emacs setup contribute HTML files to a website,
because the fonts will represent the individual setups. In these cases,
it is much better to let Org/Htmlize assign classes only, and to use
a style file to define the look of these classes.
To get a start for your css file, start Emacs session and make sure that
all the faces you are interested in are defined, for example by loading files
in all modes you want. Then, use the command
\\[org-export-htmlize-generate-css] to extract class definitions."
:group 'org-export-htmlize
:type '(choice (const css) (const inline-css)))
(defcustom org-export-htmlize-css-font-prefix "org-"
"The prefix for CSS class names for htmlize font specifications."
:group 'org-export-htmlize
:type 'string)
(defcustom org-export-htmlized-org-css-url nil
"URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
Normally when creating an htmlized version of an Org buffer, htmlize will
create CSS to define the font colors. However, this does not work when
converting in batch mode, and it also can look bad if different people
with different fontification setup work on the same website.
When this variable is non-nil, creating an htmlized version of an Org buffer
using `org-export-as-org' will remove the internal CSS section and replace it
with a link to this URL."
:group 'org-export-htmlize
:type '(choice
(const :tag "Keep internal css" nil)
(string :tag "URL or local href")))
;;; Hooks
(defvar org-export-html-after-blockquotes-hook nil
"Hook run during HTML export, after blockquote, verse, center are done.")
(defvar org-export-html-final-hook nil
"Hook run at the end of HTML export, in the new buffer.")
;;; HTML export
(defun org-export-html-preprocess (parameters)
"Convert LaTeX fragments to images."
(when (and org-current-export-file
(plist-get parameters :LaTeX-fragments))
(org-format-latex
(concat "ltxpng/" (file-name-sans-extension
(file-name-nondirectory
org-current-export-file)))
org-current-export-dir nil "Creating LaTeX image %s"
nil nil
(cond
((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
(t nil))))
(goto-char (point-min))
(let (label l1)
(while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
(org-if-unprotected-at (match-beginning 1)
(setq label (match-string 1))
(save-match-data
(if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
(setq l1 (substring label (match-beginning 1)))
(setq l1 label)))
(replace-match (format "[[#%s][%s]]" label l1) t t)))))
;;;###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)
(when org-export-kill-product-buffer-when-displayed
(kill-buffer (current-buffer))))
;;;###autoload
(defun org-export-as-html-batch ()
"Call the function `org-export-as-html'.
This function can 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*")
(when org-export-show-temporary-export-buffer
(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-subtree-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)
;;; org-html-cvt-link-fn
(defconst org-html-cvt-link-fn
nil
"Function to convert link URLs to exportable URLs.
Takes two arguments, TYPE and PATH.
Returns exportable url as (TYPE PATH), or nil to signal that it
didn't handle this case.
Intended to be locally bound around a call to `org-export-as-html'." )
(defun org-html-cvt-org-as-html (opt-plist type path)
"Convert an org filename to an equivalent html filename.
If TYPE is not file, just return `nil'.
See variable `org-export-html-link-org-files-as-html'"
(save-match-data
(and
org-export-html-link-org-files-as-html
(string= type "file")
(string-match "\\.org$" path)
(progn
(list
"file"
(concat
(substring path 0 (match-beginning 0))
"."
(plist-get opt-plist :html-extension)))))))
;;; org-html-should-inline-p
(defun org-html-should-inline-p (filename descp)
"Return non-nil if link FILENAME should be inlined.
The decision to inline the FILENAME link is based on the current
settings. DESCP is the boolean of whether there was a link
description. See variables `org-export-html-inline-images' and
`org-export-html-inline-image-extensions'."
(declare (special
org-export-html-inline-images
org-export-html-inline-image-extensions))
(and (or (eq t org-export-html-inline-images)
(and org-export-html-inline-images (not descp)))
(org-file-image-p
filename org-export-html-inline-image-extensions)))
;;; org-html-format-org-link
(defun org-html-format-org-link (opt-plist type-1 path fragment desc attr
descp)
"Make an HTML link.
OPT-PLIST is an options list.
TYPE is the device-type of the link (THIS://foo.html)
PATH is the path of the link (http://THIS#locationx)
FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
DESC is the link description, if any.
ATTR is a string of other attributes of the a element.
MAY-INLINE-P allows inlining it as an image."
(declare (special org-par-open))
(save-match-data
(let* ((may-inline-p
(and (member type-1 '("http" "https" "file"))
(org-html-should-inline-p path descp)
(not fragment)))
(type (if (equal type-1 "id") "file" type-1))
(filename path)
;;First pass. Just sanity stuff.
(components-1
(cond
((string= type "file")
(list
type
;;Substitute just if original path was absolute.
;;(Otherwise path must remain relative)
(if (file-name-absolute-p path)
(concat "file://" (expand-file-name path))
path)))
((string= type "")
(list nil path))
(t (list type path))))
;;Second pass. Components converted so they can refer
;;to a remote site.
(components-2
(or
(and org-html-cvt-link-fn
(apply org-html-cvt-link-fn
opt-plist components-1))
(apply #'org-html-cvt-org-as-html
opt-plist components-1)
components-1))
(type (first components-2))
(thefile (second components-2)))
;;Third pass. Build final link except for leading type
;;spec.
(cond
((or
(not type)
(string= type "http")
(string= type "https")
(string= type "file"))
(if fragment
(setq thefile (concat thefile "#" fragment))))
(t))
;;Final URL-build, for all types.
(setq thefile
(let
((str (org-export-html-format-href thefile)))
(if (and type (not (string= "file" type)))
(concat type ":" str)
str)))
(if may-inline-p
(org-export-html-format-image thefile)
(org-parse-format
'LINK (org-export-html-format-desc desc) thefile attr)))))
(defun org-html-format-inline-image (desc)
;; FIXME: alt text missing here?
(org-html-format-tags '("" . "") "" desc))
(defvar org-parse-link-description-is-image)
(defun org-parse-format-org-link (line opt-plist)
"Return LINE with markup of Org mode links.
OPT-PLIST is the export options list."
(let ((start 0)
(current-dir (if buffer-file-name
(file-name-directory buffer-file-name)
default-directory))
(link-validate (plist-get opt-plist :link-validation-function))
type id-file fnc
rpl path attr desc descp desc1 desc2 link
org-parse-link-description-is-image)
(while (string-match org-bracket-link-analytic-regexp++ line start)
(setq org-parse-link-description-is-image nil)
(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))
(setq org-parse-link-description-is-image t)
(save-match-data
(if (string-match "^file:" desc)
(setq desc (substring desc (match-end 0)))))
(save-match-data
(setq desc (org-add-props
(org-parse-format 'INLINE-IMAGE desc)
'(org-protected t)))))
(cond
((equal type "internal")
(let
((frag-0
(if (= (string-to-char path) ?#)
(substring path 1)
path)))
(setq rpl
(org-parse-format
'ORG-LINK opt-plist "" "" (org-solidify-link-text
(save-match-data
(org-link-unescape frag-0))
nil) desc attr descp))))
((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...)
(save-match-data
(setq id-file (file-relative-name
id-file
(file-name-directory org-current-export-file)))
(setq rpl
(org-parse-format
'ORG-LINK opt-plist type id-file
(concat (if (org-uuidgen-p path) "ID-") path)
desc attr descp))))
((member type '("http" "https"))
;; standard URL, can inline as image
(setq rpl
(org-parse-format
'ORG-LINK opt-plist type path nil desc attr descp)))
((member type '("ftp" "mailto" "news"))
;; standard URL, can't inline as image
(setq rpl
(org-parse-format
'ORG-LINK opt-plist type path nil desc attr descp)))
((string= type "coderef")
(let*
((coderef-str (format "coderef-%s" path))
(attr-1
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
coderef-str coderef-str)))
(setq rpl
(org-parse-format
'ORG-LINK opt-plist type "" coderef-str
(format
(org-export-get-coderef-format
path
(and descp desc))
(cdr (assoc path org-export-code-refs))) attr-1 descp))))
((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
(save-match-data
(let*
((components
(if
(string-match "::\\(.*\\)" path)
(list
(replace-match "" t nil path)
(match-string 1 path))
(list path nil)))
;;The proper path, without a fragment
(path-1
(first components))
;;The raw fragment
(fragment-0
(second components))
;;Check the fragment. If it can't be used as
;;target fragment we'll pass nil instead.
(fragment-1
(if
(and fragment-0
(not (string-match "^[0-9]*$" fragment-0))
(not (string-match "^\\*" fragment-0))
(not (string-match "^/.*/$" fragment-0)))
(org-solidify-link-text
(org-link-unescape fragment-0))
nil))
(desc-2
;;Description minus "file:" and ".org"
(if (string-match "^file:" desc)
(let
((desc-1 (replace-match "" t t desc)))
(if (string-match "\\.org$" desc-1)
(replace-match "" t t desc-1)
desc-1))
desc)))
(setq rpl
(if
(and
(functionp link-validate)
(not (funcall link-validate path-1 current-dir)))
desc
(org-parse-format
'ORG-LINK opt-plist "file" path-1 fragment-1
desc-2 attr descp))))))
(t
;; just publish the path, as default
(setq rpl (concat "<" type ":"
(save-match-data (org-link-unescape path))
">"))))
(setq line (replace-match rpl t t line)
start (+ start (length rpl))))
line))
;;; org-export-as-html
;;;###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. HIDDEN is obsolete and does nothing.
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
..., without even the body tags themselves. When
PUB-DIR is set, use this as the publishing directory."
(interactive "P")
(run-hooks 'org-export-first-hook)
(let* ((org-parse-get-callback 'org-html-get))
(org-do-export arg hidden ext-plist to-buffer body-only pub-dir)))
(defun org-do-export (arg &optional hidden ext-plist
to-buffer body-only pub-dir)
"Export the outline as a pretty HTML file."
;; 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* (org-html-protect org-par-open
(org-parse-entity-control-callbacks-alist
(org-parse-get 'ENTITY-CONTROL))
(org-parse-entity-format-callbacks-alist
(org-parse-get 'ENTITY-FORMAT))
(opt-plist
(org-export-process-option-filters
(org-combine-plists (org-default-export-plist)
ext-plist
(org-infile-export-plist))))
(body-only (or body-only (plist-get opt-plist :body-only)))
valid org-html-dyn-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-subtree-p)
nil
(when region-p
(save-excursion
(goto-char rbeg)
(and (org-at-heading-p)
(>= (org-end-of-subtree t t) rend))))))
(level-offset (if subtree-p
(save-excursion
(goto-char rbeg)
(+ (funcall outline-level)
(if org-odd-levels-only 1 0)))
0))
(opt-plist (setq org-export-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-parse-get 'EXPORT-DIR 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)))
"." (org-parse-get 'FILE-NAME-EXTENSION opt-plist))
(file-name-as-directory
(or pub-dir (org-parse-get 'EXPORT-DIR 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-parse-get 'EXPORT-BUFFER-NAME)))
(t (get-buffer-create to-buffer)))
(find-file-noselect
(or (let ((f (org-parse-get 'INIT-METHOD)))
(and f (functionp f) (funcall f filename)))
filename))))
(org-levels-open (make-vector org-level-max nil))
(date (plist-get opt-plist :date))
(date (cond
((and date (string-match "%" date))
(format-time-string date))
(date date)
(t (format-time-string "%Y-%m-%d %T %Z"))))
(dummy (setq opt-plist (plist-put opt-plist :effective-date date)))
(title (org-html-expand
(or (and subtree-p (org-export-get-title-from-subtree))
(plist-get opt-plist :title)
(and (not body-only)
(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")))
(dummy (setq opt-plist (plist-put opt-plist :title title)))
(html-table-tag (plist-get opt-plist :html-table-tag))
(quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
(quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
(org-parse-dyn-current-environment nil)
;; Get the language-dependent settings
(lang-words (or (assoc (plist-get opt-plist :language)
org-export-language-setup)
(assoc "en" org-export-language-setup)))
(dummy (setq opt-plist (plist-put opt-plist :lang-words lang-words)))
(head-count 0) cnt
(start 0)
(coding-system-for-write (org-html-get-coding-system-for-write))
(save-buffer-coding-system (org-html-get-coding-system-for-save))
(region
(buffer-substring
(if region-p (region-beginning) (point-min))
(if region-p (region-end) (point-max))))
(org-export-have-math nil)
(insertion-point-for-normalized-footnotes 'point-min)
(org-parse-backend (org-parse-get 'BACKEND))
(lines
(org-split-string
(org-export-preprocess-string
region
:emph-multiline t
:for-backend org-parse-backend
: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
table-buffer table-orig-buffer
ind
rpl path attr desc descp desc1 desc2 link
snumber fnc
footnotes footref-seen
org-html-output-buffer
org-html-footnote-definitions
org-html-footnote-number
org-html-footnote-buffer
org-parse-table-of-contents
href
)
(let ((inhibit-read-only t))
(org-unmodified
(remove-text-properties (point-min) (point-max)
'(:org-license-to-kill t))))
(message "Exporting...")
(org-init-section-numbers)
;; Switch to the output buffer
(setq org-html-output-buffer buffer)
(set-buffer org-html-output-buffer)
(let ((inhibit-read-only t)) (erase-buffer))
(fundamental-mode)
(org-install-letbind)
(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))
(when (and org-export-with-toc (not body-only))
(setq lines (org-html-prepare-toc
lines level-offset opt-plist umax-toc)))
(unless body-only
(org-parse-begin 'DOCUMENT-CONTENT opt-plist)
(org-parse-begin 'DOCUMENT-BODY opt-plist))
(setq head-count 0)
(org-init-section-numbers)
(org-parse-begin-paragraph)
(while (setq line (pop lines) origline line)
(catch 'nextline
(when (and (org-parse-current-environment-p 'quote)
(string-match "^\\*+ " line))
(org-parse-end-environment 'quote))
(when (org-parse-current-environment-p 'quote)
(insert (org-parse-format 'PLAIN line))
(throw 'nextline nil))
;; Fixed-width, verbatim lines (examples)
(when (and org-export-with-fixed-width
(string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
(when (not (org-parse-current-environment-p 'fixedwidth))
(org-parse-begin-environment 'fixedwidth))
(insert (org-parse-format 'PLAIN (match-string 3 line)))
(when (or (not lines)
(not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
(car lines))))
(org-parse-end-environment 'fixedwidth))
(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 ((ind (get-text-property 0 'original-indentation line)))
(with-org-html-preserve-paragraph-state
(insert (org-parse-format 'PLAIN line))
(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 (org-parse-format 'PLAIN (pop lines))))))
(throw 'nextline nil))
;; Blockquotes, verse, and center
(when (string-match "^ORG-\\(.+\\)-\\(START\\|END\\)$" line)
(let* ((style (intern (downcase (match-string 1 line))))
(f (cdr (assoc (match-string 2 line)
'(("START" . org-parse-begin-environment)
("END" . org-parse-end-environment))))))
(when (memq style '(blockquote verse center))
(funcall f style)
(throw 'nextline nil))))
(run-hooks 'org-export-html-after-blockquotes-hook)
(when (org-parse-current-environment-p 'verse)
(let ((i (org-get-string-indentation line)))
(if (> i 0)
(setq line (concat
(let ((org-html-protect t))
(org-parse-format 'SPACES (* 2 i)))
" " (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
(let ((org-html-protect t))
(org-parse-format
'ANCHOR "" (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
(let ((org-html-protect t))
(org-parse-format
'FONTIFY (match-string 1 line) "target"))
;; (concat "@" (match-string 1 line) "@ ")
t t line)))
(t
(setq line (replace-match
(concat
(let ((org-html-protect t))
(org-parse-format
'ANCHOR (match-string 1 line)
(org-solidify-link-text (match-string 1 line))
"target")) " ")
t t line)))))
(let ((org-html-protect t))
(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)))
(setq line (org-parse-format-org-link 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-parse-format 'TODO (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].*?\\)[ \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)) refcnt a)
(if (setq a (assoc n footref-seen))
(progn
(setcdr a (1+ (cdr a)))
(setq refcnt (cdr a)))
(setq refcnt 1)
(push (cons n 1) footref-seen))
(setq line
(replace-match
(concat
(or (match-string 1 line) "")
(org-parse-format
'FOOTNOTE-REFERENCE
n (cdr (assoc n org-html-footnote-definitions))
refcnt))
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)))
(unless org-html-dyn-first-heading-pos
(setq org-html-dyn-first-heading-pos (point)))
(org-parse-begin 'LEVEL level txt umax
(and org-export-with-toc (<= level umax))
head-count)
;; QUOTES
(when (string-match quote-re line)
(org-parse-begin-environment 'quote)))
((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-parse-end-paragraph)
(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)
(with-org-html-preserve-paragraph-state
(insert (org-parse-format 'HORIZONTAL-LINE)))
(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.
(when (string-match "^ [-+*]-\\|^[ \t]*$" line)
(when org-html-footnote-number
(org-parse-end-footnote-definition org-html-footnote-number)
(setq org-html-footnote-number nil))
(org-parse-begin-paragraph))
;; 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-parse-end-paragraph)
(setq org-html-footnote-number (match-string 1 line))
(setq line (replace-match "" t t line))
(org-parse-begin-footnote-definition org-html-footnote-number)))
;; Check if the line break needs to be conserved
(cond
((string-match "\\\\\\\\[ \t]*$" line)
(setq line (replace-match
(org-parse-format 'LINE-BREAK)
t t line)))
(org-export-preserve-breaks
(setq line (concat line (org-parse-format 'LINE-BREAK)))))
;; Check if a paragraph should be started
(let ((start 0))
(while (and org-par-open
(string-match "\\\\par\\>" line start))
(error "FIXME")
;; Leave a space in the 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 (org-parse-format 'PLAIN line))))))
;; Properly close all local lists and other lists
(when (org-parse-current-environment-p 'quote)
(org-parse-end-environment 'quote))
(org-parse-end 'LEVEL 1 umax)
;; the to close the last text-... div.
(when (and (> umax 0) org-html-dyn-first-heading-pos)
(org-parse-end 'SECTION))
(org-parse-end 'DOCUMENT-BODY opt-plist)
(unless body-only
(org-parse-end 'DOCUMENT-CONTENT))
(unless (plist-get opt-plist :buffer-will-be-killed)
(set-auto-mode t))
(org-parse-end 'EXPORT)
(goto-char (point-min))
(or (org-export-push-to-kill-ring
(upcase (symbol-name org-parse-backend)))
(message "Exporting... done"))
(cond
((not to-buffer)
(let ((f (org-parse-get 'SAVE-METHOD)))
(or (and f (functionp f) (funcall f filename))
(save-buffer)))
(current-buffer))
((eq to-buffer 'string)
(prog1 (buffer-substring (point-min) (point-max))
(kill-buffer (current-buffer))))
(t (current-buffer))))))
(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 ""
src (org-find-text-property-in-string 'org-latex-src 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))
(caption (and caption (org-html-do-expand caption)))
(img (format ""
src
(if (string-match "\\" . "\n")
(concat
(org-parse-format '("\n" . "
") img)
(org-parse-format '("\n" . "
") caption))
extra)))
(buffer-string))
img)))))
(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)))))
(defun org-table-get-colalign-info (lines)
(let ((forced-aligns (org-find-text-property-in-string
'org-forced-aligns (car lines))))
(when (and forced-aligns org-table-clean-did-remove-column)
(setq forced-aligns
(mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
forced-aligns))
(defvar org-table-style)
(defvar org-table-ncols)
(defvar org-table-rownum)
(defvar org-table-is-styled)
(defvar org-table-begin-marker)
(defvar org-table-num-numeric-items-per-column)
(defvar org-table-colalign-info)
(defvar org-table-colalign-vector)
(defvar org-table-number-fraction) ; defined in org-table.el
(defun org-do-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)))
(caption (and caption (org-html-do-expand caption)))
(label (org-find-text-property-in-string 'org-label (car lines)))
(org-table-colalign-info (org-table-get-colalign-info lines))
(attributes (org-find-text-property-in-string 'org-attributes
(car lines)))
(head (and org-export-highlight-first-table-line
(delq nil (mapcar
(lambda (x) (string-match "^[ \t]*|-" x))
(cdr lines)))))
(org-table-rownum -1) org-table-ncols i (cnt 0)
tbopen line fields
org-table-current-rowgroup-is-header
org-table-rowgroup-open
org-table-num-numeric-items-per-column
org-table-colalign-vector n
org-table-rowgroup-info
org-table-begin-marker
(org-table-style 'org-table)
org-table-is-styled)
(cond
(splice
(setq org-table-is-styled nil)
(while (setq line (pop lines))
(unless (string-match "^[ \t]*|-" line)
(insert
(org-parse-format-table-row
(org-split-string line "[ \t]*|[ \t]*")) "\n"))))
(t
(setq org-table-is-styled t)
(org-parse-begin 'TABLE caption label attributes)
(setq org-table-begin-marker (point))
(org-parse-begin-table-rowgroup head)
(while (setq line (pop lines))
(cond
((string-match "^[ \t]*|-" line)
(when lines (org-parse-begin-table-rowgroup)))
(t
(insert
(org-parse-format-table-row
(org-split-string line "[ \t]*|[ \t]*")) "\n"))))
(org-parse-end 'TABLE-ROWGROUP)
(org-parse-end-table)))))
(defun org-format-org-table-html (lines &optional splice no-css)
(with-temp-buffer
(org-do-format-org-table-html lines splice no-css)
(buffer-substring-no-properties (point-min) (point-max))))
(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-do-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
(org-table-current-rowgroup-is-header
org-export-highlight-first-table-line)
(caption nil)
(attributes nil)
(label nil)
(org-table-style 'table-table)
(org-table-is-styled nil)
fields org-table-ncols i (org-table-rownum -1))
(org-parse-begin 'TABLE caption label attributes)
(while (setq line (pop lines))
(setq empty (org-parse-format 'SPACES 1))
(cond
((string-match "^[ \t]*\\+-" line)
(when field-buffer
(let ((org-export-table-row-tags '("" . "
"))
(org-export-html-table-use-header-tags-for-first-column nil))
(insert (org-parse-format-table-row field-buffer empty)))
(setq org-table-current-rowgroup-is-header nil)
(setq field-buffer nil)))
(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 (org-parse-format 'LINE-BREAK)
(pop fields)))
field-buffer))
(setq field-buffer fields)))))
(org-parse-end-table)))
(defun org-format-table-table-html (lines)
(with-temp-buffer
(org-do-format-table-table-html lines)
(buffer-substring-no-properties (point-min) (point-max))))
(defun org-format-table-table-html-using-table-generate-source (lines)
"Format a table into html, using `table-generate-source' from table.el.
This has the advantage that cell- or row-spanning is allowed.
But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
(require 'table)
(with-current-buffer (get-buffer-create " org-tmp1 ")
(erase-buffer)
(insert (mapconcat 'identity lines "\n"))
(goto-char (point-min))
(if (not (re-search-forward "|[^+]" nil t))
(error "Error processing table"))
(table-recognize-table)
(with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
(table-generate-source 'html " org-tmp2 ")
(set-buffer " org-tmp2 ")
(buffer-substring (point-min) (point-max))))
(defun org-export-splice-style (style extra)
"Splice EXTRA into STYLE, just before \"\"."
(if (and (stringp extra)
(string-match "\\S-" extra)
(string-match "" style))
(concat (substring style 0 (match-beginning 0))
"\n" extra "\n"
(substring style (match-beginning 0)))
style))
(defun org-html-handle-time-stamps (s)
"Format time stamps in string S, or remove them."
(catch 'exit
(let (r b)
(while (string-match org-maybe-keyword-time-regexp s)
(or b (setq b (substring s 0 (match-beginning 0))))
(setq r (concat
r (substring s 0 (match-beginning 0))
(org-parse-format
'FONTIFY
(concat
(if (match-end 1)
(org-parse-format
'FONTIFY
(match-string 1 s) "timestamp-kwd"))
(org-parse-format
'FONTIFY
(substring (org-translate-time (match-string 3 s)) 1 -1)
"timestamp"))
"timestamp-wrapper"))
s (substring s (match-end 0))))
;; Line break if line started and ended with time stamp stuff
(if (not r)
s
(setq r (concat r s))
(unless (string-match "\\S-" (concat b s))
(setq r (concat r (org-parse-format 'LINE-BREAK))))
r))))
(defvar htmlize-buffer-places) ; from htmlize.el
(defun org-export-htmlize-region-for-paste (beg end)
"Convert the region to HTML, using htmlize.el.
This is much like `htmlize-region-for-paste', only that it uses
the settings define in the org-... variables."
(let* ((htmlize-output-type org-export-htmlize-output-type)
(htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
(htmlbuf (htmlize-region beg end)))
(unwind-protect
(with-current-buffer htmlbuf
(buffer-substring (plist-get htmlize-buffer-places 'content-start)
(plist-get htmlize-buffer-places 'content-end)))
(kill-buffer htmlbuf))))
;;;###autoload
(defun org-export-htmlize-generate-css ()
"Create the CSS for all font definitions in the current Emacs session.
Use this to create face definitions in your CSS style file that can then
be used by code snippets transformed by htmlize.
This command just produces a buffer that contains class definitions for all
faces used in the current Emacs session. You can copy and paste the ones you
need into your CSS file.
If you then set `org-export-htmlize-output-type' to `css', calls to
the function `org-export-htmlize-region-for-paste' will produce code
that uses these same face definitions."
(interactive)
(require 'htmlize)
(and (get-buffer "*html*") (kill-buffer "*html*"))
(with-temp-buffer
(let ((fl (face-list))
(htmlize-css-name-prefix "org-")
(htmlize-output-type 'css)
f i)
(while (setq f (pop fl)
i (and f (face-attribute f :inherit)))
(when (and (symbolp f) (or (not i) (not (listp i))))
(insert (org-add-props (copy-sequence "1") nil 'face f))))
(htmlize-region (point-min) (point-max))))
(switch-to-buffer "*html*")
(goto-char (point-min))
(if (re-search-forward "