ox-html: attributes lines are more comprehensive

* lisp/ox-html.el (html): Rename :html-table-tag property
  into :org-table-attributes.
(org-html-table-default-attributes): New variable.
(org-html-table-tag): Removed variable.
(org-html--make-attribute-string): New function.
(org-html-link--inline-image, org-html-table): Use new function.
* doc/org.texi: Document variable changes.

It is now possible to write properties and values in attributes lines
without falling back on `:options':

  #+attr_html: :border 1
  | a |
This commit is contained in:
Nicolas Goaziou 2013-04-10 21:28:36 +02:00
parent adb439dea9
commit bc269f01f3
2 changed files with 49 additions and 48 deletions

View File

@ -12494,7 +12494,7 @@ string for the respective variable for details.
@item @code{:html-extension} @tab @code{org-html-extension}
@item @code{:html-preamble} @tab @code{org-html-preamble}
@item @code{:html-postamble} @tab @code{org-html-postamble}
@item @code{:html-table-tag} @tab @code{org-html-table-tag}
@item @code{:html-table-attributes} @tab @code{org-html-table-default-attributes}
@item @code{:html-head-include-default-style} @tab @code{org-html-style-include-default}
@item @code{:html-head-include-scripts} @tab @code{org-html-style-include-scripts}
@end multitable

View File

@ -124,7 +124,7 @@
(:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
(:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
(:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
(:html-table-tag nil nil org-html-table-tag)
(:html-table-attributes nil nil org-html-table-default-attributes)
(:html-table-row-tags nil nil org-html-table-row-tags)
(:html-xml-declaration nil nil org-html-xml-declaration)
(:html-inline-images nil nil org-html-inline-images)
@ -743,13 +743,16 @@ in all modes you want. Then, use the command
;;;; Table
(defcustom org-html-table-tag
"<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
"The HTML tag that is used to start a table.
This must be a <table> tag, but you may change the options like
borders and spacing."
(defcustom org-html-table-default-attributes
'(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
"Default attributes and values which will be used in table tags.
This is a plist where attributes are symbols, starting with
colons, and values are strings."
:group 'org-export-html
:type 'string)
:version "24.4"
:package-version '(Org . "8.0")
:type '(plist :key-type (symbol :tag "Property")
:value-type (string :tag "Value")))
(defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
"The opening tag for table header fields.
@ -1236,6 +1239,19 @@ CSS classes, then this prefix can be very useful."
;;; Internal Functions
(defun org-html--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
"\"" "&quot;" (org-html-encode-plain-text item))))
(setcar output (format "%s=\"%s\"" key value))))))))
(defun org-html-format-inline-image (src &optional
caption label attr standalone-p)
"Format an inline image from SRC.
@ -2399,6 +2415,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(defun org-html-link--inline-image (link desc info)
"Return HTML code for an inline image.
LINK is the link pointing to the inline image. INFO is a plist
used as a communication channel.
@ -2414,20 +2431,12 @@ Inline images can have these attributes:
(t raw-path)))
(parent (org-export-get-parent-element link))
(caption (org-export-data (org-export-get-caption parent) info))
(label (org-element-property :name parent))
(attrs (org-export-read-attribute :attr_html parent))
(alt (plist-get attrs :alt))
(width (plist-get attrs :width))
(height (plist-get attrs :height))
(options (plist-get attrs :options)))
(label (org-element-property :name parent)))
;; Return proper string, depending on DISPOSITION.
(org-html-format-inline-image
path caption label
(mapconcat 'identity
(delq nil (list (if width (format "width=\"%s\"" width))
(if alt (format "alt=\"%s\"" alt))
(if height (format "height=\"%s\"" height))
options)) " ")
(org-html--make-attribute-string
(org-export-read-attribute :attr_html parent))
(org-html-standalone-image-p link info))))
(defvar org-html-standalone-image-predicate)
@ -2528,20 +2537,19 @@ INFO is a plist holding contextual information. See
numbers "-"))))))
(t raw-path))))
(t raw-path)))
attributes protocol)
;; Extract attributes from parent's paragraph. HACK: Only do this
;; for the first link in parent. This is needed as long as
;; attributes cannot be set on a per link basis.
(and (setq attributes
(let ((parent (org-export-get-parent-element link)))
(if (not (eq (org-element-map parent 'link 'identity info t)
link))
""
(let ((att (org-export-read-attribute :attr_html parent :options)))
(unless (and desc att (string-match (regexp-quote att) desc))
(or att ""))))))
(unless (string= attributes "")
(setq attributes (concat " " attributes))))
;; Extract attributes from parent's paragraph. HACK: Only do
;; this for the first link in parent. This is needed as long
;; as attributes cannot be set on a per link basis.
(attributes
(let ((parent (org-export-get-parent-element link)))
(if (not (eq (org-element-map parent 'link 'identity info t) link))
""
(let ((att (org-html--make-attribute-string
(org-export-read-attribute :attr_html parent))))
(cond ((not (org-string-nw-p att)) "")
((and desc (string-match (regexp-quote att) desc)) "")
(t (concat " " att)))))))
protocol)
(cond
;; Image file.
((and (or (eq t org-html-inline-images)
@ -3022,7 +3030,11 @@ contextual information."
(let* ((label (org-element-property :name table))
(caption (org-export-get-caption table))
(attributes
(org-export-read-attribute :attr_html table :options))
(org-html--make-attribute-string
(org-combine-plists
(and label (list :id (org-export-solidify-link-text label)))
(plist-get info :html-table-attributes)
(org-export-read-attribute :attr_html table))))
(alignspec
(if (and (boundp 'org-html-format-table-no-css)
org-html-format-table-no-css)
@ -3045,20 +3057,9 @@ contextual information."
(when (org-export-table-cell-ends-colgroup-p
table-cell info)
"\n</colgroup>"))))
(org-html-table-first-row-data-cells table info) "\n"))))
(table-attributes
(let ((table-tag (plist-get info :html-table-tag)))
(concat
(and (string-match "<table\\(.*\\)>" table-tag)
(match-string 1 table-tag))
(and label (format " id=\"%s\""
(org-export-solidify-link-text label)))
(unless (string= attributes "")
(concat " " attributes))))))
;; Remove last blank line.
(setq contents (substring contents 0 -1))
(format "<table%s>\n%s\n%s\n%s\n</table>"
table-attributes
(org-html-table-first-row-data-cells table info) "\n")))))
(format "<table%s>\n%s\n%s\n%s</table>"
(if (equal attributes "") "" (concat " " attributes))
(if (not caption) ""
(format "<caption>%s</caption>"
(org-export-data caption info)))