org-export-generic.el 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. ;;; org-export-generic.el --- Export frameworg with custom backends
  2. ;; Copyright (C) 2009 Free Software Foundation, Inc.
  3. ;; Author: Wes Hardaker <hardaker at users dot sourceforge dot net>
  4. ;; Keywords: outlines, hypermedia, calendar, wp, export
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 6.25trans
  7. ;; Acks: Much of this code was stolen form the ascii export from Carsten
  8. ;;
  9. ;; This file is not yet part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;
  22. ;; ----------------------------------------------------------------------
  23. ;;
  24. ;; OVERVIEW
  25. ;;
  26. ;; org-export-generic is basically a simple translation system that
  27. ;; knows how to parse at least most of a .org buffer and then add
  28. ;; various formatting prefixes before and after each section type. It
  29. ;; does this by examining a property list stored in org-generic-alist.
  30. ;; You can dynamically add propety lists of your own using the
  31. ;; org-set-generic-type function:
  32. ;;
  33. ;; (org-set-generic-type
  34. ;; "really-basic-text"
  35. ;; '(:file-suffix ".txt"
  36. ;; :key-binding ?R
  37. ;;
  38. ;; :title-format "=== %s ===\n"
  39. ;; :body-header-section-numbers t
  40. ;; :body-header-section-number-format "%s) "
  41. ;; :body-section-header-prefix "\n"
  42. ;; :body-section-header-suffix "\n"
  43. ;; :body-line-format " %s\n"
  44. ;; :body-line-wrap 75
  45. ;; ))
  46. ;;
  47. ;; Note: Upper case key-bindings are reserved for your use. Lower
  48. ;; case key bindings may conflict with future export-generic
  49. ;; publications.
  50. ;;
  51. ;; Then run org-export (ctrl-c ctrl-e) and select generic or run
  52. ;; org-export-generic. You'll then be prompted with a list of export
  53. ;; types to choose from which will include your new type assigned to
  54. ;; the key "r".
  55. ;;
  56. ;; ----------------------------------------------------------------------
  57. ;;
  58. ;; TODO (non-ordered)
  59. ;; * handle function references
  60. ;; * handle other types of multi-complex-listy-things to do
  61. ;; ideas: (t ?- "%s" ?-)
  62. ;; * handle indent specifiers better
  63. ;; ideas: (4 ?\ "%s")
  64. ;; * need flag to remove indents from body text
  65. ;; * handle links
  66. ;; * handle internationalization strings better
  67. ;; * date/author/etc needs improvment (internationalization too)
  68. ;; * allow specifying of section ordering
  69. ;; ideas: :ordering ("header" "toc" "body" "footer")
  70. ;; ^ matches current hard coded ordering
  71. ;; * err, actually *do* a footer
  72. ;; * deal with usage of org globals
  73. ;; *** should we even consider them, or let the per-section specifiers do it
  74. ;; *** answer: remove; mostly removed now
  75. ;; * deal with interactive support for picking a export specifier label
  76. ;; * char specifiers that need extra length because of formatting
  77. ;; idea: (?- 4) for 4-longer
  78. ;; * centering specifier
  79. ;; idea: ('center " -- %s -- ")
  80. ;; * remove more of the unneeded export-to-ascii copy code
  81. ;; * tags
  82. ;; *** supported now, but need separate format per tag
  83. ;; *** allow different open/closing prefixes
  84. ;; * properties
  85. ;; * drawers
  86. ;; * oh my
  87. ;; * optmization (many plist extracts should be in (let) vars
  88. ;; * define defcustom spec for the specifier list
  89. ;;
  90. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  91. ;;
  92. ;;; Commentary:
  93. (require 'org-exp)
  94. (require 'assoc)
  95. (defgroup org-export-generic nil
  96. "Options specific for ASCII export of Org-mode files."
  97. :tag "Org Export ASCII"
  98. :group 'org-export)
  99. (defcustom org-export-generic-links-to-notes t
  100. "Non-nil means convert links to notes before the next headline.
  101. When nil, the link will be exported in place. If the line becomes long
  102. in this way, it will be wrapped."
  103. :group 'org-export-generic
  104. :type 'boolean)
  105. (defvar org-generic-current-indentation nil) ; For communication
  106. (defvar org-generic-alist
  107. '(
  108. ;;
  109. ;; generic DEMO exporter
  110. ;;
  111. ;; (this tries to use every specifier for demo purposes)
  112. ;;
  113. ("demo"
  114. :file-suffix ".txt"
  115. :key-binding ?d
  116. :header-prefix "<header>\n"
  117. :header-suffix "</header>\n"
  118. :author-export t
  119. :tags-export t
  120. :drawers-export t
  121. :title-prefix ?=
  122. :title-format "<h1>%s</h1>\n"
  123. :title-suffix ?=
  124. :date-export t
  125. :date-prefix "<date>"
  126. :date-format "<br /><b>Date:</b> <i>%s</i><br />"
  127. :date-suffix "</date>\n\n"
  128. :toc-export t
  129. :toc-header-prefix "<tocname>\n"
  130. :toc-header-format "__%s__\n"
  131. :toc-header-suffix "</tocname>\n"
  132. :toc-prefix "<toc>\n"
  133. :toc-suffix "</toc>\n"
  134. :toc-section-numbers t
  135. :toc-section-number-format "\#(%s) "
  136. :toc-format "--%s--"
  137. :toc-format-with-todo "!!%s!!\n"
  138. :toc-indent-char ?\
  139. :toc-indent-depth 4
  140. :toc-tags-export t
  141. :toc-tags-prefix " <tags>"
  142. :toc-tags-format "*%s*"
  143. :toc-tags-suffix "</tags>\n"
  144. :toc-tags-none-string "\n"
  145. :body-header-section-numbers 3 ; t = all, nil = none
  146. ; lists indicate different things per level
  147. ; list contents or straight value can either be a
  148. ; ?x char reference for printing strings that match the header len
  149. ; "" string to print directly
  150. :body-section-header-prefix ("<h1>" "<h2>" "<h3>"
  151. "<h4>" "<h5>" "<h6>")
  152. :body-section-header-format "%s"
  153. :body-section-header-suffix ("</h1>\n" "</h2>\n" "</h3>\n"
  154. "</h4>\n" "</h5>\n" "</h6>\n")
  155. :timestamps-export t
  156. :priorities-export t
  157. :todo-keywords-export t
  158. :body-tags-export t
  159. :body-tags-prefix " <tags>"
  160. :body-tags-suffix "</tags>\n"
  161. ; section prefixes/suffixes can be direct strings or lists as well
  162. :body-section-prefix "<secprefix>\n"
  163. :body-section-suffix "</secsuffix>\n"
  164. ; :body-section-prefix ("<sec1>\n" "<sec2>\n" "<sec3>\n")
  165. ; :body-section-suffix ("</sec1>\n" "</sec2>\n" "</sec3>\n")
  166. ; if preformated text should be included (eg, : prefixed)
  167. :body-line-export-preformated t
  168. :body-line-fixed-prefix "<pre>\n"
  169. :body-line-fixed-suffix "\n</pre>\n"
  170. :body-line-fixed-format "%s\n"
  171. :body-list-prefix "<list>\n"
  172. :body-list-suffix "</list>\n"
  173. :body-list-format "<li>%s</li>\n"
  174. :body-number-list-prefix "<ol>\n"
  175. :body-number-list-suffix "</ol>\n"
  176. :body-number-list-format "<li>%s</li>\n"
  177. :body-number-list-leave-number t
  178. :body-list-checkbox-todo "<checkbox type=\"todo\">"
  179. :body-list-checkbox-todo-end "</checkbox (todo)>"
  180. :body-list-checkbox-done "<checkbox type=\"done\">"
  181. :body-list-checkbox-done-end "</checkbox (done)>"
  182. :body-list-checkbox-half "<checkbox type=\"half\">"
  183. :body-list-checkbox-half-end "</checkbox (half)>"
  184. ; other body lines
  185. :body-line-format "%s"
  186. :body-line-wrap 60 ; wrap at 60 chars
  187. ; print above and below all body parts
  188. :body-text-prefix "<p>\n"
  189. :body-text-suffix "</p>\n"
  190. )
  191. ;;
  192. ;; ascii exporter
  193. ;;
  194. ;; (close to the original ascii specifier)
  195. ;;
  196. ("ascii"
  197. :file-suffix ".txt"
  198. :key-binding ?a
  199. :header-prefix ""
  200. :header-suffix ""
  201. :title-prefix ?=
  202. :title-format "%s\n"
  203. :title-suffix ?=
  204. :date-export t
  205. :date-prefix ""
  206. :date-format "Date: %s\n"
  207. :date-suffix ""
  208. :toc-header-prefix ""
  209. :toc-header-format "%s\n"
  210. :toc-header-suffix ?=
  211. :toc-export t
  212. :toc-section-numbers t
  213. :toc-section-number-format "%s "
  214. :toc-format "%s\n"
  215. :toc-format-with-todo "%s (*)\n"
  216. :toc-indent-char ?\
  217. :toc-indent-depth 4
  218. :body-header-section-numbers 3
  219. :body-section-prefix "\n"
  220. ; :body-section-header-prefix "\n"
  221. ; :body-section-header-format "%s\n"
  222. ; :body-section-header-suffix (?\$ ?\# ?^ ?\~ ?\= ?\-)
  223. :body-section-header-prefix ("" "" "" "* " " + " " - ")
  224. :body-section-header-format "%s\n"
  225. :body-section-header-suffix (?~ ?= ?- "\n" "\n" "\n")
  226. ; :body-section-marker-prefix ""
  227. ; :body-section-marker-chars (?\$ ?\# ?^ ?\~ ?\= ?\-)
  228. ; :body-section-marker-suffix "\n"
  229. :body-line-export-preformated t
  230. :body-line-format "%s\n"
  231. :body-line-wrap 75
  232. ; :body-text-prefix "<t>\n"
  233. ; :body-text-suffix "</t>\n"
  234. :body-bullet-list-prefix (?* ?+ ?-)
  235. ; :body-bullet-list-suffix (?* ?+ ?-)
  236. )
  237. ;;
  238. ;; wikipedia
  239. ;;
  240. ("wikipedia"
  241. :file-suffix ".txt"
  242. :key-binding ?w
  243. :header-prefix ""
  244. :header-suffix ""
  245. :title-format "= %s =\n"
  246. :date-export nil
  247. :toc-export nil
  248. :body-header-section-numbers nil
  249. :body-section-prefix "\n"
  250. :body-section-header-prefix ("= " "== " "=== "
  251. "==== " "===== " "====== ")
  252. :body-section-header-suffix (" =\n\n" " ==\n\n" " ===\n\n"
  253. " ====\n\n" " =====\n\n" " ======\n\n")
  254. :body-line-export-preformated t ;; yes/no/maybe???
  255. :body-line-format "%s\n"
  256. :body-line-wrap 75
  257. :body-line-fixed-format " %s\n"
  258. :body-list-format "* %s\n"
  259. :body-number-list-format "# %s\n"
  260. :body-bullet-list-prefix ("* " "** " "*** " "**** " "***** ")
  261. )
  262. ;;
  263. ;; minimal html exporter
  264. ;;
  265. ("html"
  266. ;; simple html output
  267. :file-suffix ".html"
  268. :key-binding ?h
  269. :header-prefix "<body>"
  270. :title-format "<h1>%s</h1>\n\n"
  271. :date-export t
  272. :date-format "<br /><b>Date:</b> <i>%s</i><br />\n\n"
  273. :toc-export nil
  274. :body-header-section-numbers 3
  275. :body-section-header-prefix ("<h1>" "<h2>" "<h3>"
  276. "<h4>" "<h5>" "<h6>")
  277. :body-section-header-format "%s"
  278. :body-section-header-suffix ("</h1>\n" "</h2>\n" "</h3>\n"
  279. "</h4>\n" "</h5>\n" "</h6>\n")
  280. :body-section-prefix "<secprefix>\n"
  281. :body-section-suffix "</secsuffix>\n"
  282. ; :body-section-prefix ("<sec1>\n" "<sec2>\n" "<sec3>\n")
  283. ; :body-section-suffix ("</sec1>\n" "</sec2>\n" "</sec3>\n")
  284. :body-line-export-preformated t
  285. :body-line-format "%s\n"
  286. :body-text-prefix "<p>\n"
  287. :body-text-suffix "</p>\n"
  288. :body-bullet-list-prefix (?* ?+ ?-)
  289. ; :body-bullet-list-suffix (?* ?+ ?-)
  290. )
  291. ;;
  292. ;; internet-draft .xml for xml2rfc exporter
  293. ;;
  294. ("ietfid"
  295. ;; this tries to use every specifier for demo purposes
  296. :file-suffix ".xml"
  297. :key-binding ?i
  298. :title-prefix "<?xml version=\"1.0\"\?>
  299. <!DOCTYPE rfc SYSTEM \"rfc2629.dtd\" [
  300. <!ENTITY rfcs PUBLIC '' 'blah'>
  301. <?rfc strict=\"yes\" ?>
  302. <?rfc toc=\"yes\" ?>
  303. <?rfc tocdepth=\"4\" ?>
  304. <?rfc symrefs=\"yes\" ?>
  305. <?rfc compact=\"yes\" ?>
  306. <?rfc subcompact=\"no\" ?>
  307. <rfc category=\"std\" ipr=\"pre5378Trust200902\" docName=\"FILLME.txt\">
  308. <front>
  309. "
  310. :title-format "<title abbrev=\"ABBREV HERE\">\n%s\n</title>\n"
  311. :title-suffix "<author initials=\"A.A\" surname=\"LASTNAME\" fullname=\"FULL NAME\">
  312. <organization>Comany, Inc..</organization>
  313. <address>
  314. <postal>
  315. <street></street>
  316. <city></city>
  317. <region></region>
  318. <code></code>
  319. <country></country>
  320. </postal>
  321. <phone></phone>
  322. <email></email>
  323. </address>
  324. </author>
  325. <date month=\"FILLMONTH\" year=\"FILLYEAR\"/>
  326. <area>Operations and Management</area>
  327. <workgroup>FIXME</workgroup>
  328. <abstract>\n"
  329. :date-export nil
  330. :toc-export nil
  331. :body-header-section-numbers nil
  332. :body-section-header-format "<section title=\"%s\">\n"
  333. :body-section-suffix "</section>\n"
  334. ; if preformated text should be included (eg, : prefixed)
  335. :body-line-export-preformated t
  336. :body-line-fixed-prefix "<figure>\n<artwork>\n"
  337. :body-line-fixed-suffix "\n</artwork>\n</figure>\n"
  338. ; other body lines
  339. :body-line-format "%s"
  340. :body-line-wrap 75
  341. ; print above and below all body parts
  342. :body-text-prefix "<t>\n"
  343. :body-text-suffix "</t>\n"
  344. :body-list-prefix "<list style=\"symbols\">\n"
  345. :body-list-suffix "</list>\n"
  346. :body-list-format "<t>%s</t>\n"
  347. )
  348. )
  349. "A assoc list of property lists to specify export definitions"
  350. )
  351. (setq org-generic-export-type "demo")
  352. (defvar org-export-generic-section-type "")
  353. (defvar org-export-generic-section-suffix "")
  354. ;;;###autoload
  355. (defun org-set-generic-type (type definition)
  356. "Adds a TYPE and DEFINITION to the existing list of defined generic
  357. export definitions."
  358. (aput 'org-generic-alist type definition))
  359. (defun org-export-generic-remember-section (type suffix &optional prefix)
  360. (setq org-export-generic-section-type type)
  361. (setq org-export-generic-section-suffix suffix)
  362. (if prefix
  363. (insert prefix))
  364. )
  365. (defun org-export-generic-check-section (type &optional prefix suffix)
  366. "checks to see if type is already in use, or we're switching parts
  367. If we're switching, then insert a potentially previously remembered
  368. suffix, and insert the current prefix immediately and then save the
  369. suffix a later change time."
  370. (when (not (equal type org-export-generic-section-type))
  371. (if org-export-generic-section-suffix
  372. (insert org-export-generic-section-suffix))
  373. (setq org-export-generic-section-type type)
  374. (setq org-export-generic-section-suffix suffix)
  375. (if prefix
  376. (insert prefix))))
  377. ;;;###autoload
  378. (defun org-export-generic (arg)
  379. "Export the outline as generic output.
  380. If there is an active region, export only the region.
  381. The prefix ARG specifies how many levels of the outline should become
  382. underlined headlines. The default is 3."
  383. (interactive "P")
  384. (setq-default org-todo-line-regexp org-todo-line-regexp)
  385. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  386. (org-infile-export-plist)))
  387. (region-p (org-region-active-p))
  388. (rbeg (and region-p (region-beginning)))
  389. (rend (and region-p (region-end)))
  390. (subtree-p
  391. (when region-p
  392. (save-excursion
  393. (goto-char rbeg)
  394. (and (org-at-heading-p)
  395. (>= (org-end-of-subtree t t) rend)))))
  396. (level-offset (if subtree-p
  397. (save-excursion
  398. (goto-char rbeg)
  399. (+ (funcall outline-level)
  400. (if org-odd-levels-only 1 0)))
  401. 0))
  402. (opt-plist (setq org-export-opt-plist
  403. (if subtree-p
  404. (org-export-add-subtree-options opt-plist rbeg)
  405. opt-plist)))
  406. helpstart
  407. (bogus (mapc (lambda (x)
  408. (setq helpstart
  409. (concat helpstart "\["
  410. (char-to-string
  411. (plist-get (cdr x) :key-binding))
  412. "] " (car x) "\n")))
  413. org-generic-alist))
  414. (help (concat helpstart "
  415. \[ ] the current setting of the org-generic-export-type variable
  416. "))
  417. (cmds
  418. (append
  419. (mapcar (lambda (x)
  420. (list
  421. (plist-get (cdr x) :key-binding)
  422. (car x)))
  423. org-generic-alist)
  424. (list (list ? "default"))))
  425. r1 r2 ass
  426. ;; read in the type to use
  427. (export-plist
  428. (progn
  429. (save-excursion
  430. (save-window-excursion
  431. (delete-other-windows)
  432. (with-output-to-temp-buffer "*Org Export/Generic Styles Help*"
  433. (princ help))
  434. (org-fit-window-to-buffer (get-buffer-window
  435. "*Org Export/Generic Styles Help*"))
  436. (message "Select command: ")
  437. (setq r1 (read-char-exclusive))))
  438. (setq r2 (if (< r1 27) (+ r1 96) r1))
  439. (unless (setq ass (cadr (assq r2 cmds)))
  440. (error "No command associated with key %c" r1))
  441. (cdr (assoc
  442. (if (equal ass "default") org-generic-export-type ass)
  443. org-generic-alist))))
  444. (custom-times org-display-custom-times)
  445. (org-generic-current-indentation '(0 . 0))
  446. (level 0) (old-level 0) line txt lastwastext
  447. (umax nil)
  448. (umax-toc nil)
  449. (case-fold-search nil)
  450. (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  451. (filesuffix (or (plist-get export-plist :file-suffix) ".foo"))
  452. (filename (concat (file-name-as-directory
  453. (org-export-directory :ascii opt-plist))
  454. (file-name-sans-extension
  455. (or (and subtree-p
  456. (org-entry-get (region-beginning)
  457. "EXPORT_FILE_NAME" t))
  458. (file-name-nondirectory bfname)))
  459. filesuffix))
  460. (filename (if (equal (file-truename filename)
  461. (file-truename bfname))
  462. (concat filename filesuffix)
  463. filename))
  464. (buffer (find-file-noselect filename))
  465. (org-levels-open (make-vector org-level-max nil))
  466. (odd org-odd-levels-only)
  467. (date (plist-get opt-plist :date))
  468. (author (plist-get opt-plist :author))
  469. (title (or (and subtree-p (org-export-get-title-from-subtree))
  470. (plist-get opt-plist :title)
  471. (and (not
  472. (plist-get opt-plist :skip-before-1st-heading))
  473. (org-export-grab-title-from-buffer))
  474. (file-name-sans-extension
  475. (file-name-nondirectory bfname))))
  476. (email (plist-get opt-plist :email))
  477. (language (plist-get opt-plist :language))
  478. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  479. ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
  480. (todo nil)
  481. (lang-words nil)
  482. (region
  483. (buffer-substring
  484. (if (org-region-active-p) (region-beginning) (point-min))
  485. (if (org-region-active-p) (region-end) (point-max))))
  486. (lines (org-split-string
  487. (org-export-preprocess-string
  488. region
  489. :for-ascii t
  490. :skip-before-1st-heading
  491. (plist-get opt-plist :skip-before-1st-heading)
  492. :drawers (plist-get export-plist :drawers-export)
  493. :tags (plist-get export-plist :tags-export)
  494. :priority (plist-get export-plist :priority-export)
  495. :footnotes (plist-get export-plist :footnotes-export)
  496. :timestamps (plist-get export-plist :timestamps-export)
  497. :todo-keywords (plist-get export-plist :todo-keywords-export)
  498. :verbatim-multiline t
  499. :select-tags (plist-get export-plist :select-tags-export)
  500. :exclude-tags (plist-get export-plist :exclude-tags-export)
  501. :archived-trees
  502. (plist-get export-plist :archived-trees-export)
  503. :add-text (plist-get opt-plist :text))
  504. "\n"))
  505. ;; export-generic plist variables
  506. (withtags (plist-get export-plist :tags-export))
  507. (tagsintoc (plist-get export-plist :toc-tags-export))
  508. (tocnotagsstr (or (plist-get export-plist :toc-tags-none-string) ""))
  509. (tocdepth (plist-get export-plist :toc-indent-depth))
  510. (tocindentchar (plist-get export-plist :toc-indent-char))
  511. (tocsecnums (plist-get export-plist :toc-section-numbers))
  512. (tocsecnumform (plist-get export-plist :toc-section-number-format))
  513. (tocformat (plist-get export-plist :toc-format))
  514. (tocformtodo (plist-get export-plist :toc-format-with-todo))
  515. (tocprefix (plist-get export-plist :toc-prefix))
  516. (tocsuffix (plist-get export-plist :toc-suffix))
  517. (bodyfixedpre (plist-get export-plist :body-line-fixed-prefix))
  518. (bodyfixedsuf (plist-get export-plist :body-line-fixed-suffix))
  519. (bodyfixedform (or (plist-get export-plist :body-line-fixed-format)
  520. "%s"))
  521. (listprefix (plist-get export-plist :body-list-prefix))
  522. (listsuffix (plist-get export-plist :body-list-suffix))
  523. (listformat (or (plist-get export-plist :body-list-format) "%s\n"))
  524. (numlistleavenum
  525. (plist-get export-plist :body-number-list-leave-number))
  526. (numlistprefix (plist-get export-plist :body-number-list-prefix))
  527. (numlistsuffix (plist-get export-plist :body-number-list-suffix))
  528. (numlistformat
  529. (or (plist-get export-plist :body-number-list-format) "%s\n"))
  530. (listchecktodo
  531. (or (plist-get export-plist :body-list-checkbox-todo) "\\1"))
  532. (listcheckdone
  533. (or (plist-get export-plist :body-list-checkbox-done) "\\1"))
  534. (listcheckhalf
  535. (or (plist-get export-plist :body-list-checkbox-half) "\\1"))
  536. (listchecktodoend
  537. (or (plist-get export-plist :body-list-checkbox-todo-end) ""))
  538. (listcheckdoneend
  539. (or (plist-get export-plist :body-list-checkbox-done-end) ""))
  540. (listcheckhalfend
  541. (or (plist-get export-plist :body-list-checkbox-half-end) ""))
  542. (bodytextpre (plist-get export-plist :body-text-prefix))
  543. (bodytextsuf (plist-get export-plist :body-text-suffix))
  544. (bodylinewrap (plist-get export-plist :body-line-wrap))
  545. (bodylineform (or (plist-get export-plist :body-line-format) "%s"))
  546. thetoc toctags have-headings first-heading-pos
  547. table-open table-buffer link-buffer link desc desc0 rpl wrap)
  548. (let ((inhibit-read-only t))
  549. (org-unmodified
  550. (remove-text-properties (point-min) (point-max)
  551. '(:org-license-to-kill t))))
  552. (setq org-min-level (org-get-min-level lines level-offset))
  553. (setq org-last-level org-min-level)
  554. (org-init-section-numbers)
  555. (find-file-noselect filename)
  556. (setq lang-words (or (assoc language org-export-language-setup)
  557. (assoc "en" org-export-language-setup)))
  558. (switch-to-buffer-other-window buffer)
  559. (erase-buffer)
  560. (fundamental-mode)
  561. ;; create local variables for all options, to make sure all called
  562. ;; functions get the correct information
  563. (mapc (lambda (x)
  564. (set (make-local-variable (nth 2 x))
  565. (plist-get opt-plist (car x))))
  566. org-export-plist-vars)
  567. (org-set-local 'org-odd-levels-only odd)
  568. (setq umax (if arg (prefix-numeric-value arg)
  569. org-export-headline-levels))
  570. (setq umax-toc umax)
  571. ;; File header
  572. (if title
  573. (insert
  574. (org-export-generic-header title export-plist
  575. :title-prefix
  576. :title-format
  577. :title-suffix)))
  578. (if (and (or author email)
  579. (plist-get export-plist :author-export))
  580. (insert (concat (nth 1 lang-words) ": " (or author "")
  581. (if email (concat " <" email ">") "")
  582. "\n")))
  583. (cond
  584. ((and date (string-match "%" date))
  585. (setq date (format-time-string date)))
  586. (date)
  587. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  588. (if (and date (plist-get export-plist :date-export))
  589. (insert
  590. (org-export-generic-header date export-plist
  591. :date-prefix
  592. :date-format
  593. :date-suffix)))
  594. ;; export the table of contents first
  595. (if (plist-get export-plist :toc-export)
  596. (progn
  597. (push
  598. (org-export-generic-header (nth 3 lang-words) export-plist
  599. :toc-header-prefix
  600. :toc-header-format
  601. :toc-header-suffix)
  602. thetoc)
  603. (if tocprefix
  604. (push tocprefix thetoc))
  605. (mapc '(lambda (line)
  606. (if (string-match org-todo-line-regexp line)
  607. ;; This is a headline
  608. (progn
  609. (setq have-headings t)
  610. (setq level (- (match-end 1) (match-beginning 1)
  611. level-offset)
  612. level (org-tr-level level)
  613. txt (match-string 3 line)
  614. todo
  615. (or (and org-export-mark-todo-in-toc
  616. (match-beginning 2)
  617. (not (member (match-string 2 line)
  618. org-done-keywords)))
  619. ; TODO, not DONE
  620. (and org-export-mark-todo-in-toc
  621. (= level umax-toc)
  622. (org-search-todo-below
  623. line lines level))))
  624. (setq txt (org-html-expand-for-generic txt))
  625. (while (string-match org-bracket-link-regexp txt)
  626. (setq txt
  627. (replace-match
  628. (match-string (if (match-end 2) 3 1) txt)
  629. t t txt)))
  630. (if (and (not tagsintoc)
  631. (string-match
  632. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  633. txt))
  634. (setq txt (replace-match "" t t txt))
  635. ; include tags but formated
  636. (if (string-match
  637. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$")
  638. txt)
  639. (progn
  640. (setq
  641. toctags
  642. (org-export-generic-header
  643. (match-string 1 txt)
  644. export-plist :toc-tags-prefix
  645. :toc-tags-format :toc-tags-suffix))
  646. (string-match
  647. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  648. txt)
  649. (setq txt (replace-match "" t t txt)))
  650. (setq toctags tocnotagsstr)))
  651. (if (string-match quote-re0 txt)
  652. (setq txt (replace-match "" t t txt)))
  653. (if (<= level umax-toc)
  654. (progn
  655. (push
  656. (concat
  657. (make-string
  658. (* (max 0 (- level org-min-level)) tocdepth)
  659. tocindentchar)
  660. (if tocsecnums
  661. (format tocsecnumform
  662. (org-section-number level))
  663. "")
  664. (format
  665. (if todo tocformtodo tocformat)
  666. txt)
  667. toctags)
  668. thetoc)
  669. (setq org-last-level level))
  670. ))))
  671. lines)
  672. (if tocsuffix
  673. (push tocsuffix thetoc))
  674. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  675. (org-init-section-numbers)
  676. (org-export-generic-check-section "top")
  677. (while (setq line (pop lines))
  678. (when (and link-buffer (string-match "^\\*+ " line))
  679. (org-export-generic-push-links (nreverse link-buffer))
  680. (setq link-buffer nil))
  681. (setq wrap nil)
  682. ;; Remove the quoted HTML tags.
  683. ;; XXX
  684. (setq line (org-html-expand-for-generic line))
  685. ;; Replace links with the description when possible
  686. ;; XXX
  687. (while (string-match org-bracket-link-regexp line)
  688. (setq link (match-string 1 line)
  689. desc0 (match-string 3 line)
  690. desc (or desc0 (match-string 1 line)))
  691. (if (and (> (length link) 8)
  692. (equal (substring link 0 8) "coderef:"))
  693. (setq line (replace-match
  694. (format (org-export-get-coderef-format (substring link 8) desc)
  695. (cdr (assoc
  696. (substring link 8)
  697. org-export-code-refs)))
  698. t t line))
  699. (setq rpl (concat "["
  700. (or (match-string 3 line) (match-string 1 line))
  701. "]"))
  702. (when (and desc0 (not (equal desc0 link)))
  703. (if org-export-generic-links-to-notes
  704. (push (cons desc0 link) link-buffer)
  705. (setq rpl (concat rpl " (" link ")")
  706. wrap (+ (length line) (- (length (match-string 0) line))
  707. (length desc)))))
  708. (setq line (replace-match rpl t t line))))
  709. (when custom-times
  710. (setq line (org-translate-time line)))
  711. (cond
  712. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  713. ;;
  714. ;; a Headline
  715. ;;
  716. (org-export-generic-check-section "headline")
  717. (setq first-heading-pos (or first-heading-pos (point)))
  718. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  719. level-offset))
  720. txt (match-string 2 line))
  721. (org-generic-level-start level old-level txt umax export-plist lines)
  722. (setq old-level level))
  723. ((and org-export-with-tables
  724. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  725. ;;
  726. ;; a Table
  727. ;;
  728. (org-export-generic-check-section "table")
  729. (if (not table-open)
  730. ;; New table starts
  731. (setq table-open t table-buffer nil))
  732. ;; Accumulate table lines
  733. (setq table-buffer (cons line table-buffer))
  734. (when (or (not lines)
  735. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  736. (car lines))))
  737. (setq table-open nil
  738. table-buffer (nreverse table-buffer))
  739. (insert (mapconcat
  740. (lambda (x)
  741. (org-fix-indentation x org-generic-current-indentation))
  742. (org-format-table-generic table-buffer)
  743. "\n") "\n")))
  744. ((string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line)
  745. ;;
  746. ;; pre-formated text
  747. ;;
  748. (setq line (replace-match "\\1" nil nil line))
  749. (org-export-generic-check-section "preformat" bodyfixedpre bodyfixedsuf)
  750. (insert (format bodyfixedform line)))
  751. ((or (string-match "^\\([ \t]*\\)\\([\-\+][ \t]*\\)" line)
  752. ;; if the bullet list item is an asterisk, the leading space is /mandatory/
  753. ;; [2010/02/02:rpg]
  754. (string-match "^\\([ \t]+\\)\\(\\*[ \t]*\\)" line))
  755. ;;
  756. ;; plain list item
  757. ;;
  758. ;; TODO: nested lists
  759. ;;
  760. ;; I believe this gets rid of leading whitespace.
  761. (setq line (replace-match "" nil nil line))
  762. ;; won't this insert the suffix /before/ the last line of the list?
  763. ;; also isn't it spoofed by bulleted lists that have a line skip between the list items
  764. ;; unless 'org-empty-line-terminates-plain-lists' is true?
  765. (org-export-generic-check-section "liststart" listprefix listsuffix)
  766. ;; deal with checkboxes
  767. (cond
  768. ((string-match "^\\(\\[ \\]\\)[ \t]*" line)
  769. (setq line (concat (replace-match listchecktodo nil nil line)
  770. listchecktodoend)))
  771. ((string-match "^\\(\\[X\\]\\)[ \t]*" line)
  772. (setq line (concat (replace-match listcheckdone nil nil line)
  773. listcheckdoneend)))
  774. ((string-match "^\\(\\[/\\]\\)[ \t]*" line)
  775. (setq line (concat (replace-match listcheckhalf nil nil line)
  776. listcheckhalfend)))
  777. )
  778. (insert (format listformat line)))
  779. ((string-match "^\\([ \t]+\\)\\([0-9]+\\.[ \t]*\\)" line)
  780. ;;
  781. ;; numbered list item
  782. ;;
  783. ;; TODO: nested lists
  784. ;;
  785. (setq line (replace-match (if numlistleavenum "\\2" "") nil nil line))
  786. (org-export-generic-check-section "numliststart"
  787. numlistprefix numlistsuffix)
  788. ;; deal with checkboxes
  789. ;; TODO: whoops; leaving the numbers is a problem for ^ matching
  790. (cond
  791. ((string-match "\\(\\[ \\]\\)[ \t]*" line)
  792. (setq line (concat (replace-match listchecktodo nil nil line)
  793. listchecktodoend)))
  794. ((string-match "\\(\\[X\\]\\)[ \t]*" line)
  795. (setq line (concat (replace-match listcheckdone nil nil line)
  796. listcheckdoneend)))
  797. ((string-match "\\(\\[/\\]\\)[ \t]*" line)
  798. (setq line (concat (replace-match listcheckhalf nil nil line)
  799. listcheckhalfend)))
  800. )
  801. (insert (format numlistformat line)))
  802. (t
  803. ;;
  804. ;; body
  805. ;;
  806. (org-export-generic-check-section "body" bodytextpre bodytextsuf)
  807. ;; XXX: properties? list?
  808. (if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)" line)
  809. (setq line (replace-match "\\1\\3:" t nil line)))
  810. (setq line (org-fix-indentation line org-generic-current-indentation))
  811. ;; Remove forced line breaks
  812. (if (string-match "\\\\\\\\[ \t]*$" line)
  813. (setq line (replace-match "" t t line)))
  814. (if bodylinewrap
  815. ;; XXX: was dependent on wrap var which was calculated by???
  816. (if (> (length line) bodylinewrap)
  817. (setq line
  818. (org-export-generic-wrap line bodylinewrap))
  819. (setq line line)))
  820. (insert (format bodylineform line)))))
  821. ;; if we're at a level > 0; insert the closing body level stuff
  822. (let ((counter 0))
  823. (while (> (- level counter) 0)
  824. (insert
  825. (org-export-generic-format export-plist :body-section-suffix 0
  826. (- level counter)))
  827. (setq counter (1+ counter))))
  828. (org-export-generic-check-section "bottom")
  829. (org-export-generic-push-links (nreverse link-buffer))
  830. (normal-mode)
  831. ;; insert the table of contents
  832. (when thetoc
  833. (goto-char (point-min))
  834. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  835. (progn
  836. (goto-char (match-beginning 0))
  837. (replace-match ""))
  838. (goto-char first-heading-pos))
  839. (mapc 'insert thetoc)
  840. (or (looking-at "[ \t]*\n[ \t]*\n")
  841. (insert "\n\n")))
  842. ;; Convert whitespace place holders
  843. (goto-char (point-min))
  844. (let (beg end)
  845. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  846. (setq end (next-single-property-change beg 'org-whitespace))
  847. (goto-char beg)
  848. (delete-region beg end)
  849. (insert (make-string (- end beg) ?\ ))))
  850. (save-buffer)
  851. ;; remove display and invisible chars
  852. (let (beg end)
  853. (goto-char (point-min))
  854. (while (setq beg (next-single-property-change (point) 'display))
  855. (setq end (next-single-property-change beg 'display))
  856. (delete-region beg end)
  857. (goto-char beg)
  858. (insert "=>"))
  859. (goto-char (point-min))
  860. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  861. (setq end (next-single-property-change beg 'org-cwidth))
  862. (delete-region beg end)
  863. (goto-char beg)))
  864. (goto-char (point-min))))
  865. (defun org-export-generic-format (export-plist prop &optional len n reverse)
  866. "converts a property specification to a string given types of properties
  867. The EXPORT-PLIST should be defined as the lookup plist.
  868. The PROP should be the property name to search for in it.
  869. LEN is set to the length of multi-characters strings to generate (or 0)
  870. N is the tree depth
  871. REVERSE means to reverse the list if the plist match is a list
  872. "
  873. (let* ((prefixtype (plist-get export-plist prop))
  874. subtype)
  875. (cond
  876. ((null prefixtype) "")
  877. ((and len (char-or-string-p prefixtype) (not (stringp prefixtype)))
  878. ;; sequence of chars
  879. (concat (make-string len prefixtype) "\n"))
  880. ((stringp prefixtype)
  881. prefixtype)
  882. ((and n (listp prefixtype))
  883. (if reverse
  884. (setq prefixtype (reverse prefixtype)))
  885. (setq subtype (if (> n (length prefixtype))
  886. (car (last prefixtype))
  887. (nth (1- n) prefixtype)))
  888. (if (stringp subtype)
  889. subtype
  890. (concat (make-string len subtype) "\n")))
  891. (t ""))
  892. ))
  893. (defun org-export-generic-header (header export-plist
  894. prefixprop formatprop postfixprop
  895. &optional n reverse)
  896. "convert a header to an output string given formatting property names"
  897. (let* ((formatspec (plist-get export-plist formatprop))
  898. (len (length header)))
  899. (concat
  900. (org-export-generic-format export-plist prefixprop len n reverse)
  901. (format (or formatspec "%s") header)
  902. (org-export-generic-format export-plist postfixprop len n reverse))
  903. ))
  904. (defun org-export-generic-preprocess (parameters)
  905. "Do extra work for ASCII export"
  906. ;; Put quotes around verbatim text
  907. (goto-char (point-min))
  908. (while (re-search-forward org-verbatim-re nil t)
  909. (goto-char (match-end 2))
  910. (backward-delete-char 1) (insert "'")
  911. (goto-char (match-beginning 2))
  912. (delete-char 1) (insert "`")
  913. (goto-char (match-end 2)))
  914. ;; Remove target markers
  915. (goto-char (point-min))
  916. (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
  917. (replace-match "\\1\\2")))
  918. (defun org-html-expand-for-generic (line)
  919. "Handle quoted HTML for ASCII export."
  920. (if org-export-html-expand
  921. (while (string-match "@<[^<>\n]*>" line)
  922. ;; We just remove the tags for now.
  923. (setq line (replace-match "" nil nil line))))
  924. line)
  925. (defun org-export-generic-wrap (line where)
  926. "Wrap LINE at or before WHERE."
  927. (let* ((ind (org-get-indentation line))
  928. (indstr (make-string ind ?\ ))
  929. (len (length line))
  930. (result "")
  931. pos didfirst)
  932. (while (> len where)
  933. (catch 'found
  934. (loop for i from where downto (/ where 2) do
  935. (and (equal (aref line i) ?\ )
  936. (setq pos i)
  937. (throw 'found t))))
  938. (if pos
  939. (progn
  940. (setq result
  941. (concat result
  942. (if didfirst indstr "")
  943. (substring line 0 pos)
  944. "\n"))
  945. (setq didfirst t)
  946. (setq line (substring line (1+ pos)))
  947. (setq len (length line)))
  948. (setq result (concat result line))
  949. (setq len 0)))
  950. (concat result indstr line)))
  951. (defun org-export-generic-push-links (link-buffer)
  952. "Push out links in the buffer."
  953. (when link-buffer
  954. ;; We still have links to push out.
  955. (insert "\n")
  956. (let ((ind ""))
  957. (save-match-data
  958. (if (save-excursion
  959. (re-search-backward
  960. "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t))
  961. (setq ind (or (match-string 2)
  962. (make-string (length (match-string 3)) ?\ )))))
  963. (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
  964. link-buffer))
  965. (insert "\n")))
  966. (defun org-generic-level-start (level old-level title umax export-plist
  967. &optional lines)
  968. "Insert a new level in a generic export."
  969. (let ((n (- level umax 1))
  970. (ind 0)
  971. (diff (- level old-level)) (counter 0)
  972. (secnums (plist-get export-plist :body-header-section-numbers))
  973. (secnumformat
  974. (plist-get export-plist :body-header-section-number-format))
  975. char tagstring)
  976. (unless org-export-with-tags
  977. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  978. (setq title (replace-match "" t t title))))
  979. (cond
  980. ;; going deeper
  981. ((> level old-level)
  982. (while (< (+ old-level counter) (1- level))
  983. (insert
  984. (org-export-generic-format export-plist :body-section-prefix 0
  985. (+ old-level counter)))
  986. (setq counter (1+ counter))
  987. ))
  988. ;; going up
  989. ((< level old-level)
  990. (while (> (- old-level counter) (1- level))
  991. (insert
  992. (org-export-generic-format export-plist :body-section-suffix 0
  993. (- old-level counter)))
  994. (setq counter (1+ counter))
  995. ))
  996. ;; same level
  997. ((= level old-level)
  998. (insert
  999. (org-export-generic-format export-plist :body-section-suffix 0 level))
  1000. )
  1001. )
  1002. (insert
  1003. (org-export-generic-format export-plist :body-section-prefix 0 level))
  1004. (if (and org-export-with-section-numbers
  1005. secnums
  1006. (or (not (numberp secnums))
  1007. (< level secnums)))
  1008. (setq title
  1009. (concat (format (or secnumformat "%s ")
  1010. (org-section-number level)) title)))
  1011. ;; handle tags and formatting
  1012. (if (string-match
  1013. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") title)
  1014. (progn
  1015. (if (plist-get export-plist :body-tags-export)
  1016. (setq tagstring (org-export-generic-header (match-string 1 title)
  1017. export-plist
  1018. :body-tags-prefix
  1019. :body-tags-format
  1020. :body-tags-suffix)))
  1021. (string-match (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$") title)
  1022. (setq title (replace-match "" t t title)))
  1023. (setq tagstring (plist-get export-plist :body-tags-none-string)))
  1024. (insert
  1025. (org-export-generic-header title export-plist
  1026. :body-section-header-prefix
  1027. :body-section-header-format
  1028. :body-section-header-suffix
  1029. level))
  1030. (if tagstring
  1031. (insert tagstring))
  1032. (setq org-generic-current-indentation '(0 . 0))))
  1033. (defun org-insert-centered (s &optional underline)
  1034. "Insert the string S centered and underline it with character UNDERLINE."
  1035. (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
  1036. (insert (make-string ind ?\ ) s "\n")
  1037. (if underline
  1038. (insert (make-string ind ?\ )
  1039. (make-string (string-width s) underline)
  1040. "\n"))))
  1041. (defvar org-table-colgroup-info nil)
  1042. (defun org-format-table-generic (lines)
  1043. "Format a table for ascii export."
  1044. (if (stringp lines)
  1045. (setq lines (org-split-string lines "\n")))
  1046. (if (not (string-match "^[ \t]*|" (car lines)))
  1047. ;; Table made by table.el - test for spanning
  1048. lines
  1049. ;; A normal org table
  1050. ;; Get rid of hlines at beginning and end
  1051. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1052. (setq lines (nreverse lines))
  1053. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1054. (setq lines (nreverse lines))
  1055. (when org-export-table-remove-special-lines
  1056. ;; Check if the table has a marking column. If yes remove the
  1057. ;; column and the special lines
  1058. (setq lines (org-table-clean-before-export lines)))
  1059. ;; Get rid of the vertical lines except for grouping
  1060. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  1061. rtn line vl1 start)
  1062. (while (setq line (pop lines))
  1063. (if (string-match org-table-hline-regexp line)
  1064. (and (string-match "|\\(.*\\)|" line)
  1065. (setq line (replace-match " \\1" t nil line)))
  1066. (setq start 0 vl1 vl)
  1067. (while (string-match "|" line start)
  1068. (setq start (match-end 0))
  1069. (or (pop vl1) (setq line (replace-match " " t t line)))))
  1070. (push line rtn))
  1071. (nreverse rtn))))
  1072. (defun org-colgroup-info-to-vline-list (info)
  1073. (let (vl new last)
  1074. (while info
  1075. (setq last new new (pop info))
  1076. (if (or (memq last '(:end :startend))
  1077. (memq new '(:start :startend)))
  1078. (push t vl)
  1079. (push nil vl)))
  1080. (setq vl (nreverse vl))
  1081. (and vl (setcar vl nil))
  1082. vl))
  1083. (provide 'org-generic)
  1084. (provide 'org-export-generic)
  1085. ;;; org-export-generic.el ends here