comparison lisp/org/org-docbook.el @ 111506:5cb272c831e8

Install org-mode version 7.3
author Carsten Dominik <carsten.dominik@gmail.com>
date Thu, 11 Nov 2010 22:10:19 -0600
parents a150e8a14679
children a7740098b594
comparison
equal deleted inserted replaced
111505:62aa3653746a 111506:5cb272c831e8
2 ;; 2 ;;
3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Emacs Lisp Archive Entry 5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-docbook.el 6 ;; Filename: org-docbook.el
7 ;; Version: 7.01 7 ;; Version: 7.3
8 ;; Author: Baoqiu Cui <cbaoqiu AT yahoo DOT com> 8 ;; Author: Baoqiu Cui <cbaoqiu AT yahoo DOT com>
9 ;; Maintainer: Baoqiu Cui <cbaoqiu AT yahoo DOT com> 9 ;; Maintainer: Baoqiu Cui <cbaoqiu AT yahoo DOT com>
10 ;; Keywords: org, wp, docbook 10 ;; Keywords: org, wp, docbook
11 ;; Description: Converts an org-mode buffer into DocBook 11 ;; Description: Converts an org-mode buffer into DocBook
12 ;; URL: 12 ;; URL:
550 (nth 1 (assoc "=" org-export-docbook-emphasis-alist))) 550 (nth 1 (assoc "=" org-export-docbook-emphasis-alist)))
551 (checkbox-end 551 (checkbox-end
552 (nth 2 (assoc "=" org-export-docbook-emphasis-alist))) 552 (nth 2 (assoc "=" org-export-docbook-emphasis-alist)))
553 table-open type 553 table-open type
554 table-buffer table-orig-buffer 554 table-buffer table-orig-buffer
555 ind item-type starter didclose 555 ind item-type starter
556 rpl path attr caption label desc descp desc1 desc2 link 556 rpl path attr caption label desc descp desc1 desc2 link
557 fnc item-tag initial-number 557 fnc item-tag item-number
558 footref-seen footnote-list 558 footref-seen footnote-list
559 id-file 559 id-file
560 ) 560 )
561 561
562 ;; Fine detailed info about author name. 562 ;; Fine detailed info about author name.
669 (setq infixed nil) 669 (setq infixed nil)
670 (insert "]]></programlisting>\n") 670 (insert "]]></programlisting>\n")
671 (org-export-docbook-open-para)) 671 (org-export-docbook-open-para))
672 (throw 'nextline nil)) 672 (throw 'nextline nil))
673 673
674 (org-export-docbook-close-lists-maybe line) 674 ;; List ender: close every open list.
675 (when (equal "ORG-LIST-END" line)
676 (while local-list-type
677 (let ((listtype (car local-list-type)))
678 (org-export-docbook-close-li listtype)
679 (insert (cond
680 ((equal listtype "o") "</orderedlist>\n")
681 ((equal listtype "u") "</itemizedlist>\n")
682 ((equal listtype "d") "</variablelist>\n"))))
683 (pop local-list-type))
684 ;; We did close a list, normal text follows: need <para>
685 (org-export-docbook-open-para)
686 (setq local-list-indent nil
687 in-local-list nil)
688 (throw 'nextline nil))
675 689
676 ;; Protected HTML 690 ;; Protected HTML
677 (when (get-text-property 0 'org-protected line) 691 (when (get-text-property 0 'org-protected line)
678 (let (par (ind (get-text-property 0 'original-indentation line))) 692 (let (par (ind (get-text-property 0 'original-indentation line)))
679 (when (re-search-backward 693 (when (re-search-backward
961 (setq level (org-tr-level (- (match-end 1) (match-beginning 1) 975 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
962 level-offset)) 976 level-offset))
963 txt (match-string 2 line)) 977 txt (match-string 2 line))
964 (if (string-match quote-re0 txt) 978 (if (string-match quote-re0 txt)
965 (setq txt (replace-match "" t t txt))) 979 (setq txt (replace-match "" t t txt)))
966 (when in-local-list
967 ;; Close any local lists before inserting a new header line
968 (while local-list-type
969 (let ((listtype (car local-list-type)))
970 (org-export-docbook-close-li listtype)
971 (insert (cond
972 ((equal listtype "o") "</orderedlist>\n")
973 ((equal listtype "u") "</itemizedlist>\n")
974 ((equal listtype "d") "</variablelist>\n"))))
975 (pop local-list-type))
976 (setq local-list-indent nil
977 in-local-list nil))
978 (org-export-docbook-level-start level txt) 980 (org-export-docbook-level-start level txt)
979 ;; QUOTES 981 ;; QUOTES
980 (when (string-match quote-re line) 982 (when (string-match quote-re line)
981 (org-export-docbook-close-para-maybe) 983 (org-export-docbook-close-para-maybe)
982 (insert "<programlisting><![CDATA[") 984 (insert "<programlisting><![CDATA[")
1001 (setq table-open nil 1003 (setq table-open nil
1002 table-buffer (nreverse table-buffer) 1004 table-buffer (nreverse table-buffer)
1003 table-orig-buffer (nreverse table-orig-buffer)) 1005 table-orig-buffer (nreverse table-orig-buffer))
1004 (org-export-docbook-close-para-maybe) 1006 (org-export-docbook-close-para-maybe)
1005 (insert (org-export-docbook-finalize-table 1007 (insert (org-export-docbook-finalize-table
1006 (org-format-table-html table-buffer table-orig-buffer))))) 1008 (org-format-table-html table-buffer table-orig-buffer
1009 'no-css)))))
1010
1007 (t 1011 (t
1008 ;; Normal lines 1012 ;; Normal lines
1009 (when (string-match 1013 (when (string-match
1010 (cond 1014 (cond
1011 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)") 1015 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1018 item-type (if (match-beginning 4) "o" "u") 1022 item-type (if (match-beginning 4) "o" "u")
1019 starter (if (match-beginning 2) 1023 starter (if (match-beginning 2)
1020 (substring (match-string 2 line) 0 -1)) 1024 (substring (match-string 2 line) 0 -1))
1021 line (substring line (match-beginning 5)) 1025 line (substring line (match-beginning 5))
1022 item-tag nil 1026 item-tag nil
1023 initial-number nil) 1027 item-number nil)
1024 (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line) 1028 (if (string-match "\\[@\\(?:start:\\)?\\([0-9]+\\)\\][ \t]?" line)
1025 (setq initial-number (match-string 1 line) 1029 (setq item-number (match-string 1 line)
1026 line (replace-match "" t t line))) 1030 line (replace-match "" t t line)))
1027 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line)) 1031 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
1028 (setq item-type "d" 1032 (setq item-type "d"
1029 item-tag (match-string 1 line) 1033 item-tag (match-string 1 line)
1030 line (substring line (match-end 0)))) 1034 line (substring line (match-end 0))))
1031 (when (and (not (equal item-type "d"))
1032 (not (string-match "[^ \t]" line)))
1033 ;; Empty line. Pretend indentation is large.
1034 (setq ind (if org-empty-line-terminates-plain-lists
1035 0
1036 (1+ (or (car local-list-indent) 1)))))
1037 (setq didclose nil)
1038 (while (and in-local-list
1039 (or (and (= ind (car local-list-indent))
1040 (not starter))
1041 (< ind (car local-list-indent))))
1042 (setq didclose t)
1043 (let ((listtype (car local-list-type)))
1044 (org-export-docbook-close-li listtype)
1045 (insert (cond
1046 ((equal listtype "o") "</orderedlist>\n")
1047 ((equal listtype "u") "</itemizedlist>\n")
1048 ((equal listtype "d") "</variablelist>\n"))))
1049 (pop local-list-type) (pop local-list-indent)
1050 (setq in-local-list local-list-indent))
1051 (cond 1035 (cond
1052 ((and starter 1036 ((and starter
1053 (or (not in-local-list) 1037 (or (not in-local-list)
1054 (> ind (car local-list-indent)))) 1038 (> ind (car local-list-indent))))
1055 ;; Start new (level of) list 1039 ;; Start new (level of) list
1056 (org-export-docbook-close-para-maybe) 1040 (org-export-docbook-close-para-maybe)
1057 (insert (cond 1041 (insert (cond
1058 ((equal item-type "u") "<itemizedlist>\n<listitem>\n") 1042 ((equal item-type "u") "<itemizedlist>\n<listitem>\n")
1059 ((equal item-type "o") 1043 ((and (equal item-type "o") item-number)
1060 ;; Check for a specific start number. If it 1044 ;; Check for a specific start number. If it
1061 ;; is specified, we use the ``override'' 1045 ;; is specified, we use the ``override''
1062 ;; attribute of element <listitem> to pass the 1046 ;; attribute of element <listitem> to pass the
1063 ;; info to DocBook. We could also use the 1047 ;; info to DocBook. We could also use the
1064 ;; ``startingnumber'' attribute of element 1048 ;; ``startingnumber'' attribute of element
1065 ;; <orderedlist>, but the former works on both 1049 ;; <orderedlist>, but the former works on both
1066 ;; DocBook 5.0 and prior versions. 1050 ;; DocBook 5.0 and prior versions.
1067 (if initial-number 1051 (format "<orderedlist>\n<listitem override=\"%s\">\n" item-number))
1068 (format "<orderedlist>\n<listitem override=\"%s\">\n" 1052 ((equal item-type "o") "<orderedlist>\n<listitem>\n")
1069 initial-number)
1070 "<orderedlist>\n<listitem>\n"))
1071 ((equal item-type "d") 1053 ((equal item-type "d")
1072 (format "<variablelist>\n<varlistentry><term>%s</term><listitem>\n" item-tag)))) 1054 (format "<variablelist>\n<varlistentry><term>%s</term><listitem>\n" item-tag))))
1073 ;; For DocBook, we need to open a para right after tag 1055 ;; For DocBook, we need to open a para right after tag
1074 ;; <listitem>. 1056 ;; <listitem>.
1075 (org-export-docbook-open-para) 1057 (org-export-docbook-open-para)
1076 (push item-type local-list-type) 1058 (push item-type local-list-type)
1077 (push ind local-list-indent) 1059 (push ind local-list-indent)
1078 (setq in-local-list t)) 1060 (setq in-local-list t))
1061 ;; Continue current list
1079 (starter 1062 (starter
1080 ;; Continue current list 1063 ;; terminate any previous sublist but first ensure
1064 ;; list is not ill-formed
1065 (let ((min-ind (apply 'min local-list-indent)))
1066 (when (< ind min-ind) (setq ind min-ind)))
1067 (while (< ind (car local-list-indent))
1068 (let ((listtype (car local-list-type)))
1069 (org-export-docbook-close-li listtype)
1070 (insert (cond
1071 ((equal listtype "o") "</orderedlist>\n")
1072 ((equal listtype "u") "</itemizedlist>\n")
1073 ((equal listtype "d") "</variablelist>\n"))))
1074 (pop local-list-type) (pop local-list-indent)
1075 (setq in-local-list local-list-indent))
1076 ;; insert new item
1081 (let ((listtype (car local-list-type))) 1077 (let ((listtype (car local-list-type)))
1082 (org-export-docbook-close-li listtype) 1078 (org-export-docbook-close-li listtype)
1083 (insert (cond 1079 (insert (cond
1080 ((and (equal listtype "o") item-number)
1081 (format "<listitem override=\"%s\">" item-number))
1084 ((equal listtype "o") "<listitem>") 1082 ((equal listtype "o") "<listitem>")
1085 ((equal listtype "u") "<listitem>") 1083 ((equal listtype "u") "<listitem>")
1086 ((equal listtype "d") (format 1084 ((equal listtype "d") (format
1087 "<varlistentry><term>%s</term><listitem>" 1085 "<varlistentry><term>%s</term><listitem>"
1088 (or item-tag 1086 (or item-tag
1089 "???")))))) 1087 "???"))))))
1090 ;; For DocBook, we need to open a para right after tag 1088 ;; For DocBook, we need to open a para right after tag
1091 ;; <listitem>. 1089 ;; <listitem>.
1092 (org-export-docbook-open-para))
1093 (didclose
1094 ;; We did close a list, normal text follows: need <para>
1095 (org-export-docbook-open-para))) 1090 (org-export-docbook-open-para)))
1096 ;; Checkboxes. 1091 ;; Checkboxes.
1097 (if (string-match "^[ \t]*\\(\\[[X -]\\]\\)" line) 1092 (if (string-match "^[ \t]*\\(\\[[X -]\\]\\)" line)
1098 (setq line 1093 (setq line
1099 (replace-match (concat checkbox-start 1094 (replace-match (concat checkbox-start
1132 1127
1133 ;; Properly close all local lists and other lists 1128 ;; Properly close all local lists and other lists
1134 (when inquote 1129 (when inquote
1135 (insert "]]></programlisting>\n") 1130 (insert "]]></programlisting>\n")
1136 (org-export-docbook-open-para)) 1131 (org-export-docbook-open-para))
1137 (when in-local-list 1132
1138 ;; Close any local lists before inserting a new header line
1139 (while local-list-type
1140 (let ((listtype (car local-list-type)))
1141 (org-export-docbook-close-li listtype)
1142 (insert (cond
1143 ((equal listtype "o") "</orderedlist>\n")
1144 ((equal listtype "u") "</itemizedlist>\n")
1145 ((equal listtype "d") "</variablelist>\n"))))
1146 (pop local-list-type))
1147 (setq local-list-indent nil
1148 in-local-list nil))
1149 ;; Close all open sections. 1133 ;; Close all open sections.
1150 (org-export-docbook-level-start 1 nil) 1134 (org-export-docbook-level-start 1 nil)
1151 1135
1152 (unless (plist-get opt-plist :buffer-will-be-killed) 1136 (unless (plist-get opt-plist :buffer-will-be-killed)
1153 (normal-mode) 1137 (normal-mode)
1210 (insert "</listitem>\n"))) 1194 (insert "</listitem>\n")))
1211 1195
1212 (defvar in-local-list) 1196 (defvar in-local-list)
1213 (defvar local-list-indent) 1197 (defvar local-list-indent)
1214 (defvar local-list-type) 1198 (defvar local-list-type)
1215 (defun org-export-docbook-close-lists-maybe (line)
1216 (let ((ind (or (get-text-property 0 'original-indentation line)))
1217 ; (and (string-match "\\S-" line)
1218 ; (org-get-indentation line))))
1219 didclose)
1220 (when ind
1221 (while (and in-local-list
1222 (<= ind (car local-list-indent)))
1223 (setq didclose t)
1224 (let ((listtype (car local-list-type)))
1225 (org-export-docbook-close-li listtype)
1226 (insert (cond
1227 ((equal listtype "o") "</orderedlist>\n")
1228 ((equal listtype "u") "</itemizedlist>\n")
1229 ((equal listtype "d") "</variablelist>\n"))))
1230 (pop local-list-type) (pop local-list-indent)
1231 (setq in-local-list local-list-indent))
1232 (and didclose (org-export-docbook-open-para)))))
1233 1199
1234 (defun org-export-docbook-level-start (level title) 1200 (defun org-export-docbook-level-start (level title)
1235 "Insert a new level in DocBook export. 1201 "Insert a new level in DocBook export.
1236 When TITLE is nil, just close all open levels." 1202 When TITLE is nil, just close all open levels."
1237 (org-export-docbook-close-para-maybe) 1203 (org-export-docbook-close-para-maybe)
1247 (when title 1213 (when title
1248 ;; If title is nil, this means this function is called to close 1214 ;; If title is nil, this means this function is called to close
1249 ;; all levels, so the rest is done only if title is given. 1215 ;; all levels, so the rest is done only if title is given.
1250 ;; 1216 ;;
1251 ;; Format tags: put them into a superscript like format. 1217 ;; Format tags: put them into a superscript like format.
1252 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title) 1218 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
1253 (setq title 1219 (setq title
1254 (replace-match 1220 (replace-match
1255 (if org-export-with-tags 1221 (if org-export-with-tags
1256 (save-match-data 1222 (save-match-data
1257 (concat 1223 (concat
1271 (defun org-docbook-expand (string) 1237 (defun org-docbook-expand (string)
1272 "Prepare STRING for DocBook export. 1238 "Prepare STRING for DocBook export.
1273 Applies all active conversions. If there are links in the 1239 Applies all active conversions. If there are links in the
1274 string, don't modify these." 1240 string, don't modify these."
1275 (let* ((re (concat org-bracket-link-regexp "\\|" 1241 (let* ((re (concat org-bracket-link-regexp "\\|"
1276 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))) 1242 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1277 m s l res) 1243 m s l res)
1278 (while (setq m (string-match re string)) 1244 (while (setq m (string-match re string))
1279 (setq s (substring string 0 m) 1245 (setq s (substring string 0 m)
1280 l (match-string 0 string) 1246 l (match-string 0 string)
1281 string (substring string (match-end 0))) 1247 string (substring string (match-end 0)))