%s")
(italic . "%s")
(strike-through . "%s"))
"Alist of HTML expressions to convert text markup.
The key must be a symbol among `bold', `code', `italic',
`strike-through', `underline' and `verbatim'. The value is
a formatting string to wrap fontified text with.
If no association can be found for a given markup, text will be
returned as-is."
:group 'org-export-twbs
:version "24.4"
:package-version '(Org . "8.0")
:type '(alist :key-type (symbol :tag "Markup type")
:value-type (string :tag "Format string"))
:options '(bold code italic strike-through underline verbatim))
(defcustom org-twbs-indent nil
"Non-nil means to indent the generated HTML.
Warning: non-nil may break indentation of source code blocks."
:group 'org-export-twbs
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
(defcustom org-twbs-use-unicode-chars nil
"Non-nil means to use unicode characters instead of HTML entities."
:group 'org-export-twbs
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
;;;; Drawers
(defcustom org-twbs-format-drawer-function
(lambda (name contents) contents)
"Function called to format a drawer in HTML code.
The function must accept two parameters:
NAME the drawer name, like \"LOGBOOK\"
CONTENTS the contents of the drawer.
The function should return the string to be exported.
For example, the variable could be set to the following function
in order to mimic default behaviour:
The default value simply returns the value of CONTENTS."
:group 'org-export-twbs
:version "24.4"
:package-version '(Org . "8.0")
:type 'function)
;;;; Footnotes
(defcustom org-twbs-footnotes-section "Date: %d
%c
")) "Alist of languages and format strings for the HTML postamble. The first element of each list is the language code, as used for the LANGUAGE keyword. See `org-export-default-language'. The second element of each list is a format string to format the postamble itself. This format string can contain these elements: %t stands for the title. %a stands for the author's name. %e stands for the author's email. %d stands for the date. %c will be replaced by `org-twbs-creator-string'. %v will be replaced by `org-twbs-validation-link'. %T will be replaced by the export time. %C will be replaced by the last modification time. If you need to use a \"%\" character, you need to escape it like that: \"%%\"." :group 'org-export-twbs :type '(repeat (list (string :tag "Language") (string :tag "Format string")))) (defcustom org-twbs-validation-link "Validate" "Link to HTML validation service." :group 'org-export-twbs :type 'string) (defcustom org-twbs-creator-string (format "Emacs %s (Org-mode %s)" emacs-version (if (fboundp 'org-version) (org-version) "unknown version")) "Information about the creator of the HTML document. This option can also be set on with the CREATOR keyword." :group 'org-export-twbs :version "24.4" :package-version '(Org . "8.0") :type '(string :tag "Creator string")) ;;;; Template :: Preamble (defcustom org-twbs-preamble t "Non-nil means insert a preamble in HTML export. When t, insert a string as defined by the formatting string in `org-twbs-preamble-format'. When set to a string, use this formatting string instead (see `org-twbs-postamble-format' for an example of such a formatting string). When set to a function, apply this function and insert the returned string. The function takes the property list of export options as its only argument. Setting :html-preamble in publishing projects will take precedence over this variable." :group 'org-export-twbs :type '(choice (const :tag "No preamble" nil) (const :tag "Default preamble" t) (string :tag "Custom formatting string") (function :tag "Function (must return a string)"))) (defcustom org-twbs-preamble-format '(("en" "")) "Alist of languages and format strings for the HTML preamble. The first element of each list is the language code, as used for the LANGUAGE keyword. See `org-export-default-language'. The second element of each list is a format string to format the preamble itself. This format string can contain these elements: %t stands for the title. %a stands for the author's name. %e stands for the author's email. %d stands for the date. %c will be replaced by `org-twbs-creator-string'. %v will be replaced by `org-twbs-validation-link'. %T will be replaced by the export time. %C will be replaced by the last modification time. If you need to use a \"%\" character, you need to escape it like that: \"%%\". See the default value of `org-twbs-postamble-format' for an example." :group 'org-export-twbs :type '(repeat (list (string :tag "Language") (string :tag "Format string")))) (defcustom org-twbs-link-up "" "Where should the \"UP\" link of exported HTML pages lead?" :group 'org-export-twbs :type '(string :tag "File or URL")) (defcustom org-twbs-link-home "" "Where should the \"HOME\" link of exported HTML pages lead?" :group 'org-export-twbs :type '(string :tag "File or URL")) (defcustom org-twbs-link-use-abs-url nil "Should we prepend relative links with HTML_LINK_HOME?" :group 'org-export-twbs :version "24.4" :package-version '(Org . "8.1") :type 'boolean) (defcustom org-twbs-home/up-format "" "Snippet used to insert the HOME and UP links. This is a format string, the first %s will receive the UP link, the second the HOME link. If both `org-twbs-link-up' and `org-twbs-link-home' are empty, the entire snippet will be ignored." :group 'org-export-twbs :type 'string) ;;;; Template :: Scripts (define-obsolete-variable-alias 'org-twbs-style-include-scripts 'org-twbs-head-include-scripts "24.4") (defcustom org-twbs-head-include-scripts t "Non-nil means include the JavaScript snippets in exported HTML files. The actual script is defined in `org-twbs-scripts' and should not be modified." :group 'org-export-twbs :version "24.4" :package-version '(Org . "8.0") :type 'boolean) ;;;; Template :: Styles (define-obsolete-variable-alias 'org-twbs-style-include-default 'org-twbs-head-include-default-style "24.4") (defcustom org-twbs-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-twbs-style-default' and should not be modified. Use `org-twbs-head' to use your own style information." :group 'org-export-twbs :version "24.4" :package-version '(Org . "8.0") :type 'boolean) ;;;###autoload (put 'org-twbs-head-include-default-style 'safe-local-variable 'booleanp) (define-obsolete-variable-alias 'org-twbs-style 'org-twbs-head "24.4") (defcustom org-twbs-head " " "Org-wide head definitions for exported HTML files. As the value of this option simply gets inserted into the HTML header, you can use it to add any arbitrary text to the header. You can set this on a per-file basis using #+HTML_HEAD:, or for publication projects using the :html-head property." :group 'org-export-twbs :version "24.4" :package-version '(Org . "8.0") :type 'string) ;;;###autoload (put 'org-twbs-head 'safe-local-variable 'stringp) (defcustom org-twbs-head-extra "" "More head information to add in the HTML output. You can set this on a per-file basis using #+HTML_HEAD_EXTRA:, or for publication projects using the :html-head-extra property." :group 'org-export-twbs :version "24.4" :package-version '(Org . "8.0") :type 'string) ;;;###autoload (put 'org-twbs-head-extra 'safe-local-variable 'stringp) ;;;; Todos (defcustom org-twbs-todo-kwd-class-prefix "" "Prefix to class names for TODO keywords. Each TODO keyword gets a class given by the keyword itself, with this prefix. The default prefix is empty because it is nice to just use the keyword as a class name. But if you get into conflicts with other, existing CSS classes, then this prefix can be very useful." :group 'org-export-twbs :type 'string) (defcustom org-twbs-todo-kwd-class-undone "label-primary" "Class name for TODO keywords which are not done. Traditionally this was not configurable, and was the value 'todo'." :group 'org-export-twbs :type 'string) (defcustom org-twbs-todo-kwd-class-done "label-default" "Class name for TODO keywords which are done. Traditionally this was not configurable, and was the value 'done'." :group 'org-export-twbs :type 'string) ;;;; Google Analytics (defcustom org-twbs-google-analytics " \n" "Snippet used to insert the Google Analytics tracking code. This is a format string, the %s will be replaced with the value set using the :gid keyword." :group 'org-export-twbs :type 'string) ;;; Internal Functions (defun org-twbs-close-tag (tag attr info) (concat "<" tag " " attr ">")) (defun org-twbs--make-attribute-string (attributes) "Return a list of attributes, as a string. ATTRIBUTES is a plist where values are either strings or nil. An attributes with a nil value will be omitted from the result." (let (output) (dolist (item attributes (mapconcat 'identity (nreverse output) " ")) (cond ((null item) (pop output)) ((symbolp item) (push (substring (symbol-name item) 1) output)) (t (let ((key (car output)) (value (replace-regexp-in-string "\"" """ (org-twbs-encode-plain-text item)))) (setcar output (format "%s=\"%s\"" key value)))))))) (defun org-twbs--wrap-image (contents info &optional caption label) "Wrap CONTENTS string within an appropriate environment for images. INFO is a plist used as a communication channel. When optional arguments CAPTION and LABEL are given, use them for caption and \"id\" attribute." (format "\n%s
" contents) ;; Caption. (if (not (org-string-nw-p caption)) "" (format "\n\n\n
" (or (plist-get attr :width) 80) (or (plist-get attr :height) (org-count-lines code)) code))) (defun org-twbs--has-caption-p (element &optional info) "Non-nil when ELEMENT has a caption affiliated keyword. INFO is a plist used as a communication channel. This function is meant to be used as a predicate for `org-export-get-ordinal' or a value to `org-twbs-standalone-image-predicate'." (org-element-property :caption element)) ;;;; Table (defun org-twbs-htmlize-region-for-paste (beg end) "Convert the region between BEG and END 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-twbs-htmlize-output-type) (htmlize-css-name-prefix org-twbs-htmlize-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-twbs-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-twbs-htmlize-output-type' to `css', calls to the function `org-twbs-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)))) (org-pop-to-buffer-same-window "*html*") (goto-char (point-min)) (if (re-search-forward "") (when (plist-get info :html-head-include-scripts) org-twbs-scripts) (org-element-normalize-string (plist-get info :html-head-extra))))) (defun org-twbs--build-mathjax-config (info) "Insert the user setup into the mathjax template. INFO is a plist used as a communication channel." (when (and (memq (plist-get info :with-latex) '(mathjax t)) (org-element-map (plist-get info :parse-tree) '(latex-fragment latex-environment) 'identity info t)) (let ((template (plist-get info :html-mathjax-template)) (options (plist-get info :html-mathjax-options)) (in-buffer (or (plist-get info :html-mathjax) ""))) (dolist (e options (org-element-normalize-string template)) (let ((name (car e)) (val (nth 1 e))) (when (string-match (concat "\\<" (symbol-name name) ":") in-buffer) (setq val (car (read-from-string (substring in-buffer (match-end 0)))))) (unless (stringp val) (setq val (format "%s" val))) (while (string-match (concat "%" (upcase (symbol-name name))) template) (setq template (replace-match val t t template)))))))) (defun org-twbs-format-spec (info) "Return format specification for elements that can be used in the preamble or postamble." `((?t . ,(org-export-data (plist-get info :title) info)) (?d . ,(org-export-data (org-export-get-date info) info)) (?T . ,(format-time-string org-twbs-metadata-timestamp-format)) (?a . ,(org-export-data (plist-get info :author) info)) (?e . ,(mapconcat (lambda (e) (format "%s" e e)) (split-string (plist-get info :email) ",+ *") ", ")) (?c . ,(plist-get info :creator)) (?C . ,(let ((file (plist-get info :input-file))) (format-time-string org-twbs-metadata-timestamp-format (if file (nth 5 (file-attributes file)) (current-time))))) (?v . ,(or org-twbs-validation-link "")))) (defun org-twbs--build-pre/postamble (type info) "Return document preamble or postamble as a string, or nil. TYPE is either 'preamble or 'postamble, INFO is a plist used as a communication channel." (let ((section (plist-get info (intern (format ":html-%s" type)))) (spec (org-twbs-format-spec info))) (when section (let ((section-contents (if (functionp section) (funcall section info) (cond ((stringp section) (format-spec section spec)) ((eq section 'auto) (let ((date (cdr (assq ?d spec))) (author (cdr (assq ?a spec))) (email (cdr (assq ?e spec))) (creator (cdr (assq ?c spec))) (timestamp (cdr (assq ?T spec))) (validation-link (cdr (assq ?v spec)))) (concat "%s: %s
\n" (org-twbs--translate "Date" info) date)) (when (and (plist-get info :with-author) (org-string-nw-p author)) (format "\n" (org-twbs--translate "Author" info) author)) (when (and (plist-get info :with-email) (org-string-nw-p email)) (format "%s: %s
\n" (org-twbs--translate "Email" info) email)) (when (plist-get info :time-stamp-file) (format "%s: %s
\n" (org-twbs--translate "Created" info) (format-time-string org-twbs-metadata-timestamp-format))) (when (plist-get info :with-creator) (format "%s
\n" creator)) "]*>\n*" code) (match-end 0)))
(end (and beg (string-match "\\'" code))))
(if (and beg end) (substring code beg end) code)))))))))
(defun org-twbs-do-format-code
(code &optional lang refs retain-labels num-start)
"Format CODE string as source code.
Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
respectively, the language of the source code, as a string, an
alist between line numbers and references (as returned by
`org-export-unravel-code'), a boolean specifying if labels should
appear in the source code, and the number associated to the first
line of code."
(let* ((code-lines (org-split-string code "\n"))
(code-length (length code-lines))
(num-fmt
(and num-start
(format "%%%ds: "
(length (number-to-string (+ code-length num-start))))))
(code (org-twbs-fontify-code code lang)))
(org-export-format-code
code
(lambda (loc line-num ref)
(setq loc
(concat
;; Add line number, if needed.
(when num-start
(format "%s"
(format num-fmt line-num)))
;; Transcoded src line.
loc
;; Add label, if needed.
(when (and ref retain-labels) (format " (%s)" ref))))
;; Mark transcoded line as an anchor, if needed.
(if (not ref) loc
(format "%s"
ref loc)))
num-start refs)))
(defun org-twbs-format-code (element info)
"Format contents of ELEMENT as source code.
ELEMENT is either an example block or a src block. INFO is
a plist used as a communication channel."
(let* ((lang (org-element-property :language element))
;; Extract code and references.
(code-info (org-export-unravel-code element))
(code (car code-info))
(refs (cdr code-info))
;; Does the src block contain labels?
(retain-labels (org-element-property :retain-labels element))
;; Does it have line numbers?
(num-start (case (org-element-property :number-lines element)
(continued (org-export-get-loc element info))
(new 0))))
(org-twbs-do-format-code code lang refs retain-labels num-start)))
;;; Tables of Contents
(defun org-twbs-display-headline-number-p (headline-number info)
"Predicate deciding if headline number should be displayed."
(let ((whn (plist-get info :with-headline-numbers)))
(or (eq whn t) (and (wholenump whn) (<= (length headline-number) whn)))))
(defun org-twbs-collect-headlines (info depth &optional scope)
"Another arity change in org:
http://orgmode.org/w/?p=org-mode.git;a=commit;h=b07e2f6ff1feddde83506b7fdb370bfe8e0a5337
Try new 3-arity first, then old 2-arity."
(with-no-warnings
(condition-case nil
(org-export-collect-headlines info depth scope)
(error (org-export-collect-headlines info depth)))))
(defun org-twbs-toc (depth info &optional scope)
"Build a table of contents.
DEPTH is an integer specifying the depth of the table. INFO is a
plist used as a communication channel. Return the table of
contents as a string, or nil if it is empty."
(let ((toc-entries
(mapcar (lambda (headline)
(cons (org-twbs--format-toc-headline headline info)
(org-export-get-relative-level headline info)))
(org-twbs-collect-headlines info depth scope)))
(outer-tag "nav"))
(when toc-entries
(concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
"\n"
(format "%s>\n" outer-tag)))))
(defun org-twbs--toc-text (toc-entries)
"Return innards of a table of contents, as a string.
TOC-ENTRIES is an alist where key is an entry title, as a string,
and value is its relative level, as an integer."
(let* ((prev-level (1- (cdar toc-entries)))
(start-level prev-level))
(concat
(mapconcat
(lambda (entry)
(let ((headline (car entry))
(level (cdr entry)))
(concat
(let* ((cnt (- level prev-level))
(times (if (> cnt 0) (1- cnt) (- cnt)))
rtn)
(setq prev-level level)
(concat
(org-twbs--make-string
times (cond ((> cnt 0) "\n" org-clock-string (org-timestamp-translate (org-element-property :value clock)) (let ((time (org-element-property :duration clock))) (and time (format " " time))))) ;;;; Code (defun org-twbs-code (code contents info) "Transcode CODE from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (format (or (cdr (assq 'code org-twbs-text-markup-alist)) "%s") (org-twbs-encode-plain-text (org-element-property :value code)))) ;;;; Drawer (defun org-twbs-drawer (drawer contents info) "Transcode a DRAWER element from Org to HTML. CONTENTS holds the contents of the block. INFO is a plist holding contextual information." (if (functionp org-twbs-format-drawer-function) (funcall org-twbs-format-drawer-function (org-element-property :drawer-name drawer) contents) ;; If there's no user defined function: simply ;; display contents of the drawer. contents)) ;;;; Dynamic Block (defun org-twbs-dynamic-block (dynamic-block contents info) "Transcode a DYNAMIC-BLOCK element from Org to HTML. CONTENTS holds the contents of the block. INFO is a plist holding contextual information. See `org-export-data'." contents) ;;;; Entity (defun org-twbs-entity (entity contents info) "Transcode an ENTITY object from Org to HTML. CONTENTS are the definition itself. INFO is a plist holding contextual information." (org-element-property :html entity)) ;;;; Example Block (defun org-twbs-example-block (example-block contents info) "Transcode a EXAMPLE-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (if (org-export-read-attribute :attr_html example-block :textarea) (org-twbs--textarea-block example-block) (format "
\n%s" (org-twbs-format-code example-block info)))) ;;;; Export Snippet (defun org-twbs-export-snippet (export-snippet contents info) "Transcode a EXPORT-SNIPPET object from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (when (eq (org-export-snippet-backend export-snippet) 'html) (org-element-property :value export-snippet))) ;;;; Export Block (defun org-twbs-export-block (export-block contents info) "Transcode a EXPORT-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (when (string= (org-element-property :type export-block) "HTML") (org-remove-indentation (org-element-property :value export-block)))) ;;;; Fixed Width (defun org-twbs-fixed-width (fixed-width contents info) "Transcode a FIXED-WIDTH element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (format "
\n%s" (org-twbs-do-format-code (org-remove-indentation (org-element-property :value fixed-width))))) ;;;; Footnote Reference (defun org-twbs-footnote-reference (footnote-reference contents info) "Transcode a FOOTNOTE-REFERENCE element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (concat ;; Insert separator between two footnotes in a row. (let ((prev (org-export-get-previous-element footnote-reference info))) (when (eq (org-element-type prev) 'footnote-reference) org-twbs-footnote-separator)) (cond ((not (org-export-footnote-first-reference-p footnote-reference info)) (org-twbs-format-footnote-reference (org-export-get-footnote-number footnote-reference info) "IGNORED" 100)) ;; Inline definitions are secondary strings. ((eq (org-element-property :type footnote-reference) 'inline) (org-twbs-format-footnote-reference (org-export-get-footnote-number footnote-reference info) "IGNORED" 1)) ;; Non-inline footnotes definitions are full Org data. (t (org-twbs-format-footnote-reference (org-export-get-footnote-number footnote-reference info) "IGNORED" 1))))) ;;;; Headline (defun org-twbs-format-headline--wrap (headline info &optional format-function &rest extra-keys) "Transcode a HEADLINE element from Org to HTML. CONTENTS holds the contents of the headline. INFO is a plist holding contextual information." (let* ((level (+ (org-export-get-relative-level headline info) (1- org-twbs-toplevel-hlevel))) (headline-number (org-export-get-headline-number headline info)) (section-number (and (not (org-export-low-level-p headline info)) (org-export-numbered-headline-p headline info) (org-twbs-display-headline-number-p headline-number info) (mapconcat 'number-to-string headline-number "."))) (todo (and (plist-get info :with-todo-keywords) (let ((todo (org-element-property :todo-keyword headline))) (and todo (org-export-data todo info))))) (todo-type (and todo (org-element-property :todo-type headline))) (priority (and (plist-get info :with-priority) (org-element-property :priority headline))) (text (org-export-data (org-element-property :title headline) info)) (tags (and (plist-get info :with-tags) (org-export-get-tags headline info))) (headline-label (or (org-element-property :CUSTOM_ID headline) (concat "sec-" (mapconcat 'number-to-string headline-number "-")))) (format-function (cond ((functionp format-function) format-function) ((not (eq org-twbs-format-headline-function 'ignore)) (lambda (todo todo-type priority text tags &rest ignore) (funcall org-twbs-format-headline-function todo todo-type priority text tags))) (t 'org-twbs-format-headline)))) (apply format-function todo todo-type priority text tags :headline-label headline-label :level level :section-number section-number extra-keys))) (defun org-twbs-headline (headline contents info) "Transcode a HEADLINE element from Org to HTML. CONTENTS holds the contents of the headline. INFO is a plist holding contextual information." (unless (org-element-property :footnote-section-p headline) (let* ((contents (or contents "")) (numberedp (org-export-numbered-headline-p headline info)) (level (org-export-get-relative-level headline info)) (text (org-export-data (org-element-property :title headline) info)) (todo (and (plist-get info :with-todo-keywords) (let ((todo (org-element-property :todo-keyword headline))) (and todo (org-export-data todo info))))) (todo-type (and todo (org-element-property :todo-type headline))) (tags (and (plist-get info :with-tags) (org-export-get-tags headline info))) (priority (and (plist-get info :with-priority) (org-element-property :priority headline))) (section-number (mapconcat #'number-to-string (org-export-get-headline-number headline info) "-")) (ids (delq 'nil (list (org-element-property :CUSTOM_ID headline) (concat "sec-" section-number) (org-element-property :ID headline)))) (preferred-id (car ids)) (extra-ids (mapconcat (lambda (id) (org-twbs--anchor (if (org-uuidgen-p id) (concat "ID-" id) id))) (cdr ids) "")) ;; Create the headline text. (full-text (org-twbs-format-headline--wrap headline info))) (if (org-export-low-level-p headline info) ;; This is a deep sub-tree: export it as a list item. (let* ((type (if numberedp 'ordered 'unordered)) (itemized-body (org-twbs-format-list-item contents type nil info nil (concat (org-twbs--anchor preferred-id) extra-ids full-text)))) (concat (and (org-export-first-sibling-p headline info) (org-twbs-begin-plain-list type)) itemized-body (and (org-export-last-sibling-p headline info) (org-twbs-end-plain-list type)))) ;; Standard headline. Export it as a section. (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline)) (level1 (+ level (1- org-twbs-toplevel-hlevel))) (first-content (car (org-element-contents headline)))) (format "<%s id=\"%s\" class=\"%s\">%s%s%s>\n" (org-twbs--container headline info) (format "outline-container-%s" (or (org-element-property :CUSTOM_ID headline) (concat "sec-" section-number))) (concat (format "outline-%d" level1) (and extra-class " ") extra-class) (format "\n
[X]")
(off "[ ]")
(trans "[-]")
(t "")))
(defun org-twbs-format-list-item (contents type checkbox info
&optional term-counter-id
headline)
"Format a list item into HTML."
(let ((checkbox (concat (org-twbs-checkbox checkbox) (and checkbox " ")))
(br (org-twbs-close-tag "br" nil info)))
(concat
(case type
(ordered
(let* ((counter term-counter-id)
(extra (if counter (format " value=\"%s\"" counter) "")))
(concat
(format "\n%s
" extra contents))))) ;;;; Plain List ;; FIXME Maybe arg1 is not needed because" (mapconcat 'identity (delq nil (list (let ((closed (org-element-property :closed planning))) (when closed (format span-fmt org-closed-string (org-timestamp-translate closed)))) (let ((deadline (org-element-property :deadline planning))) (when deadline (format span-fmt org-deadline-string (org-timestamp-translate deadline)))) (let ((scheduled (org-element-property :scheduled planning))) (when scheduled (format span-fmt org-scheduled-string (org-timestamp-translate scheduled)))))) " ")))) ;;;; Property Drawer (defun org-twbs-property-drawer (property-drawer contents info) "Transcode a PROPERTY-DRAWER element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." ;; The property drawer isn't exported but we want separating blank ;; lines nonetheless. "") ;;;; Quote Block (defun org-twbs-quote-block (quote-block contents info) "Transcode a QUOTE-BLOCK element from Org to HTML. CONTENTS holds the contents of the block. INFO is a plist holding contextual information." (format "
\n%s" contents)) ;;;; Quote Section (defun org-twbs-quote-section (quote-section contents info) "Transcode a QUOTE-SECTION element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let ((value (org-remove-indentation (org-element-property :value quote-section)))) (when value (format "
\n%s" value)))) ;;;; Section (defun org-twbs-section (section contents info) "Transcode a SECTION element from Org to HTML. CONTENTS holds the contents of the section. INFO is a plist holding contextual information." (let ((parent (org-export-get-parent-headline section))) ;; Before first headline: no container, just return CONTENTS. (if (not parent) contents ;; Get div's class and id references. (let* ((class-num (+ (org-export-get-relative-level parent info) (1- org-twbs-toplevel-hlevel))) (section-number (mapconcat 'number-to-string (org-export-get-headline-number parent info) "-"))) ;; Build return value. (format "
\n%s" label code) (format "
%s" lang label code)))))) ;;;; Statistics Cookie (defun org-twbs-statistics-cookie (statistics-cookie contents info) "Transcode a STATISTICS-COOKIE object from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let ((cookie-value (org-element-property :value statistics-cookie))) (format "
%s" cookie-value)))
;;;; Strike-Through
(defun org-twbs-strike-through (strike-through contents info)
"Transcode STRIKE-THROUGH from Org to HTML.
CONTENTS is the text with strike-through markup. INFO is a plist
holding contextual information."
(format (or (cdr (assq 'strike-through org-twbs-text-markup-alist)) "%s")
contents))
;;;; Subscript
(defun org-twbs-subscript (subscript contents info)
"Transcode a SUBSCRIPT object from Org to HTML.
CONTENTS is the contents of the object. INFO is a plist holding
contextual information."
(format "%s" contents))
;;;; Superscript
(defun org-twbs-superscript (superscript contents info)
"Transcode a SUPERSCRIPT object from Org to HTML.
CONTENTS is the contents of the object. INFO is a plist holding
contextual information."
(format "%s" contents))
;;;; Table Cell
(defun org-twbs-table-cell (table-cell contents info)
"Transcode a TABLE-CELL element from Org to HTML.
CONTENTS is nil. INFO is a plist used as a communication
channel."
(let* ((table-row (org-export-get-parent table-cell))
(table (org-export-get-parent-table table-cell))
(cell-attrs
(if (not org-twbs-table-align-individual-fields) ""
(format (if (and (boundp 'org-twbs-format-table-no-css)
org-twbs-format-table-no-css)
" align=\"%s\"" " class=\"text-%s\"")
(org-export-table-cell-alignment table-cell info)))))
(when (or (not contents) (string= "" (org-trim contents)))
(setq contents " "))
(cond
((and (org-export-table-has-header-p table info)
(= 1 (org-export-table-row-group table-row info)))
(concat "\n" (format (car org-twbs-table-header-tags) "col" cell-attrs)
contents (cdr org-twbs-table-header-tags)))
((and org-twbs-table-use-header-tags-for-first-column
(zerop (cdr (org-export-table-cell-address table-cell info))))
(concat "\n" (format (car org-twbs-table-header-tags) "row" cell-attrs)
contents (cdr org-twbs-table-header-tags)))
(t (concat "\n" (format (car org-twbs-table-data-tags) cell-attrs)
contents (cdr org-twbs-table-data-tags))))))
;;;; Table Row
(defun org-twbs-table-row (table-row contents info)
"Transcode a TABLE-ROW element from Org to HTML.
CONTENTS is the contents of the row. INFO is a plist used as a
communication channel."
;; Rules are ignored since table separators are deduced from
;; borders of the current row.
(when (eq (org-element-property :type table-row) 'standard)
(let* ((rowgroup-number (org-export-table-row-group table-row info))
(row-number (org-export-table-row-number table-row info))
(start-rowgroup-p
(org-export-table-row-starts-rowgroup-p table-row info))
(end-rowgroup-p
(org-export-table-row-ends-rowgroup-p table-row info))
;; `top-row-p' and `end-rowgroup-p' are not used directly
;; but should be set so that `org-twbs-table-row-tags' can
;; use them (see the docstring of this variable.)
(top-row-p (and (equal start-rowgroup-p '(top))
(equal end-rowgroup-p '(below top))))
(bottom-row-p (and (equal start-rowgroup-p '(above))
(equal end-rowgroup-p '(bottom above))))
(rowgroup-tags
(cond
;; Case 1: Row belongs to second or subsequent rowgroups.
((not (= 1 rowgroup-number))
'("" . "\n"))
;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
((org-export-table-has-header-p
(org-export-get-parent-table table-row) info)
'("" . "\n"))
;; Case 2: Row is from first and only row group.
(t '("" . "\n")))))
(concat
;; Begin a rowgroup?
(when start-rowgroup-p (car rowgroup-tags))
;; Actual table row
(concat "\n" (eval (car org-twbs-table-row-tags))
contents
"\n"
(eval (cdr org-twbs-table-row-tags)))
;; End a rowgroup?
(when end-rowgroup-p (cdr rowgroup-tags))))))
;;;; Table
(defun org-twbs-table-first-row-data-cells (table info)
"Transcode the first row of TABLE.
INFO is a plist used as a communication channel."
(let ((table-row
(org-element-map table 'table-row
(lambda (row)
(unless (eq (org-element-property :type row) 'rule) row))
info 'first-match))
(special-column-p (org-export-table-has-special-column-p table)))
(if (not special-column-p) (org-element-contents table-row)
(cdr (org-element-contents table-row)))))
(defun org-twbs-table--table.el-table (table info)
"Format table.el tables into HTML.
INFO is a plist used as a communication channel."
(when (eq (org-element-property :type table) 'table.el)
(require 'table)
(let ((outbuf (with-current-buffer
(get-buffer-create "*org-export-table*")
(erase-buffer) (current-buffer))))
(with-temp-buffer
(insert (org-element-property :value table))
(goto-char 1)
(re-search-forward "^[ \t]*|[^|]" nil t)
(table-generate-source 'html outbuf))
(with-current-buffer outbuf
(prog1 (org-trim (buffer-string))
(kill-buffer) )))))
(defun org-twbs-table (table contents info)
"Transcode a TABLE element from Org to HTML.
CONTENTS is the contents of the table. INFO is a plist holding
contextual information."
(case (org-element-property :type table)
;; Case 1: table.el table. Convert it using appropriate tools.
(table.el (org-twbs-table--table.el-table table info))
;; Case 2: Standard table.
(t
(let* ((label (org-element-property :name table))
(caption (org-export-get-caption table))
(number (org-export-get-ordinal
table info nil 'org-twbs--has-caption-p))
(attributes
(org-twbs--make-attribute-string
(org-combine-plists
(and label (list :id label))
(plist-get info :html-table-attributes)
(org-export-read-attribute :attr_html table))))
(alignspec
(if (and (boundp 'org-twbs-format-table-no-css)
org-twbs-format-table-no-css)
"align=\"%s\"" "class=\"%s\""))
(table-column-specs
(function
(lambda (table info)
(mapconcat
(lambda (table-cell)
(let ((alignment (org-export-table-cell-alignment
table-cell info)))
(concat
;; Begin a colgroup?
(when (org-export-table-cell-starts-colgroup-p
table-cell info)
"\n\n%s
" contents)) ;;; Filter Functions (defun org-twbs-final-function (contents backend info) "Filter to indent the HTML and convert HTML entities." (with-temp-buffer (insert contents) (set-auto-mode t) (if org-twbs-indent (indent-region (point-min) (point-max))) (when org-twbs-use-unicode-chars (require 'mm-url) (mm-url-decode-entities)) (buffer-substring-no-properties (point-min) (point-max)))) ;;; End-user functions ;;;###autoload (defun org-twbs-export-as-html (&optional async subtreep visible-only body-only ext-plist) "Export current buffer to an HTML buffer. If narrowing is active in the current buffer, only export its narrowed part. If a region is active, export that region. A non-nil optional argument ASYNC means the process should happen asynchronously. The resulting buffer should be accessible through the `org-export-stack' interface. When optional argument SUBTREEP is non-nil, export the sub-tree at point, extracting information from the headline properties first. When optional argument VISIBLE-ONLY is non-nil, don't export contents of hidden elements. When optional argument BODY-ONLY is non-nil, only write code between \"\" and \"\" tags. EXT-PLIST, when provided, is a property list with external parameters overriding Org default settings, but still inferior to file-local settings. Export is done in a buffer named \"*Org HTML Export*\", which will be displayed when `org-export-show-temporary-export-buffer' is non-nil." (interactive) (org-export-to-buffer 'twbs "*Org HTML Export*" async subtreep visible-only body-only ext-plist (lambda () (set-auto-mode t)))) ;;;###autoload (defun org-twbs-convert-region-to-html () "Assume the current region has org-mode syntax, and convert it to HTML. This can be used in any buffer. For example, you can write an itemized list in org-mode syntax in an HTML buffer and use this command to convert it." (interactive) (org-export-replace-region-by 'twbs)) ;;;###autoload (defun org-twbs-export-to-html (&optional async subtreep visible-only body-only ext-plist) "Export current buffer to a HTML file. If narrowing is active in the current buffer, only export its narrowed part. If a region is active, export that region. A non-nil optional argument ASYNC means the process should happen asynchronously. The resulting file should be accessible through the `org-export-stack' interface. When optional argument SUBTREEP is non-nil, export the sub-tree at point, extracting information from the headline properties first. When optional argument VISIBLE-ONLY is non-nil, don't export contents of hidden elements. When optional argument BODY-ONLY is non-nil, only write code between \"\" and \"\" tags. EXT-PLIST, when provided, is a property list with external parameters overriding Org default settings, but still inferior to file-local settings. Return output file's name." (interactive) (let* ((extension (concat "." org-twbs-extension)) (file (org-export-output-file-name extension subtreep)) (org-export-coding-system org-twbs-coding-system)) (org-export-to-file 'twbs file async subtreep visible-only body-only ext-plist))) ;;;###autoload (defun org-twbs-publish-to-html (plist filename pub-dir) "Publish an org file to HTML. FILENAME is the filename of the Org file to be published. PLIST is the property list for the given project. PUB-DIR is the publishing directory. Return output file name." (org-publish-org-to 'twbs filename (concat "." (or (plist-get plist :html-extension) org-twbs-extension "html")) plist pub-dir)) (provide 'ox-twbs) ;; Local variables: ;; coding: utf-8 ;; End: ;;; ox-twbs.el ends here