org-export-generic.el 40 KB

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