diff options
Diffstat (limited to 'lisp/org/org-docbook.el')
-rw-r--r-- | lisp/org/org-docbook.el | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/lisp/org/org-docbook.el b/lisp/org/org-docbook.el index afc91daf3c2..e5ee98bb344 100644 --- a/lisp/org/org-docbook.el +++ b/lisp/org/org-docbook.el @@ -4,7 +4,7 @@ ;; ;; Emacs Lisp Archive Entry ;; Filename: org-docbook.el -;; Version: 6.33x +;; Version: 6.35i ;; Author: Baoqiu Cui <cbaoqiu AT yahoo DOT com> ;; Maintainer: Baoqiu Cui <cbaoqiu AT yahoo DOT com> ;; Keywords: org, wp, docbook @@ -384,6 +384,8 @@ header and footer, simply return the content of the document (all top-level sections). When PUB-DIR is set, use this as the publishing directory." (interactive "P") + (run-hooks 'org-export-first-hook) + ;; Make sure we have a file name when we need it. (when (and (not (or to-buffer body-only)) (not buffer-file-name)) @@ -609,7 +611,9 @@ publishing directory." </info>\n" (org-docbook-expand title) firstname othername surname - (if email (concat "<email>" email "</email>") "") + (if (and org-export-email-info + email (string-match "\\S-" email)) + (concat "<email>" email "</email>") "") ))) (org-init-section-numbers) @@ -622,7 +626,7 @@ publishing directory." ;; End of quote section? (when (and inquote (string-match "^\\*+ " line)) - (insert "]]>\n</programlisting>\n") + (insert "]]></programlisting>\n") (org-export-docbook-open-para) (setq inquote nil)) ;; Inside a quote section? @@ -642,7 +646,7 @@ publishing directory." (not (string-match "^[ \t]*\\(:.*\\)" (car lines)))) (setq infixed nil) - (insert "]]>\n</programlisting>\n") + (insert "]]></programlisting>\n") (org-export-docbook-open-para)) (throw 'nextline nil)) @@ -910,7 +914,8 @@ publishing directory." (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start) (if (get-text-property (match-beginning 2) 'org-protected line) (setq start (match-end 2)) - (let ((num (match-string 2 line))) + (let* ((num (match-string 2 line)) + (footnote-def (assoc num footnote-list))) (if (assoc num footref-seen) (setq line (replace-match (format "%s<footnoteref linkend=\"%s%s\"/>" @@ -922,9 +927,10 @@ publishing directory." (match-string 1 line) org-export-docbook-footnote-id-prefix num - (save-match-data - (org-docbook-expand - (cdr (assoc num footnote-list))))) + (if footnote-def + (save-match-data + (org-docbook-expand (cdr footnote-def))) + (format "FOOTNOTE DEFINITION NOT FOUND: %s" num))) t t line)) (push (cons num 1) footref-seen)))))) @@ -1090,7 +1096,7 @@ publishing directory." ;; Properly close all local lists and other lists (when inquote - (insert "]]>\n</programlisting>\n") + (insert "]]></programlisting>\n") (org-export-docbook-open-para)) (when in-local-list ;; Close any local lists before inserting a new header line @@ -1119,6 +1125,13 @@ publishing directory." "[ \r\n\t]*\\(<para>\\)[ \r\n\t]*</para>[ \r\n\t]*" nil t) (when (not (get-text-property (match-beginning 1) 'org-protected)) (replace-match "\n") + ;; Avoid empty <listitem></listitem> caused by inline tasks. + ;; We should add an empty para to make everything valid. + (when (and (looking-at "</listitem>") + (save-excursion + (backward-char (length "<listitem>\n")) + (looking-at "<listitem>"))) + (insert "<para></para>")) (backward-char 1))) ;; Fill empty sections with <para></para>. This is to make sure ;; that the DocBook document generated is valid and well-formed. @@ -1246,16 +1259,14 @@ string, don't modify these." (if org-export-with-sub-superscripts (setq s (org-export-docbook-convert-sub-super s))) (if org-export-with-TeX-macros - (let ((start 0) wd ass) + (let ((start 0) wd rep) (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?" s start)) (if (get-text-property (match-beginning 0) 'org-protected s) (setq start (match-end 0)) (setq wd (match-string 1 s)) - (if (setq ass (assoc wd org-html-entities)) - (setq s (replace-match (or (cdr ass) - (concat "&" (car ass) ";")) - t t s)) + (if (setq rep (org-entity-get-representation wd 'html)) + (setq s (replace-match rep t t s)) (setq start (+ start (length wd)))))))) s) @@ -1312,6 +1323,7 @@ string, don't modify these." (label (org-find-text-property-in-string 'org-label src)) (default-attr org-export-docbook-default-image-attributes) tmp) + (setq caption (and caption (org-html-do-expand caption))) (while (setq tmp (pop default-attr)) (if (not (string-match (concat (car tmp) "=") attr)) (setq attr (concat attr " " (car tmp) "=" (cdr tmp))))) @@ -1337,18 +1349,33 @@ string, don't modify these." (replace-match "")))) (defun org-export-docbook-finalize-table (table) - "Change TABLE to informaltable if caption does not exist. + "Clean up TABLE and turn it into DocBook format. +This function adds a label to the table if it is available, and +also changes TABLE to informaltable if caption does not exist. TABLE is a string containing the HTML code generated by `org-format-table-html' for a table in Org-mode buffer." - (if (string-match - "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\\)</table>" - table) - (replace-match (concat "<informaltable " - (match-string 1 table) - (match-string 3 table) - "</informaltable>") - nil nil table) - table)) + (let (table-with-label) + ;; Get the label if it exists, and move it into the <table> element. + (setq table-with-label + (if (string-match + "^<table \\(\\(.\\|\n\\)+\\)<a name=\"\\(.+\\)\" id=\".+\"></a>\n\\(\\(.\\|\n\\)+\\)</table>" + table) + (replace-match (concat "<table xml:id=\"" (match-string 3 table) "\" " + (match-string 1 table) + (match-string 4 table) + "</table>") + nil nil table) + table)) + ;; Change <table> into <informaltable> if caption does not exist. + (if (string-match + "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\\)</table>" + table-with-label) + (replace-match (concat "<informaltable " + (match-string 1 table-with-label) + (match-string 3 table-with-label) + "</informaltable>") + nil nil table-with-label) + table-with-label))) ;; Note: This function is very similar to ;; org-export-html-convert-sub-super. They can be merged in the future. |