org-export-generic.el 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. ;;; helper functions for org-set-generic-type
  361. (defvar org-export-generic-keywords nil)
  362. (defmacro* def-org-export-generic-keyword (keyword
  363. &key documentation
  364. type)
  365. "Define KEYWORD as a legitimate element for inclusion in
  366. the body of an org-set-generic-type definition."
  367. `(progn
  368. (pushnew ,keyword org-export-generic-keywords)
  369. ;; TODO: push the documentation and type information
  370. ;; somewhere where it will do us some good.
  371. ))
  372. (def-org-export-generic-keyword :body-newline-paragraph
  373. :documentation "Bound either to NIL or to a pattern to be
  374. inserted in the output for every blank line in the input.
  375. The intention is to handle formats where text is flowed, and
  376. newlines are interpreted as significant \(e.g., as indicating
  377. preformatted text\). A common non-nil value for this keyword
  378. is \"\\n\". Should typically be combined with a value for
  379. :body-line-format that does NOT end with a newline."
  380. :type string))
  381. (defun org-export-generic-remember-section (type suffix &optional prefix)
  382. (setq org-export-generic-section-type type)
  383. (setq org-export-generic-section-suffix suffix)
  384. (if prefix
  385. (insert prefix))
  386. )
  387. (defun org-export-generic-check-section (type &optional prefix suffix)
  388. "checks to see if type is already in use, or we're switching parts
  389. If we're switching, then insert a potentially previously remembered
  390. suffix, and insert the current prefix immediately and then save the
  391. suffix a later change time."
  392. (when (not (equal type org-export-generic-section-type))
  393. (if org-export-generic-section-suffix
  394. (insert org-export-generic-section-suffix))
  395. (setq org-export-generic-section-type type)
  396. (setq org-export-generic-section-suffix suffix)
  397. (if prefix
  398. (insert prefix))))
  399. ;;;###autoload
  400. (defun org-export-generic (arg)
  401. "Export the outline as generic output.
  402. If there is an active region, export only the region.
  403. The prefix ARG specifies how many levels of the outline should become
  404. underlined headlines. The default is 3."
  405. (interactive "P")
  406. (setq-default org-todo-line-regexp org-todo-line-regexp)
  407. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  408. (org-infile-export-plist)))
  409. (region-p (org-region-active-p))
  410. (rbeg (and region-p (region-beginning)))
  411. (rend (and region-p (region-end)))
  412. (subtree-p
  413. (when region-p
  414. (save-excursion
  415. (goto-char rbeg)
  416. (and (org-at-heading-p)
  417. (>= (org-end-of-subtree t t) rend)))))
  418. (level-offset (if subtree-p
  419. (save-excursion
  420. (goto-char rbeg)
  421. (+ (funcall outline-level)
  422. (if org-odd-levels-only 1 0)))
  423. 0))
  424. (opt-plist (setq org-export-opt-plist
  425. (if subtree-p
  426. (org-export-add-subtree-options opt-plist rbeg)
  427. opt-plist)))
  428. helpstart
  429. (bogus (mapc (lambda (x)
  430. (setq helpstart
  431. (concat helpstart "\["
  432. (char-to-string
  433. (plist-get (cdr x) :key-binding))
  434. "] " (car x) "\n")))
  435. org-generic-alist))
  436. (help (concat helpstart "
  437. \[ ] the current setting of the org-generic-export-type variable
  438. "))
  439. (cmds
  440. (append
  441. (mapcar (lambda (x)
  442. (list
  443. (plist-get (cdr x) :key-binding)
  444. (car x)))
  445. org-generic-alist)
  446. (list (list ? "default"))))
  447. r1 r2 ass
  448. ;; read in the type to use
  449. (export-plist
  450. (progn
  451. (save-excursion
  452. (save-window-excursion
  453. (delete-other-windows)
  454. (with-output-to-temp-buffer "*Org Export/Generic Styles Help*"
  455. (princ help))
  456. (org-fit-window-to-buffer (get-buffer-window
  457. "*Org Export/Generic Styles Help*"))
  458. (message "Select command: ")
  459. (setq r1 (read-char-exclusive))))
  460. (setq r2 (if (< r1 27) (+ r1 96) r1))
  461. (unless (setq ass (cadr (assq r2 cmds)))
  462. (error "No command associated with key %c" r1))
  463. (cdr (assoc
  464. (if (equal ass "default") org-generic-export-type ass)
  465. org-generic-alist))))
  466. (custom-times org-display-custom-times)
  467. (org-generic-current-indentation '(0 . 0))
  468. (level 0) (old-level 0) line txt lastwastext
  469. (umax nil)
  470. (umax-toc nil)
  471. (case-fold-search nil)
  472. (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  473. (filesuffix (or (plist-get export-plist :file-suffix) ".foo"))
  474. (filename (concat (file-name-as-directory
  475. (org-export-directory :ascii opt-plist))
  476. (file-name-sans-extension
  477. (or (and subtree-p
  478. (org-entry-get (region-beginning)
  479. "EXPORT_FILE_NAME" t))
  480. (file-name-nondirectory bfname)))
  481. filesuffix))
  482. (filename (if (equal (file-truename filename)
  483. (file-truename bfname))
  484. (concat filename filesuffix)
  485. filename))
  486. (buffer (find-file-noselect filename))
  487. (org-levels-open (make-vector org-level-max nil))
  488. (odd org-odd-levels-only)
  489. (date (plist-get opt-plist :date))
  490. (author (plist-get opt-plist :author))
  491. (title (or (and subtree-p (org-export-get-title-from-subtree))
  492. (plist-get opt-plist :title)
  493. (and (not
  494. (plist-get opt-plist :skip-before-1st-heading))
  495. (org-export-grab-title-from-buffer))
  496. (file-name-sans-extension
  497. (file-name-nondirectory bfname))))
  498. (email (plist-get opt-plist :email))
  499. (language (plist-get opt-plist :language))
  500. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  501. ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
  502. (todo nil)
  503. (lang-words nil)
  504. (region
  505. (buffer-substring
  506. (if (org-region-active-p) (region-beginning) (point-min))
  507. (if (org-region-active-p) (region-end) (point-max))))
  508. (lines (org-split-string
  509. (org-export-preprocess-string
  510. region
  511. :for-ascii t
  512. :skip-before-1st-heading
  513. (plist-get opt-plist :skip-before-1st-heading)
  514. :drawers (plist-get export-plist :drawers-export)
  515. :tags (plist-get export-plist :tags-export)
  516. :priority (plist-get export-plist :priority-export)
  517. :footnotes (plist-get export-plist :footnotes-export)
  518. :timestamps (plist-get export-plist :timestamps-export)
  519. :todo-keywords (plist-get export-plist :todo-keywords-export)
  520. :verbatim-multiline t
  521. :select-tags (plist-get export-plist :select-tags-export)
  522. :exclude-tags (plist-get export-plist :exclude-tags-export)
  523. :archived-trees
  524. (plist-get export-plist :archived-trees-export)
  525. :add-text (plist-get opt-plist :text))
  526. "\n"))
  527. ;; export-generic plist variables
  528. (withtags (plist-get export-plist :tags-export))
  529. (tagsintoc (plist-get export-plist :toc-tags-export))
  530. (tocnotagsstr (or (plist-get export-plist :toc-tags-none-string) ""))
  531. (tocdepth (plist-get export-plist :toc-indent-depth))
  532. (tocindentchar (plist-get export-plist :toc-indent-char))
  533. (tocsecnums (plist-get export-plist :toc-section-numbers))
  534. (tocsecnumform (plist-get export-plist :toc-section-number-format))
  535. (tocformat (plist-get export-plist :toc-format))
  536. (tocformtodo (plist-get export-plist :toc-format-with-todo))
  537. (tocprefix (plist-get export-plist :toc-prefix))
  538. (tocsuffix (plist-get export-plist :toc-suffix))
  539. (bodyfixedpre (plist-get export-plist :body-line-fixed-prefix))
  540. (bodyfixedsuf (plist-get export-plist :body-line-fixed-suffix))
  541. (bodyfixedform (or (plist-get export-plist :body-line-fixed-format)
  542. "%s"))
  543. (listprefix (plist-get export-plist :body-list-prefix))
  544. (listsuffix (plist-get export-plist :body-list-suffix))
  545. (listformat (or (plist-get export-plist :body-list-format) "%s\n"))
  546. (numlistleavenum
  547. (plist-get export-plist :body-number-list-leave-number))
  548. (numlistprefix (plist-get export-plist :body-number-list-prefix))
  549. (numlistsuffix (plist-get export-plist :body-number-list-suffix))
  550. (numlistformat
  551. (or (plist-get export-plist :body-number-list-format) "%s\n"))
  552. (listchecktodo
  553. (or (plist-get export-plist :body-list-checkbox-todo) "\\1"))
  554. (listcheckdone
  555. (or (plist-get export-plist :body-list-checkbox-done) "\\1"))
  556. (listcheckhalf
  557. (or (plist-get export-plist :body-list-checkbox-half) "\\1"))
  558. (listchecktodoend
  559. (or (plist-get export-plist :body-list-checkbox-todo-end) ""))
  560. (listcheckdoneend
  561. (or (plist-get export-plist :body-list-checkbox-done-end) ""))
  562. (listcheckhalfend
  563. (or (plist-get export-plist :body-list-checkbox-half-end) ""))
  564. (bodynewline-paragraph (plist-get export-plist :body-newline-paragraph))
  565. (bodytextpre (plist-get export-plist :body-text-prefix))
  566. (bodytextsuf (plist-get export-plist :body-text-suffix))
  567. (bodylinewrap (plist-get export-plist :body-line-wrap))
  568. (bodylineform (or (plist-get export-plist :body-line-format) "%s"))
  569. (blockquotestart (or (plist-get export-plist :blockquote-start) "\n\n\t"))
  570. (blockquoteend (or (plist-get export-plist :blockquote-end) "\n\n"))
  571. thetoc toctags have-headings first-heading-pos
  572. table-open table-buffer link-buffer link desc desc0 rpl wrap)
  573. (let ((inhibit-read-only t))
  574. (org-unmodified
  575. (remove-text-properties (point-min) (point-max)
  576. '(:org-license-to-kill t))))
  577. (setq org-min-level (org-get-min-level lines level-offset))
  578. (setq org-last-level org-min-level)
  579. (org-init-section-numbers)
  580. (find-file-noselect filename)
  581. (setq lang-words (or (assoc language org-export-language-setup)
  582. (assoc "en" org-export-language-setup)))
  583. (switch-to-buffer-other-window buffer)
  584. (erase-buffer)
  585. (fundamental-mode)
  586. ;; create local variables for all options, to make sure all called
  587. ;; functions get the correct information
  588. (mapc (lambda (x)
  589. (set (make-local-variable (nth 2 x))
  590. (plist-get opt-plist (car x))))
  591. org-export-plist-vars)
  592. (org-set-local 'org-odd-levels-only odd)
  593. (setq umax (if arg (prefix-numeric-value arg)
  594. org-export-headline-levels))
  595. (setq umax-toc umax)
  596. ;; File header
  597. (if title
  598. (insert
  599. (org-export-generic-header title export-plist
  600. :title-prefix
  601. :title-format
  602. :title-suffix)))
  603. (if (and (or author email)
  604. (plist-get export-plist :author-export))
  605. (insert (concat (nth 1 lang-words) ": " (or author "")
  606. (if email (concat " <" email ">") "")
  607. "\n")))
  608. (cond
  609. ((and date (string-match "%" date))
  610. (setq date (format-time-string date)))
  611. (date)
  612. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  613. (if (and date (plist-get export-plist :date-export))
  614. (insert
  615. (org-export-generic-header date export-plist
  616. :date-prefix
  617. :date-format
  618. :date-suffix)))
  619. ;; export the table of contents first
  620. (if (plist-get export-plist :toc-export)
  621. (progn
  622. (push
  623. (org-export-generic-header (nth 3 lang-words) export-plist
  624. :toc-header-prefix
  625. :toc-header-format
  626. :toc-header-suffix)
  627. thetoc)
  628. (if tocprefix
  629. (push tocprefix thetoc))
  630. (mapc '(lambda (line)
  631. (if (string-match org-todo-line-regexp line)
  632. ;; This is a headline
  633. (progn
  634. (setq have-headings t)
  635. (setq level (- (match-end 1) (match-beginning 1)
  636. level-offset)
  637. level (org-tr-level level)
  638. txt (match-string 3 line)
  639. todo
  640. (or (and org-export-mark-todo-in-toc
  641. (match-beginning 2)
  642. (not (member (match-string 2 line)
  643. org-done-keywords)))
  644. ; TODO, not DONE
  645. (and org-export-mark-todo-in-toc
  646. (= level umax-toc)
  647. (org-search-todo-below
  648. line lines level))))
  649. (setq txt (org-html-expand-for-generic txt))
  650. (while (string-match org-bracket-link-regexp txt)
  651. (setq txt
  652. (replace-match
  653. (match-string (if (match-end 2) 3 1) txt)
  654. t t txt)))
  655. (if (and (not tagsintoc)
  656. (string-match
  657. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  658. txt))
  659. (setq txt (replace-match "" t t txt))
  660. ; include tags but formated
  661. (if (string-match
  662. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$")
  663. txt)
  664. (progn
  665. (setq
  666. toctags
  667. (org-export-generic-header
  668. (match-string 1 txt)
  669. export-plist :toc-tags-prefix
  670. :toc-tags-format :toc-tags-suffix))
  671. (string-match
  672. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  673. txt)
  674. (setq txt (replace-match "" t t txt)))
  675. (setq toctags tocnotagsstr)))
  676. (if (string-match quote-re0 txt)
  677. (setq txt (replace-match "" t t txt)))
  678. (if (<= level umax-toc)
  679. (progn
  680. (push
  681. (concat
  682. (make-string
  683. (* (max 0 (- level org-min-level)) tocdepth)
  684. tocindentchar)
  685. (if tocsecnums
  686. (format tocsecnumform
  687. (org-section-number level))
  688. "")
  689. (format
  690. (if todo tocformtodo tocformat)
  691. txt)
  692. toctags)
  693. thetoc)
  694. (setq org-last-level level))
  695. ))))
  696. lines)
  697. (if tocsuffix
  698. (push tocsuffix thetoc))
  699. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  700. (org-init-section-numbers)
  701. (org-export-generic-check-section "top")
  702. (while (setq line (pop lines))
  703. (when (and link-buffer (string-match "^\\*+ " line))
  704. (org-export-generic-push-links (nreverse link-buffer))
  705. (setq link-buffer nil))
  706. (setq wrap nil)
  707. ;; Remove the quoted HTML tags.
  708. ;; XXX
  709. (setq line (org-html-expand-for-generic line))
  710. ;; Replace links with the description when possible
  711. ;; XXX
  712. (while (string-match org-bracket-link-regexp line)
  713. (setq link (match-string 1 line)
  714. desc0 (match-string 3 line)
  715. desc (or desc0 (match-string 1 line)))
  716. (if (and (> (length link) 8)
  717. (equal (substring link 0 8) "coderef:"))
  718. (setq line (replace-match
  719. (format (org-export-get-coderef-format (substring link 8) desc)
  720. (cdr (assoc
  721. (substring link 8)
  722. org-export-code-refs)))
  723. t t line))
  724. (setq rpl (concat "["
  725. (or (match-string 3 line) (match-string 1 line))
  726. "]"))
  727. (when (and desc0 (not (equal desc0 link)))
  728. (if org-export-generic-links-to-notes
  729. (push (cons desc0 link) link-buffer)
  730. (setq rpl (concat rpl " (" link ")")
  731. wrap (+ (length line) (- (length (match-string 0) line))
  732. (length desc)))))
  733. (setq line (replace-match rpl t t line))))
  734. (when custom-times
  735. (setq line (org-translate-time line)))
  736. (cond
  737. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  738. ;;
  739. ;; a Headline
  740. ;;
  741. (org-export-generic-check-section "headline")
  742. (setq first-heading-pos (or first-heading-pos (point)))
  743. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  744. level-offset))
  745. txt (match-string 2 line))
  746. (org-generic-level-start level old-level txt umax export-plist lines)
  747. (setq old-level level))
  748. ((and org-export-with-tables
  749. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  750. ;;
  751. ;; a Table
  752. ;;
  753. (org-export-generic-check-section "table")
  754. (if (not table-open)
  755. ;; New table starts
  756. (setq table-open t table-buffer nil))
  757. ;; Accumulate table lines
  758. (setq table-buffer (cons line table-buffer))
  759. (when (or (not lines)
  760. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  761. (car lines))))
  762. (setq table-open nil
  763. table-buffer (nreverse table-buffer))
  764. (insert (mapconcat
  765. (lambda (x)
  766. (org-fix-indentation x org-generic-current-indentation))
  767. (org-format-table-generic table-buffer)
  768. "\n") "\n")))
  769. ((string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line)
  770. ;;
  771. ;; pre-formatted text
  772. ;;
  773. (setq line (replace-match "\\1" nil nil line))
  774. (org-export-generic-check-section "preformat" bodyfixedpre bodyfixedsuf)
  775. (insert (format bodyfixedform line)))
  776. ((or (string-match "^\\([ \t]*\\)\\([\-\+][ \t]*\\)" line)
  777. ;; if the bullet list item is an asterisk, the leading space is /mandatory/
  778. ;; [2010/02/02:rpg]
  779. (string-match "^\\([ \t]+\\)\\(\\*[ \t]*\\)" line))
  780. ;;
  781. ;; plain list item
  782. ;;
  783. ;; TODO: nested lists
  784. ;;
  785. ;; I believe this gets rid of leading whitespace.
  786. (setq line (replace-match "" nil nil line))
  787. ;; won't this insert the suffix /before/ the last line of the list?
  788. ;; also isn't it spoofed by bulleted lists that have a line skip between the list items
  789. ;; unless 'org-empty-line-terminates-plain-lists' is true?
  790. (org-export-generic-check-section "liststart" listprefix listsuffix)
  791. ;; deal with checkboxes
  792. (cond
  793. ((string-match "^\\(\\[ \\]\\)[ \t]*" line)
  794. (setq line (concat (replace-match listchecktodo nil nil line)
  795. listchecktodoend)))
  796. ((string-match "^\\(\\[X\\]\\)[ \t]*" line)
  797. (setq line (concat (replace-match listcheckdone nil nil line)
  798. listcheckdoneend)))
  799. ((string-match "^\\(\\[/\\]\\)[ \t]*" line)
  800. (setq line (concat (replace-match listcheckhalf nil nil line)
  801. listcheckhalfend)))
  802. )
  803. (insert (format listformat line)))
  804. ((string-match "^\\([ \t]+\\)\\([0-9]+\\.[ \t]*\\)" line)
  805. ;;
  806. ;; numbered list item
  807. ;;
  808. ;; TODO: nested lists
  809. ;;
  810. (setq line (replace-match (if numlistleavenum "\\2" "") nil nil line))
  811. (org-export-generic-check-section "numliststart"
  812. numlistprefix numlistsuffix)
  813. ;; deal with checkboxes
  814. ;; TODO: whoops; leaving the numbers is a problem for ^ matching
  815. (cond
  816. ((string-match "\\(\\[ \\]\\)[ \t]*" line)
  817. (setq line (concat (replace-match listchecktodo nil nil line)
  818. listchecktodoend)))
  819. ((string-match "\\(\\[X\\]\\)[ \t]*" line)
  820. (setq line (concat (replace-match listcheckdone nil nil line)
  821. listcheckdoneend)))
  822. ((string-match "\\(\\[/\\]\\)[ \t]*" line)
  823. (setq line (concat (replace-match listcheckhalf nil nil line)
  824. listcheckhalfend)))
  825. )
  826. (insert (format numlistformat line)))
  827. ((equal line "ORG-BLOCKQUOTE-START")
  828. (setq line blockquotestart))
  829. ((equal line "ORG-BLOCKQUOTE-END")
  830. (setq line blockquoteend))
  831. ((string-match "^\\s-*$" line)
  832. ;; blank line
  833. (if bodynewline-paragraph
  834. (insert bodynewline-paragraph)))
  835. (t
  836. ;;
  837. ;; body
  838. ;;
  839. (org-export-generic-check-section "body" bodytextpre bodytextsuf)
  840. ;; XXX: properties? list?
  841. (if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)" line)
  842. (setq line (replace-match "\\1\\3:" t nil line)))
  843. (setq line (org-fix-indentation line org-generic-current-indentation))
  844. ;; Remove forced line breaks
  845. (if (string-match "\\\\\\\\[ \t]*$" line)
  846. (setq line (replace-match "" t t line)))
  847. (if bodylinewrap
  848. ;; XXX: was dependent on wrap var which was calculated by???
  849. (if (> (length line) bodylinewrap)
  850. (setq line
  851. (org-export-generic-wrap line bodylinewrap))
  852. (setq line line)))
  853. (insert (format bodylineform line)))))
  854. ;; if we're at a level > 0; insert the closing body level stuff
  855. (let ((counter 0))
  856. (while (> (- level counter) 0)
  857. (insert
  858. (org-export-generic-format export-plist :body-section-suffix 0
  859. (- level counter)))
  860. (setq counter (1+ counter))))
  861. (org-export-generic-check-section "bottom")
  862. (org-export-generic-push-links (nreverse link-buffer))
  863. (normal-mode)
  864. ;; insert the table of contents
  865. (when thetoc
  866. (goto-char (point-min))
  867. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  868. (progn
  869. (goto-char (match-beginning 0))
  870. (replace-match ""))
  871. (goto-char first-heading-pos))
  872. (mapc 'insert thetoc)
  873. (or (looking-at "[ \t]*\n[ \t]*\n")
  874. (insert "\n\n")))
  875. ;; Convert whitespace place holders
  876. (goto-char (point-min))
  877. (let (beg end)
  878. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  879. (setq end (next-single-property-change beg 'org-whitespace))
  880. (goto-char beg)
  881. (delete-region beg end)
  882. (insert (make-string (- end beg) ?\ ))))
  883. (save-buffer)
  884. ;; remove display and invisible chars
  885. (let (beg end)
  886. (goto-char (point-min))
  887. (while (setq beg (next-single-property-change (point) 'display))
  888. (setq end (next-single-property-change beg 'display))
  889. (delete-region beg end)
  890. (goto-char beg)
  891. (insert "=>"))
  892. (goto-char (point-min))
  893. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  894. (setq end (next-single-property-change beg 'org-cwidth))
  895. (delete-region beg end)
  896. (goto-char beg)))
  897. (goto-char (point-min))))
  898. (defun org-export-generic-format (export-plist prop &optional len n reverse)
  899. "converts a property specification to a string given types of properties
  900. The EXPORT-PLIST should be defined as the lookup plist.
  901. The PROP should be the property name to search for in it.
  902. LEN is set to the length of multi-characters strings to generate (or 0)
  903. N is the tree depth
  904. REVERSE means to reverse the list if the plist match is a list
  905. "
  906. (let* ((prefixtype (plist-get export-plist prop))
  907. subtype)
  908. (cond
  909. ((null prefixtype) "")
  910. ((and len (char-or-string-p prefixtype) (not (stringp prefixtype)))
  911. ;; sequence of chars
  912. (concat (make-string len prefixtype) "\n"))
  913. ((stringp prefixtype)
  914. prefixtype)
  915. ((and n (listp prefixtype))
  916. (if reverse
  917. (setq prefixtype (reverse prefixtype)))
  918. (setq subtype (if (> n (length prefixtype))
  919. (car (last prefixtype))
  920. (nth (1- n) prefixtype)))
  921. (if (stringp subtype)
  922. subtype
  923. (concat (make-string len subtype) "\n")))
  924. (t ""))
  925. ))
  926. (defun org-export-generic-header (header export-plist
  927. prefixprop formatprop postfixprop
  928. &optional n reverse)
  929. "convert a header to an output string given formatting property names"
  930. (let* ((formatspec (plist-get export-plist formatprop))
  931. (len (length header)))
  932. (concat
  933. (org-export-generic-format export-plist prefixprop len n reverse)
  934. (format (or formatspec "%s") header)
  935. (org-export-generic-format export-plist postfixprop len n reverse))
  936. ))
  937. (defun org-export-generic-preprocess (parameters)
  938. "Do extra work for ASCII export"
  939. ;; Put quotes around verbatim text
  940. (goto-char (point-min))
  941. (while (re-search-forward org-verbatim-re nil t)
  942. (goto-char (match-end 2))
  943. (backward-delete-char 1) (insert "'")
  944. (goto-char (match-beginning 2))
  945. (delete-char 1) (insert "`")
  946. (goto-char (match-end 2)))
  947. ;; Remove target markers
  948. (goto-char (point-min))
  949. (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
  950. (replace-match "\\1\\2")))
  951. (defun org-html-expand-for-generic (line)
  952. "Handle quoted HTML for ASCII export."
  953. (if org-export-html-expand
  954. (while (string-match "@<[^<>\n]*>" line)
  955. ;; We just remove the tags for now.
  956. (setq line (replace-match "" nil nil line))))
  957. line)
  958. (defun org-export-generic-wrap (line where)
  959. "Wrap LINE at or before WHERE."
  960. (let* ((ind (org-get-indentation line))
  961. (indstr (make-string ind ?\ ))
  962. (len (length line))
  963. (result "")
  964. pos didfirst)
  965. (while (> len where)
  966. (catch 'found
  967. (loop for i from where downto (/ where 2) do
  968. (and (equal (aref line i) ?\ )
  969. (setq pos i)
  970. (throw 'found t))))
  971. (if pos
  972. (progn
  973. (setq result
  974. (concat result
  975. (if didfirst indstr "")
  976. (substring line 0 pos)
  977. "\n"))
  978. (setq didfirst t)
  979. (setq line (substring line (1+ pos)))
  980. (setq len (length line)))
  981. (setq result (concat result line))
  982. (setq len 0)))
  983. (concat result indstr line)))
  984. (defun org-export-generic-push-links (link-buffer)
  985. "Push out links in the buffer."
  986. (when link-buffer
  987. ;; We still have links to push out.
  988. (insert "\n")
  989. (let ((ind ""))
  990. (save-match-data
  991. (if (save-excursion
  992. (re-search-backward
  993. "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t))
  994. (setq ind (or (match-string 2)
  995. (make-string (length (match-string 3)) ?\ )))))
  996. (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
  997. link-buffer))
  998. (insert "\n")))
  999. (defun org-generic-level-start (level old-level title umax export-plist
  1000. &optional lines)
  1001. "Insert a new level in a generic export."
  1002. (let ((n (- level umax 1))
  1003. (ind 0)
  1004. (diff (- level old-level)) (counter 0)
  1005. (secnums (plist-get export-plist :body-header-section-numbers))
  1006. (secnumformat
  1007. (plist-get export-plist :body-header-section-number-format))
  1008. char tagstring)
  1009. (unless org-export-with-tags
  1010. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  1011. (setq title (replace-match "" t t title))))
  1012. (cond
  1013. ;; going deeper
  1014. ((> level old-level)
  1015. (while (< (+ old-level counter) (1- level))
  1016. (insert
  1017. (org-export-generic-format export-plist :body-section-prefix 0
  1018. (+ old-level counter)))
  1019. (setq counter (1+ counter))
  1020. ))
  1021. ;; going up
  1022. ((< level old-level)
  1023. (while (> (- old-level counter) (1- level))
  1024. (insert
  1025. (org-export-generic-format export-plist :body-section-suffix 0
  1026. (- old-level counter)))
  1027. (setq counter (1+ counter))
  1028. ))
  1029. ;; same level
  1030. ((= level old-level)
  1031. (insert
  1032. (org-export-generic-format export-plist :body-section-suffix 0 level))
  1033. )
  1034. )
  1035. (insert
  1036. (org-export-generic-format export-plist :body-section-prefix 0 level))
  1037. (if (and org-export-with-section-numbers
  1038. secnums
  1039. (or (not (numberp secnums))
  1040. (< level secnums)))
  1041. (setq title
  1042. (concat (format (or secnumformat "%s ")
  1043. (org-section-number level)) title)))
  1044. ;; handle tags and formatting
  1045. (if (string-match
  1046. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") title)
  1047. (progn
  1048. (if (plist-get export-plist :body-tags-export)
  1049. (setq tagstring (org-export-generic-header (match-string 1 title)
  1050. export-plist
  1051. :body-tags-prefix
  1052. :body-tags-format
  1053. :body-tags-suffix)))
  1054. (string-match (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$") title)
  1055. (setq title (replace-match "" t t title)))
  1056. (setq tagstring (plist-get export-plist :body-tags-none-string)))
  1057. (insert
  1058. (org-export-generic-header title export-plist
  1059. :body-section-header-prefix
  1060. :body-section-header-format
  1061. :body-section-header-suffix
  1062. level))
  1063. (if tagstring
  1064. (insert tagstring))
  1065. (setq org-generic-current-indentation '(0 . 0))))
  1066. (defun org-insert-centered (s &optional underline)
  1067. "Insert the string S centered and underline it with character UNDERLINE."
  1068. (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
  1069. (insert (make-string ind ?\ ) s "\n")
  1070. (if underline
  1071. (insert (make-string ind ?\ )
  1072. (make-string (string-width s) underline)
  1073. "\n"))))
  1074. (defvar org-table-colgroup-info nil)
  1075. (defun org-format-table-generic (lines)
  1076. "Format a table for ascii export."
  1077. (if (stringp lines)
  1078. (setq lines (org-split-string lines "\n")))
  1079. (if (not (string-match "^[ \t]*|" (car lines)))
  1080. ;; Table made by table.el - test for spanning
  1081. lines
  1082. ;; A normal org table
  1083. ;; Get rid of hlines at beginning and end
  1084. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1085. (setq lines (nreverse lines))
  1086. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1087. (setq lines (nreverse lines))
  1088. (when org-export-table-remove-special-lines
  1089. ;; Check if the table has a marking column. If yes remove the
  1090. ;; column and the special lines
  1091. (setq lines (org-table-clean-before-export lines)))
  1092. ;; Get rid of the vertical lines except for grouping
  1093. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  1094. rtn line vl1 start)
  1095. (while (setq line (pop lines))
  1096. (if (string-match org-table-hline-regexp line)
  1097. (and (string-match "|\\(.*\\)|" line)
  1098. (setq line (replace-match " \\1" t nil line)))
  1099. (setq start 0 vl1 vl)
  1100. (while (string-match "|" line start)
  1101. (setq start (match-end 0))
  1102. (or (pop vl1) (setq line (replace-match " " t t line)))))
  1103. (push line rtn))
  1104. (nreverse rtn))))
  1105. (defun org-colgroup-info-to-vline-list (info)
  1106. (let (vl new last)
  1107. (while info
  1108. (setq last new new (pop info))
  1109. (if (or (memq last '(:end :startend))
  1110. (memq new '(:start :startend)))
  1111. (push t vl)
  1112. (push nil vl)))
  1113. (setq vl (nreverse vl))
  1114. (and vl (setcar vl nil))
  1115. vl))
  1116. (provide 'org-generic)
  1117. (provide 'org-export-generic)
  1118. ;;; org-export-generic.el ends here