org-exp.el 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563
  1. ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 6.26c
  8. ;;
  9. ;; This file is 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. ;;; Commentary:
  24. (require 'org)
  25. (require 'org-agenda)
  26. (eval-and-compile
  27. (require 'cl))
  28. (declare-function org-export-latex-preprocess "org-latex" (parameters))
  29. (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
  30. (declare-function org-export-html-preprocess "org-html" (parameters))
  31. (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
  32. (declare-function org-agenda-skip "org-agenda" ())
  33. (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
  34. (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
  35. (defgroup org-export nil
  36. "Options for exporting org-listings."
  37. :tag "Org Export"
  38. :group 'org)
  39. (defgroup org-export-general nil
  40. "General options for exporting Org-mode files."
  41. :tag "Org Export General"
  42. :group 'org-export)
  43. ;; FIXME
  44. (defvar org-export-publishing-directory nil)
  45. (defcustom org-export-run-in-background nil
  46. "Non-nil means export and publishing commands will run in background.
  47. This works by starting up a separate Emacs process visiting the same file
  48. and doing the export from there.
  49. Not all export commands are affected by this - only the ones which
  50. actually write to a file, and that do not depend on the buffer state.
  51. If this option is nil, you can still get background export by calling
  52. `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
  53. If this option is t, the double prefix can be used to exceptionally
  54. force an export command into the current process."
  55. :group 'org-export-general
  56. :type 'boolean)
  57. (defcustom org-export-select-tags '("export")
  58. "Tags that select a tree for export.
  59. If any such tag is found in a buffer, all trees that do not carry one
  60. of these tags will be deleted before export.
  61. Inside trees that are selected like this, you can still deselect a
  62. subtree by tagging it with one of the `org-export-exclude-tags'."
  63. :group 'org-export-general
  64. :type '(repeat (string :tag "Tag")))
  65. (defcustom org-export-exclude-tags '("noexport")
  66. "Tags that exclude a tree from export.
  67. All trees carrying any of these tags will be excluded from export.
  68. This is without condition, so even subtrees inside that carry one of the
  69. `org-export-select-tags' will be removed."
  70. :group 'org-export-general
  71. :type '(repeat (string :tag "Tag")))
  72. ;; FIXME: rename, this is a general variable
  73. (defcustom org-export-html-expand t
  74. "Non-nil means, for HTML export, treat @<...> as HTML tag.
  75. When nil, these tags will be exported as plain text and therefore
  76. not be interpreted by a browser.
  77. This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
  78. :group 'org-export-html
  79. :group 'org-export-general
  80. :type 'boolean)
  81. (defcustom org-export-with-special-strings t
  82. "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
  83. When this option is turned on, these strings will be exported as:
  84. Org HTML LaTeX
  85. -----+----------+--------
  86. \\- &shy; \\-
  87. -- &ndash; --
  88. --- &mdash; ---
  89. ... &hellip; \ldots
  90. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
  91. :group 'org-export-translation
  92. :type 'boolean)
  93. (defcustom org-export-html-link-up ""
  94. "Where should the \"UP\" link of exported HTML pages lead?"
  95. :group 'org-export-html
  96. :group 'org-export-general
  97. :type '(string :tag "File or URL"))
  98. (defcustom org-export-html-link-home ""
  99. "Where should the \"HOME\" link of exported HTML pages lead?"
  100. :group 'org-export-html
  101. :group 'org-export-general
  102. :type '(string :tag "File or URL"))
  103. (defcustom org-export-language-setup
  104. '(("en" "Author" "Date" "Table of Contents" "Footnotes")
  105. ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
  106. ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
  107. ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
  108. ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
  109. ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
  110. ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
  111. ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
  112. ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
  113. ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
  114. ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
  115. ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
  116. ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
  117. ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
  118. ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
  119. ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
  120. ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
  121. ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
  122. "Terms used in export text, translated to different languages.
  123. Use the variable `org-export-default-language' to set the language,
  124. or use the +OPTION lines for a per-file setting."
  125. :group 'org-export-general
  126. :type '(repeat
  127. (list
  128. (string :tag "HTML language tag")
  129. (string :tag "Author")
  130. (string :tag "Date")
  131. (string :tag "Table of Contents")
  132. (string :tag "Footnotes"))))
  133. (defcustom org-export-default-language "en"
  134. "The default language of HTML export, as a string.
  135. This should have an association in `org-export-language-setup'."
  136. :group 'org-export-general
  137. :type 'string)
  138. (defvar org-export-page-description ""
  139. "The page description, for the XHTML meta tag.
  140. This is best set with the #+DESCRIPTION line in a file, it does not make
  141. sense to set this globally.")
  142. (defvar org-export-page-keywords ""
  143. "The page description, for the XHTML meta tag.
  144. This is best set with the #+KEYWORDS line in a file, it does not make
  145. sense to set this globally.")
  146. (defcustom org-export-skip-text-before-1st-heading nil
  147. "Non-nil means, skip all text before the first headline when exporting.
  148. When nil, that text is exported as well."
  149. :group 'org-export-general
  150. :type 'boolean)
  151. (defcustom org-export-headline-levels 3
  152. "The last level which is still exported as a headline.
  153. Inferior levels will produce itemize lists when exported.
  154. Note that a numeric prefix argument to an exporter function overrides
  155. this setting.
  156. This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
  157. :group 'org-export-general
  158. :type 'integer)
  159. (defcustom org-export-with-section-numbers t
  160. "Non-nil means, add section numbers to headlines when exporting.
  161. This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
  162. :group 'org-export-general
  163. :type 'boolean)
  164. (defcustom org-export-section-number-format '((("1" ".")) . "")
  165. "Format of section numbers for export.
  166. The variable has two components.
  167. 1. A list of lists, each indicating a counter type and a separator.
  168. The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
  169. It causes causes numeric, alphabetic, or roman counters, respectively.
  170. The separator is only used if another counter for a subsection is being
  171. added.
  172. If there are more numbered section levels than entries in this lists,
  173. then the last entry will be reused.
  174. 2. A terminator string that will be added after the entire
  175. section number."
  176. :group 'org-export-general
  177. :type '(cons
  178. (repeat
  179. (list
  180. (string :tag "Counter Type")
  181. (string :tag "Separator ")))
  182. (string :tag "Terminator")))
  183. (defcustom org-export-with-toc t
  184. "Non-nil means, create a table of contents in exported files.
  185. The TOC contains headlines with levels up to`org-export-headline-levels'.
  186. When an integer, include levels up to N in the toc, this may then be
  187. different from `org-export-headline-levels', but it will not be allowed
  188. to be larger than the number of headline levels.
  189. When nil, no table of contents is made.
  190. Headlines which contain any TODO items will be marked with \"(*)\" in
  191. ASCII export, and with red color in HTML output, if the option
  192. `org-export-mark-todo-in-toc' is set.
  193. In HTML output, the TOC will be clickable.
  194. This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
  195. or \"toc:3\"."
  196. :group 'org-export-general
  197. :type '(choice
  198. (const :tag "No Table of Contents" nil)
  199. (const :tag "Full Table of Contents" t)
  200. (integer :tag "TOC to level")))
  201. (defcustom org-export-mark-todo-in-toc nil
  202. "Non-nil means, mark TOC lines that contain any open TODO items."
  203. :group 'org-export-general
  204. :type 'boolean)
  205. (defcustom org-export-with-todo-keywords t
  206. "Non-nil means, include TODO keywords in export.
  207. When nil, remove all these keywords from the export."
  208. :group 'org-export-general
  209. :type 'boolean)
  210. (defcustom org-export-with-priority nil
  211. "Non-nil means, include priority cookies in export.
  212. When nil, remove priority cookies for export."
  213. :group 'org-export-general
  214. :type 'boolean)
  215. (defcustom org-export-preserve-breaks nil
  216. "Non-nil means, preserve all line breaks when exporting.
  217. Normally, in HTML output paragraphs will be reformatted. In ASCII
  218. export, line breaks will always be preserved, regardless of this variable.
  219. This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
  220. :group 'org-export-general
  221. :type 'boolean)
  222. (defcustom org-export-with-archived-trees 'headline
  223. "Whether subtrees with the ARCHIVE tag should be exported.
  224. This can have three different values
  225. nil Do not export, pretend this tree is not present
  226. t Do export the entire tree
  227. headline Only export the headline, but skip the tree below it."
  228. :group 'org-export-general
  229. :group 'org-archive
  230. :type '(choice
  231. (const :tag "not at all" nil)
  232. (const :tag "headline only" 'headline)
  233. (const :tag "entirely" t)))
  234. (defcustom org-export-author-info t
  235. "Non-nil means, insert author name and email into the exported file.
  236. This option can also be set with the +OPTIONS line,
  237. e.g. \"author-info:nil\"."
  238. :group 'org-export-general
  239. :type 'boolean)
  240. (defcustom org-export-creator-info t
  241. "Non-nil means, the postamble should contain a creator sentence.
  242. This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
  243. :group 'org-export-general
  244. :type 'boolean)
  245. (defcustom org-export-time-stamp-file t
  246. "Non-nil means, insert a time stamp into the exported file.
  247. The time stamp shows when the file was created.
  248. This option can also be set with the +OPTIONS line,
  249. e.g. \"timestamp:nil\"."
  250. :group 'org-export-general
  251. :type 'boolean)
  252. (defcustom org-export-with-timestamps t
  253. "If nil, do not export time stamps and associated keywords."
  254. :group 'org-export-general
  255. :type 'boolean)
  256. (defcustom org-export-remove-timestamps-from-toc t
  257. "If nil, remove timestamps from the table of contents entries."
  258. :group 'org-export-general
  259. :type 'boolean)
  260. (defcustom org-export-with-tags 'not-in-toc
  261. "If nil, do not export tags, just remove them from headlines.
  262. If this is the symbol `not-in-toc', tags will be removed from table of
  263. contents entries, but still be shown in the headlines of the document.
  264. This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
  265. :group 'org-export-general
  266. :type '(choice
  267. (const :tag "Off" nil)
  268. (const :tag "Not in TOC" not-in-toc)
  269. (const :tag "On" t)))
  270. (defcustom org-export-with-drawers nil
  271. "Non-nil means, export with drawers like the property drawer.
  272. When t, all drawers are exported. This may also be a list of
  273. drawer names to export."
  274. :group 'org-export-general
  275. :type '(choice
  276. (const :tag "All drawers" t)
  277. (const :tag "None" nil)
  278. (repeat :tag "Selected drawers"
  279. (string :tag "Drawer name"))))
  280. (defvar org-export-preprocess-hook nil
  281. "Hook for preprocessing an export buffer.
  282. Pretty much the first thing when exporting is running this hook.")
  283. (defvar org-export-preprocess-after-include-files-hook nil
  284. "Hook for preprocessing an export buffer.
  285. This is run after the contents of included files have been inserted.")
  286. (defvar org-export-preprocess-after-tree-selection-hook nil
  287. "Hook for preprocessing an export buffer.
  288. This is run after selection of trees to be exported has happened.
  289. This selection includes tags-based selection, as well as removal
  290. of commented and archived trees.")
  291. (defvar org-export-preprocess-before-backend-specifics-hook nil
  292. "Hook run before backend-specific functions are called during preprocessing.")
  293. (defvar org-export-preprocess-final-hook nil
  294. "Hook for preprocessing an export buffer.
  295. This is run as the last thing in the preprocessing buffer, just before
  296. returning the buffer string to the backend.")
  297. (defgroup org-export-translation nil
  298. "Options for translating special ascii sequences for the export backends."
  299. :tag "Org Export Translation"
  300. :group 'org-export)
  301. (defcustom org-export-with-emphasize t
  302. "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
  303. If the export target supports emphasizing text, the word will be
  304. typeset in bold, italic, or underlined, respectively. Works only for
  305. single words, but you can say: I *really* *mean* *this*.
  306. Not all export backends support this.
  307. This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
  308. :group 'org-export-translation
  309. :type 'boolean)
  310. (defcustom org-export-with-footnotes t
  311. "If nil, export [1] as a footnote marker.
  312. Lines starting with [1] will be formatted as footnotes.
  313. This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
  314. :group 'org-export-translation
  315. :type 'boolean)
  316. (defcustom org-export-with-sub-superscripts t
  317. "Non-nil means, interpret \"_\" and \"^\" for export.
  318. When this option is turned on, you can use TeX-like syntax for sub- and
  319. superscripts. Several characters after \"_\" or \"^\" will be
  320. considered as a single item - so grouping with {} is normally not
  321. needed. For example, the following things will be parsed as single
  322. sub- or superscripts.
  323. 10^24 or 10^tau several digits will be considered 1 item.
  324. 10^-12 or 10^-tau a leading sign with digits or a word
  325. x^2-y^3 will be read as x^2 - y^3, because items are
  326. terminated by almost any nonword/nondigit char.
  327. x_{i^2} or x^(2-i) braces or parenthesis do grouping.
  328. Still, ambiguity is possible - so when in doubt use {} to enclose the
  329. sub/superscript. If you set this variable to the symbol `{}',
  330. the braces are *required* in order to trigger interpretations as
  331. sub/superscript. This can be helpful in documents that need \"_\"
  332. frequently in plain text.
  333. Not all export backends support this, but HTML does.
  334. This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
  335. :group 'org-export-translation
  336. :type '(choice
  337. (const :tag "Always interpret" t)
  338. (const :tag "Only with braces" {})
  339. (const :tag "Never interpret" nil)))
  340. (defcustom org-export-with-TeX-macros t
  341. "Non-nil means, interpret simple TeX-like macros when exporting.
  342. For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
  343. Not only real TeX macros will work here, but the standard HTML entities
  344. for math can be used as macro names as well. For a list of supported
  345. names in HTML export, see the constant `org-html-entities'.
  346. Not all export backends support this.
  347. This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
  348. :group 'org-export-translation
  349. :group 'org-export-latex
  350. :type 'boolean)
  351. (defcustom org-export-with-LaTeX-fragments nil
  352. "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
  353. When set, the exporter will find LaTeX environments if the \\begin line is
  354. the first non-white thing on a line. It will also find the math delimiters
  355. like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
  356. display math.
  357. This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
  358. :group 'org-export-translation
  359. :group 'org-export-latex
  360. :type 'boolean)
  361. (defcustom org-export-with-fixed-width t
  362. "Non-nil means, lines starting with \":\" will be in fixed width font.
  363. This can be used to have pre-formatted text, fragments of code etc. For
  364. example:
  365. : ;; Some Lisp examples
  366. : (while (defc cnt)
  367. : (ding))
  368. will be looking just like this in also HTML. See also the QUOTE keyword.
  369. Not all export backends support this.
  370. This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
  371. :group 'org-export-translation
  372. :type 'boolean)
  373. (defcustom org-match-sexp-depth 3
  374. "Number of stacked braces for sub/superscript matching.
  375. This has to be set before loading org.el to be effective."
  376. :group 'org-export-translation
  377. :type 'integer)
  378. (defgroup org-export-tables nil
  379. "Options for exporting tables in Org-mode."
  380. :tag "Org Export Tables"
  381. :group 'org-export)
  382. (defcustom org-export-with-tables t
  383. "If non-nil, lines starting with \"|\" define a table.
  384. For example:
  385. | Name | Address | Birthday |
  386. |-------------+----------+-----------|
  387. | Arthur Dent | England | 29.2.2100 |
  388. Not all export backends support this.
  389. This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
  390. :group 'org-export-tables
  391. :type 'boolean)
  392. (defcustom org-export-highlight-first-table-line t
  393. "Non-nil means, highlight the first table line.
  394. In HTML export, this means use <th> instead of <td>.
  395. In tables created with table.el, this applies to the first table line.
  396. In Org-mode tables, all lines before the first horizontal separator
  397. line will be formatted with <th> tags."
  398. :group 'org-export-tables
  399. :type 'boolean)
  400. (defcustom org-export-table-remove-special-lines t
  401. "Remove special lines and marking characters in calculating tables.
  402. This removes the special marking character column from tables that are set
  403. up for spreadsheet calculations. It also removes the entire lines
  404. marked with `!', `_', or `^'. The lines with `$' are kept, because
  405. the values of constants may be useful to have."
  406. :group 'org-export-tables
  407. :type 'boolean)
  408. (defcustom org-export-prefer-native-exporter-for-tables nil
  409. "Non-nil means, always export tables created with table.el natively.
  410. Natively means, use the HTML code generator in table.el.
  411. When nil, Org-mode's own HTML generator is used when possible (i.e. if
  412. the table does not use row- or column-spanning). This has the
  413. advantage, that the automatic HTML conversions for math symbols and
  414. sub/superscripts can be applied. Org-mode's HTML generator is also
  415. much faster."
  416. :group 'org-export-tables
  417. :type 'boolean)
  418. (defgroup org-export-xml nil
  419. "Options specific for XML export of Org-mode files."
  420. :tag "Org Export XML"
  421. :group 'org-export)
  422. ;;;; Exporting
  423. ;;; Variables, constants, and parameter plists
  424. (defconst org-level-max 20)
  425. (defvar org-current-export-file nil) ; dynamically scoped parameter
  426. (defvar org-current-export-dir nil) ; dynamically scoped parameter
  427. (defvar org-export-opt-plist nil
  428. "Contains the current option plist.")
  429. (defvar org-last-level nil) ; dynamically scoped variable
  430. (defvar org-min-level nil) ; dynamically scoped variable
  431. (defvar org-levels-open nil) ; dynamically scoped parameter
  432. (defconst org-export-plist-vars
  433. '((:link-up nil org-export-html-link-up)
  434. (:link-home nil org-export-html-link-home)
  435. (:language nil org-export-default-language)
  436. (:keywords nil org-export-page-keywords)
  437. (:description nil org-export-page-description)
  438. (:customtime nil org-display-custom-times)
  439. (:headline-levels "H" org-export-headline-levels)
  440. (:section-numbers "num" org-export-with-section-numbers)
  441. (:section-number-format nil org-export-section-number-format)
  442. (:table-of-contents "toc" org-export-with-toc)
  443. (:preserve-breaks "\\n" org-export-preserve-breaks)
  444. (:archived-trees nil org-export-with-archived-trees)
  445. (:emphasize "*" org-export-with-emphasize)
  446. (:sub-superscript "^" org-export-with-sub-superscripts)
  447. (:special-strings "-" org-export-with-special-strings)
  448. (:footnotes "f" org-export-with-footnotes)
  449. (:drawers "d" org-export-with-drawers)
  450. (:tags "tags" org-export-with-tags)
  451. (:todo-keywords "todo" org-export-with-todo-keywords)
  452. (:priority "pri" org-export-with-priority)
  453. (:TeX-macros "TeX" org-export-with-TeX-macros)
  454. (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
  455. (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
  456. (:fixed-width ":" org-export-with-fixed-width)
  457. (:timestamps "<" org-export-with-timestamps)
  458. (:author-info "author" org-export-author-info)
  459. (:creator-info "creator" org-export-creator-info)
  460. (:time-stamp-file "timestamp" org-export-time-stamp-file)
  461. (:tables "|" org-export-with-tables)
  462. (:table-auto-headline nil org-export-highlight-first-table-line)
  463. (:style-include-default nil org-export-html-style-include-default)
  464. (:style-include-scripts nil org-export-html-style-include-scripts)
  465. (:style nil org-export-html-style)
  466. (:style-extra nil org-export-html-style-extra)
  467. (:agenda-style nil org-agenda-export-html-style)
  468. (:convert-org-links nil org-export-html-link-org-files-as-html)
  469. (:inline-images nil org-export-html-inline-images)
  470. (:html-extension nil org-export-html-extension)
  471. (:html-table-tag nil org-export-html-table-tag)
  472. (:expand-quoted-html "@" org-export-html-expand)
  473. (:timestamp nil org-export-html-with-timestamp)
  474. (:publishing-directory nil org-export-publishing-directory)
  475. (:preamble nil org-export-html-preamble)
  476. (:postamble nil org-export-html-postamble)
  477. (:auto-preamble nil org-export-html-auto-preamble)
  478. (:auto-postamble nil org-export-html-auto-postamble)
  479. (:author nil user-full-name)
  480. (:email nil user-mail-address)
  481. (:select-tags nil org-export-select-tags)
  482. (:exclude-tags nil org-export-exclude-tags))
  483. "List of properties that represent export/publishing variables.
  484. Each element is a list of 3 items:
  485. 1. The property that is used internally, and also for org-publish-project-alist
  486. 2. The string that can be used in the OPTION lines to set this option,
  487. or nil if this option cannot be changed in this way
  488. 3. The customization variable that sets the default for this option."
  489. )
  490. (defun org-default-export-plist ()
  491. "Return the property list with default settings for the export variables."
  492. (let ((l org-export-plist-vars) rtn e s v)
  493. (while (setq e (pop l))
  494. (setq s (nth 2 e)
  495. v (if (boundp s) (symbol-value s) nil)
  496. rtn (cons (car e) (cons v rtn))))
  497. rtn))
  498. (defvar org-export-inbuffer-options-extra nil
  499. "List of additional in-buffer options that should be detected.
  500. Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
  501. etc. Extensions can add to this list to get their options detected, and they
  502. can then add a function to `org-export-options-filters' to process these
  503. options.
  504. Each element in this list must be a list, with the in-buffer keyword as car,
  505. and a property (a symbol) as the next element. All occurrences of the
  506. keyword will be found, the values concatenated with a space character
  507. in between, and the result stored in the export options property list.")
  508. (defvar org-export-options-filters nil
  509. "Functions to be called to finalize the export/publishing options.
  510. All these options are stored in a property list, and each of the functions
  511. in this hook gets a chance to modify this property list. Each function
  512. must accept the property list as an argument, and must return the (possibly
  513. modified) list.")
  514. ;; FIXME: should we fold case here?
  515. (defun org-infile-export-plist ()
  516. "Return the property list with file-local settings for export."
  517. (save-excursion
  518. (save-restriction
  519. (widen)
  520. (goto-char (point-min))
  521. (let ((re (org-make-options-regexp
  522. (append
  523. '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
  524. "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
  525. "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
  526. "KEYWORDS" "DESCRIPTION")
  527. (mapcar 'car org-export-inbuffer-options-extra))))
  528. p key val text options a pr style
  529. latex-header
  530. ext-setup-or-nil setup-contents (start 0))
  531. (while (or (and ext-setup-or-nil
  532. (string-match re ext-setup-or-nil start)
  533. (setq start (match-end 0)))
  534. (and (setq ext-setup-or-nil nil start 0)
  535. (re-search-forward re nil t)))
  536. (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
  537. val (org-match-string-no-properties 2 ext-setup-or-nil))
  538. (cond
  539. ((setq a (assoc key org-export-inbuffer-options-extra))
  540. (setq pr (nth 1 a))
  541. (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
  542. ((string-equal key "TITLE") (setq p (plist-put p :title val)))
  543. ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
  544. ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
  545. ((string-equal key "DATE") (setq p (plist-put p :date val)))
  546. ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
  547. ((string-equal key "DESCRIPTION")
  548. (setq p (plist-put p :description val)))
  549. ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
  550. ((string-equal key "STYLE")
  551. (setq style (concat style "\n" val)))
  552. ((string-equal key "LATEX_HEADER")
  553. (setq latex-header (concat latex-header "\n" val)))
  554. ((string-equal key "TEXT")
  555. (setq text (if text (concat text "\n" val) val)))
  556. ((string-equal key "OPTIONS")
  557. (setq options (concat val " " options)))
  558. ((string-equal key "LINK_UP")
  559. (setq p (plist-put p :link-up val)))
  560. ((string-equal key "LINK_HOME")
  561. (setq p (plist-put p :link-home val)))
  562. ((string-equal key "EXPORT_SELECT_TAGS")
  563. (setq p (plist-put p :select-tags (org-split-string val))))
  564. ((string-equal key "EXPORT_EXCLUDE_TAGS")
  565. (setq p (plist-put p :exclude-tags (org-split-string val))))
  566. ((equal key "SETUPFILE")
  567. (setq setup-contents (org-file-contents
  568. (expand-file-name
  569. (org-remove-double-quotes
  570. (org-trim val)))
  571. 'noerror))
  572. (if (not ext-setup-or-nil)
  573. (setq ext-setup-or-nil setup-contents start 0)
  574. (setq ext-setup-or-nil
  575. (concat (substring ext-setup-or-nil 0 start)
  576. "\n" setup-contents "\n"
  577. (substring ext-setup-or-nil start)))))))
  578. (setq p (plist-put p :text text))
  579. (when style (setq p (plist-put p :style-extra style)))
  580. (when latex-header
  581. (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
  582. (when options
  583. (setq p (org-export-add-options-to-plist p options)))
  584. ;; Add macro definitions
  585. (goto-char (point-min))
  586. (while (re-search-forward
  587. "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
  588. nil t)
  589. (setq p (plist-put p (intern (concat ":macro-"
  590. (downcase (match-string 1))))
  591. (match-string 2))))
  592. p))))
  593. (defun org-export-add-options-to-plist (p options)
  594. "Parse an OPTIONS line and set values in the property list P."
  595. (let (o)
  596. (when options
  597. (let ((op org-export-plist-vars))
  598. (while (setq o (pop op))
  599. (if (and (nth 1 o)
  600. (string-match (concat (regexp-quote (nth 1 o))
  601. ":\\([^ \t\n\r;,.]*\\)")
  602. options))
  603. (setq p (plist-put p (car o)
  604. (car (read-from-string
  605. (match-string 1 options))))))))))
  606. p)
  607. (defun org-export-add-subtree-options (p pos)
  608. "Add options in subtree at position POS to property list P."
  609. (save-excursion
  610. (goto-char pos)
  611. (when (org-at-heading-p)
  612. (let (a)
  613. ;; This is actually read in `org-export-get-title-from-subtree'
  614. ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
  615. ;; (setq p (plist-put p :title a)))
  616. (when (setq a (org-entry-get pos "EXPORT_TEXT"))
  617. (setq p (plist-put p :text a)))
  618. (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
  619. (setq p (plist-put p :author a)))
  620. (when (setq a (org-entry-get pos "EXPORT_DATE"))
  621. (setq p (plist-put p :date a)))
  622. (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
  623. (setq p (org-export-add-options-to-plist p a)))))
  624. p))
  625. (defun org-export-directory (type plist)
  626. (let* ((val (plist-get plist :publishing-directory))
  627. (dir (if (listp val)
  628. (or (cdr (assoc type val)) ".")
  629. val)))
  630. dir))
  631. (defun org-export-process-option-filters (plist)
  632. (let ((functions org-export-options-filters) f)
  633. (while (setq f (pop functions))
  634. (setq plist (funcall f plist))))
  635. plist)
  636. ;;;###autoload
  637. (defun org-export (&optional arg)
  638. "Export dispatcher for Org-mode.
  639. When `org-export-run-in-background' is non-nil, try to run the command
  640. in the background. This will be done only for commands that write
  641. to a file. For details see the docstring of `org-export-run-in-background'.
  642. The prefix argument ARG will be passed to the exporter. However, if
  643. ARG is a double universal prefix `C-u C-u', that means to inverse the
  644. value of `org-export-run-in-background'."
  645. (interactive "P")
  646. (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
  647. (help "[t] insert the export option template
  648. \[v] limit export to visible part of outline tree
  649. \[a] export as ASCII
  650. \[h] export as HTML [H] to temporary buffer [R] export region
  651. \[b] export as HTML and open in browser
  652. \[l] export as LaTeX [L] to temporary buffer
  653. \[p] export as LaTeX and process to PDF
  654. \[d] export as LaTeX, process to PDF, and open the resulting PDF document
  655. \[D] export as DocBook
  656. \[V] export as DocBook, process to PDF, and open the resulting PDF document
  657. \[x] export as XOXO
  658. \[i] export current file as iCalendar file
  659. \[I] export all agenda files as iCalendar files
  660. \[c] export agenda files into combined iCalendar file
  661. \[F] publish current file [P] publish current project
  662. \[X] publish a project... [A] publish all projects")
  663. (cmds
  664. '((?t org-insert-export-options-template nil)
  665. (?v org-export-visible nil)
  666. (?a org-export-as-ascii t)
  667. (?h org-export-as-html t)
  668. (?b org-export-as-html-and-open t)
  669. (?H org-export-as-html-to-buffer nil)
  670. (?R org-export-region-as-html nil)
  671. (?x org-export-as-xoxo t)
  672. (?D org-export-as-docbook t)
  673. (?V org-export-as-docbook-pdf-and-open t)
  674. (?l org-export-as-latex t)
  675. (?p org-export-as-pdf t)
  676. (?d org-export-as-pdf-and-open t)
  677. (?L org-export-as-latex-to-buffer nil)
  678. (?i org-export-icalendar-this-file t)
  679. (?I org-export-icalendar-all-agenda-files t)
  680. (?c org-export-icalendar-combine-agenda-files t)
  681. (?F org-publish-current-file t)
  682. (?P org-publish-current-project t)
  683. (?X org-publish t)
  684. (?A org-publish-all t)))
  685. r1 r2 ass)
  686. (save-excursion
  687. (save-window-excursion
  688. (delete-other-windows)
  689. (with-output-to-temp-buffer "*Org Export/Publishing Help*"
  690. (princ help))
  691. (org-fit-window-to-buffer (get-buffer-window
  692. "*Org Export/Publishing Help*"))
  693. (message "Select command: ")
  694. (setq r1 (read-char-exclusive))))
  695. (setq r2 (if (< r1 27) (+ r1 96) r1))
  696. (unless (setq ass (assq r2 cmds))
  697. (error "No command associated with key %c" r1))
  698. (if (and bg (nth 2 ass)
  699. (not (buffer-base-buffer))
  700. (not (org-region-active-p)))
  701. ;; execute in background
  702. (let ((p (start-process
  703. (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
  704. "*Org Processes*"
  705. (expand-file-name invocation-name invocation-directory)
  706. "-batch"
  707. "-l" user-init-file
  708. "--eval" "(require 'org-exp)"
  709. "--eval" "(setq org-wait .2)"
  710. (buffer-file-name)
  711. "-f" (symbol-name (nth 1 ass)))))
  712. (set-process-sentinel p 'org-export-process-sentinel)
  713. (message "Background process \"%s\": started" p))
  714. ;; background processing not requested, or not possible
  715. (call-interactively (nth 1 ass)))))
  716. (defun org-export-process-sentinel (process status)
  717. (if (string-match "\n+\\'" status)
  718. (setq status (substring status 0 -1)))
  719. (message "Background process \"%s\": %s" process status))
  720. (defconst org-html-entities
  721. '(("nbsp")
  722. ("iexcl")
  723. ("cent")
  724. ("pound")
  725. ("curren")
  726. ("yen")
  727. ("brvbar")
  728. ("vert" . "&#124;")
  729. ("sect")
  730. ("uml")
  731. ("copy")
  732. ("ordf")
  733. ("laquo")
  734. ("not")
  735. ("shy")
  736. ("reg")
  737. ("macr")
  738. ("deg")
  739. ("plusmn")
  740. ("sup2")
  741. ("sup3")
  742. ("acute")
  743. ("micro")
  744. ("para")
  745. ("middot")
  746. ("odot"."o")
  747. ("star"."*")
  748. ("cedil")
  749. ("sup1")
  750. ("ordm")
  751. ("raquo")
  752. ("frac14")
  753. ("frac12")
  754. ("frac34")
  755. ("iquest")
  756. ("Agrave")
  757. ("Aacute")
  758. ("Acirc")
  759. ("Atilde")
  760. ("Auml")
  761. ("Aring") ("AA"."&Aring;")
  762. ("AElig")
  763. ("Ccedil")
  764. ("Egrave")
  765. ("Eacute")
  766. ("Ecirc")
  767. ("Euml")
  768. ("Igrave")
  769. ("Iacute")
  770. ("Icirc")
  771. ("Iuml")
  772. ("ETH")
  773. ("Ntilde")
  774. ("Ograve")
  775. ("Oacute")
  776. ("Ocirc")
  777. ("Otilde")
  778. ("Ouml")
  779. ("times")
  780. ("Oslash")
  781. ("Ugrave")
  782. ("Uacute")
  783. ("Ucirc")
  784. ("Uuml")
  785. ("Yacute")
  786. ("THORN")
  787. ("szlig")
  788. ("agrave")
  789. ("aacute")
  790. ("acirc")
  791. ("atilde")
  792. ("auml")
  793. ("aring")
  794. ("aelig")
  795. ("ccedil")
  796. ("egrave")
  797. ("eacute")
  798. ("ecirc")
  799. ("euml")
  800. ("igrave")
  801. ("iacute")
  802. ("icirc")
  803. ("iuml")
  804. ("eth")
  805. ("ntilde")
  806. ("ograve")
  807. ("oacute")
  808. ("ocirc")
  809. ("otilde")
  810. ("ouml")
  811. ("divide")
  812. ("oslash")
  813. ("ugrave")
  814. ("uacute")
  815. ("ucirc")
  816. ("uuml")
  817. ("yacute")
  818. ("thorn")
  819. ("yuml")
  820. ("fnof")
  821. ("Alpha")
  822. ("Beta")
  823. ("Gamma")
  824. ("Delta")
  825. ("Epsilon")
  826. ("Zeta")
  827. ("Eta")
  828. ("Theta")
  829. ("Iota")
  830. ("Kappa")
  831. ("Lambda")
  832. ("Mu")
  833. ("Nu")
  834. ("Xi")
  835. ("Omicron")
  836. ("Pi")
  837. ("Rho")
  838. ("Sigma")
  839. ("Tau")
  840. ("Upsilon")
  841. ("Phi")
  842. ("Chi")
  843. ("Psi")
  844. ("Omega")
  845. ("alpha")
  846. ("beta")
  847. ("gamma")
  848. ("delta")
  849. ("epsilon")
  850. ("varepsilon"."&epsilon;")
  851. ("zeta")
  852. ("eta")
  853. ("theta")
  854. ("iota")
  855. ("kappa")
  856. ("lambda")
  857. ("mu")
  858. ("nu")
  859. ("xi")
  860. ("omicron")
  861. ("pi")
  862. ("rho")
  863. ("sigmaf") ("varsigma"."&sigmaf;")
  864. ("sigma")
  865. ("tau")
  866. ("upsilon")
  867. ("phi")
  868. ("chi")
  869. ("psi")
  870. ("omega")
  871. ("thetasym") ("vartheta"."&thetasym;")
  872. ("upsih")
  873. ("piv")
  874. ("bull") ("bullet"."&bull;")
  875. ("hellip") ("dots"."&hellip;")
  876. ("prime")
  877. ("Prime")
  878. ("oline")
  879. ("frasl")
  880. ("weierp")
  881. ("image")
  882. ("real")
  883. ("trade")
  884. ("alefsym")
  885. ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
  886. ("uarr") ("uparrow"."&uarr;")
  887. ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
  888. ("darr")("downarrow"."&darr;")
  889. ("harr") ("leftrightarrow"."&harr;")
  890. ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
  891. ("lArr") ("Leftarrow"."&lArr;")
  892. ("uArr") ("Uparrow"."&uArr;")
  893. ("rArr") ("Rightarrow"."&rArr;")
  894. ("dArr") ("Downarrow"."&dArr;")
  895. ("hArr") ("Leftrightarrow"."&hArr;")
  896. ("forall")
  897. ("part") ("partial"."&part;")
  898. ("exist") ("exists"."&exist;")
  899. ("empty") ("emptyset"."&empty;")
  900. ("nabla")
  901. ("isin") ("in"."&isin;")
  902. ("notin")
  903. ("ni")
  904. ("prod")
  905. ("sum")
  906. ("minus")
  907. ("lowast") ("ast"."&lowast;")
  908. ("radic")
  909. ("prop") ("proptp"."&prop;")
  910. ("infin") ("infty"."&infin;")
  911. ("ang") ("angle"."&ang;")
  912. ("and") ("wedge"."&and;")
  913. ("or") ("vee"."&or;")
  914. ("cap")
  915. ("cup")
  916. ("int")
  917. ("there4")
  918. ("sim")
  919. ("cong") ("simeq"."&cong;")
  920. ("asymp")("approx"."&asymp;")
  921. ("ne") ("neq"."&ne;")
  922. ("equiv")
  923. ("le")
  924. ("ge")
  925. ("sub") ("subset"."&sub;")
  926. ("sup") ("supset"."&sup;")
  927. ("nsub")
  928. ("sube")
  929. ("supe")
  930. ("oplus")
  931. ("otimes")
  932. ("perp")
  933. ("sdot") ("cdot"."&sdot;")
  934. ("lceil")
  935. ("rceil")
  936. ("lfloor")
  937. ("rfloor")
  938. ("lang")
  939. ("rang")
  940. ("loz") ("Diamond"."&loz;")
  941. ("spades") ("spadesuit"."&spades;")
  942. ("clubs") ("clubsuit"."&clubs;")
  943. ("hearts") ("diamondsuit"."&hearts;")
  944. ("diams") ("diamondsuit"."&diams;")
  945. ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
  946. ("quot")
  947. ("amp")
  948. ("lt")
  949. ("gt")
  950. ("OElig")
  951. ("oelig")
  952. ("Scaron")
  953. ("scaron")
  954. ("Yuml")
  955. ("circ")
  956. ("tilde")
  957. ("ensp")
  958. ("emsp")
  959. ("thinsp")
  960. ("zwnj")
  961. ("zwj")
  962. ("lrm")
  963. ("rlm")
  964. ("ndash")
  965. ("mdash")
  966. ("lsquo")
  967. ("rsquo")
  968. ("sbquo")
  969. ("ldquo")
  970. ("rdquo")
  971. ("bdquo")
  972. ("dagger")
  973. ("Dagger")
  974. ("permil")
  975. ("lsaquo")
  976. ("rsaquo")
  977. ("euro")
  978. ("arccos"."arccos")
  979. ("arcsin"."arcsin")
  980. ("arctan"."arctan")
  981. ("arg"."arg")
  982. ("cos"."cos")
  983. ("cosh"."cosh")
  984. ("cot"."cot")
  985. ("coth"."coth")
  986. ("csc"."csc")
  987. ("deg"."deg")
  988. ("det"."det")
  989. ("dim"."dim")
  990. ("exp"."exp")
  991. ("gcd"."gcd")
  992. ("hom"."hom")
  993. ("inf"."inf")
  994. ("ker"."ker")
  995. ("lg"."lg")
  996. ("lim"."lim")
  997. ("liminf"."liminf")
  998. ("limsup"."limsup")
  999. ("ln"."ln")
  1000. ("log"."log")
  1001. ("max"."max")
  1002. ("min"."min")
  1003. ("Pr"."Pr")
  1004. ("sec"."sec")
  1005. ("sin"."sin")
  1006. ("sinh"."sinh")
  1007. ("sup"."sup")
  1008. ("tan"."tan")
  1009. ("tanh"."tanh")
  1010. )
  1011. "Entities for TeX->HTML translation.
  1012. Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
  1013. \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
  1014. In that case, \"\\ent\" will be translated to \"&other;\".
  1015. The list contains HTML entities for Latin-1, Greek and other symbols.
  1016. It is supplemented by a number of commonly used TeX macros with appropriate
  1017. translations. There is currently no way for users to extend this.")
  1018. ;;; General functions for all backends
  1019. (defvar org-export-target-aliases nil
  1020. "Alist of targets with invisible aliases.")
  1021. (defvar org-export-preferred-target-alist nil
  1022. "Alist of section id's with preferred aliases.")
  1023. (defvar org-export-code-refs nil
  1024. "Alist of code references and line numbers")
  1025. (defun org-export-preprocess-string (string &rest parameters)
  1026. "Cleanup STRING so that that the true exported has a more consistent source.
  1027. This function takes STRING, which should be a buffer-string of an org-file
  1028. to export. It then creates a temporary buffer where it does its job.
  1029. The result is then again returned as a string, and the exporter works
  1030. on this string to produce the exported version."
  1031. (interactive)
  1032. (let* ((htmlp (plist-get parameters :for-html))
  1033. (asciip (plist-get parameters :for-ascii))
  1034. (latexp (plist-get parameters :for-LaTeX))
  1035. (docbookp (plist-get parameters :for-docbook))
  1036. (backend (cond (htmlp 'html)
  1037. (latexp 'latex)
  1038. (asciip 'ascii)
  1039. (docbookp 'docbook)))
  1040. (archived-trees (plist-get parameters :archived-trees))
  1041. (inhibit-read-only t)
  1042. (drawers org-drawers)
  1043. (outline-regexp "\\*+ ")
  1044. target-alist rtn)
  1045. (setq org-export-target-aliases nil)
  1046. (setq org-export-preferred-target-alist nil)
  1047. (setq org-export-code-refs nil)
  1048. (with-current-buffer (get-buffer-create " org-mode-tmp")
  1049. (erase-buffer)
  1050. (insert string)
  1051. (setq case-fold-search t)
  1052. ;; Remove license-to-kill stuff
  1053. ;; The caller marks some stuff for killing, stuff that has been
  1054. ;; used to create the page title, for example.
  1055. (org-export-kill-licensed-text)
  1056. (let ((org-inhibit-startup t)) (org-mode))
  1057. (setq case-fold-search t)
  1058. ;; Call the hook
  1059. (run-hooks 'org-export-preprocess-hook)
  1060. ;; Process the macros
  1061. (org-export-preprocess-apply-macros)
  1062. (run-hooks 'org-export-preprocess-after-macros-hook)
  1063. (untabify (point-min) (point-max))
  1064. ;; Handle include files, and call a hook
  1065. (org-export-handle-include-files)
  1066. (run-hooks 'org-export-preprocess-after-include-files-hook)
  1067. ;; Get rid of archived trees
  1068. (org-export-remove-archived-trees archived-trees)
  1069. ;; Remove comment environment and comment subtrees
  1070. (org-export-remove-comment-blocks-and-subtrees)
  1071. ;; Get rid of excluded trees, and call a hook
  1072. (org-export-handle-export-tags (plist-get parameters :select-tags)
  1073. (plist-get parameters :exclude-tags))
  1074. (run-hooks 'org-export-preprocess-after-tree-selection-hook)
  1075. ;; Handle source code snippets
  1076. (org-export-replace-src-segments-and-examples backend)
  1077. ;; Protect short examples marked by a leading colon
  1078. (org-export-protect-colon-examples)
  1079. ;; Normalize footnotes
  1080. (when (plist-get parameters :footnotes)
  1081. (org-footnote-normalize nil t))
  1082. ;; Find all headings and compute the targets for them
  1083. (setq target-alist (org-export-define-heading-targets target-alist))
  1084. ;; Get rid of drawers
  1085. (org-export-remove-or-extract-drawers drawers
  1086. (plist-get parameters :drawers))
  1087. ;; Get the correct stuff before the first headline
  1088. (when (plist-get parameters :skip-before-1st-heading)
  1089. (goto-char (point-min))
  1090. (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
  1091. (delete-region (point-min) (match-beginning 0))
  1092. (goto-char (point-min))
  1093. (insert "\n")))
  1094. (when (plist-get parameters :add-text)
  1095. (goto-char (point-min))
  1096. (insert (plist-get parameters :add-text) "\n"))
  1097. ;; Remove todo-keywords before exporting, if the user has requested so
  1098. (org-export-remove-headline-metadata parameters)
  1099. ;; Find targets in comments and move them out of comments,
  1100. ;; but mark them as targets that should be invisible
  1101. (setq target-alist (org-export-handle-invisible-targets target-alist))
  1102. ;; Select and protect backend specific stuff, throw away stuff
  1103. ;; that is specific for other backends
  1104. (org-export-select-backend-specific-text backend)
  1105. ;; Protect quoted subtrees
  1106. (org-export-protect-quoted-subtrees)
  1107. ;; Remove clock lines
  1108. (org-export-remove-clock-lines)
  1109. ;; Protect verbatim elements
  1110. (org-export-protect-verbatim)
  1111. ;; Blockquotes, verse, and center
  1112. (org-export-mark-blockquote-verse-center)
  1113. ;; Remove timestamps, if the user has requested so
  1114. (unless (plist-get parameters :timestamps)
  1115. (org-export-remove-timestamps))
  1116. ;; Attach captions to the correct object
  1117. (setq target-alist (org-export-attach-captions-and-attributes
  1118. backend target-alist))
  1119. ;; Find matches for radio targets and turn them into internal links
  1120. (org-export-mark-radio-links)
  1121. ;; Find all links that contain a newline and put them into a single line
  1122. (org-export-concatenate-multiline-links)
  1123. ;; Normalize links: Convert angle and plain links into bracket links
  1124. ;; and expand link abbreviations
  1125. (org-export-normalize-links)
  1126. ;; Find all internal links. If they have a fuzzy match (i.e. not
  1127. ;; a *dedicated* target match, let the link point to the
  1128. ;; corresponding section.
  1129. (org-export-target-internal-links target-alist)
  1130. ;; Find multiline emphasis and put them into single line
  1131. (when (plist-get parameters :emph-multiline)
  1132. (org-export-concatenate-multiline-emphasis))
  1133. ;; Remove special table lines
  1134. (when org-export-table-remove-special-lines
  1135. (org-export-remove-special-table-lines))
  1136. ;; Another hook
  1137. (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
  1138. ;; LaTeX-specific preprocessing
  1139. (when latexp
  1140. (require 'org-latex nil)
  1141. (org-export-latex-preprocess parameters))
  1142. ;; ASCII-specific preprocessing
  1143. (when asciip
  1144. (org-export-ascii-preprocess parameters))
  1145. ;; HTML-specific preprocessing
  1146. (when htmlp
  1147. (org-export-html-preprocess parameters))
  1148. ;; DocBook-specific preprocessing
  1149. (when docbookp
  1150. (require 'org-docbook nil)
  1151. (org-export-docbook-preprocess parameters))
  1152. ;; Remove or replace comments
  1153. (org-export-handle-comments (plist-get parameters :comments))
  1154. ;; Run the final hook
  1155. (run-hooks 'org-export-preprocess-final-hook)
  1156. (setq rtn (buffer-string)))
  1157. (kill-buffer " org-mode-tmp")
  1158. rtn))
  1159. (defun org-export-kill-licensed-text ()
  1160. "Remove all text that is marked with a :org-license-to-kill property."
  1161. (let (p)
  1162. (while (setq p (text-property-any (point-min) (point-max)
  1163. :org-license-to-kill t))
  1164. (delete-region
  1165. p (or (next-single-property-change p :org-license-to-kill)
  1166. (point-max))))))
  1167. (defun org-export-define-heading-targets (target-alist)
  1168. "Find all headings and define the targets for them.
  1169. The new targets are added to TARGET-ALIST, which is also returned."
  1170. (goto-char (point-min))
  1171. (org-init-section-numbers)
  1172. (let ((re (concat "^" org-outline-regexp
  1173. "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
  1174. level target last-section-target a id)
  1175. (while (re-search-forward re nil t)
  1176. (if (match-end 2)
  1177. (progn
  1178. (setq id (org-match-string-no-properties 2))
  1179. (push (cons id target) target-alist)
  1180. (setq a (or (assoc last-section-target org-export-target-aliases)
  1181. (progn
  1182. (push (list last-section-target)
  1183. org-export-target-aliases)
  1184. (car org-export-target-aliases))))
  1185. (push (caar target-alist) (cdr a))
  1186. (when (equal (match-string 1) "CUSTOM_ID")
  1187. (if (not (assoc last-section-target
  1188. org-export-preferred-target-alist))
  1189. (push (cons last-section-target id)
  1190. org-export-preferred-target-alist))))
  1191. (setq level (org-reduced-level
  1192. (save-excursion (goto-char (point-at-bol))
  1193. (org-outline-level))))
  1194. (setq target (org-solidify-link-text
  1195. (format "sec-%s" (org-section-number level))))
  1196. (setq last-section-target target)
  1197. (push (cons target target) target-alist)
  1198. (add-text-properties
  1199. (point-at-bol) (point-at-eol)
  1200. (list 'target target)))))
  1201. target-alist)
  1202. (defun org-export-handle-invisible-targets (target-alist)
  1203. "Find targets in comments and move them out of comments.
  1204. Mark them as invisible targets."
  1205. (let (target tmp a)
  1206. (goto-char (point-min))
  1207. (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
  1208. ;; Check if the line before or after is a headline with a target
  1209. (if (setq target (or (get-text-property (point-at-bol 0) 'target)
  1210. (get-text-property (point-at-bol 2) 'target)))
  1211. (progn
  1212. ;; use the existing target in a neighboring line
  1213. (setq tmp (match-string 2))
  1214. (replace-match "")
  1215. (and (looking-at "\n") (delete-char 1))
  1216. (push (cons (setq tmp (org-solidify-link-text tmp)) target)
  1217. target-alist)
  1218. (setq a (or (assoc target org-export-target-aliases)
  1219. (progn
  1220. (push (list target) org-export-target-aliases)
  1221. (car org-export-target-aliases))))
  1222. (push tmp (cdr a)))
  1223. ;; Make an invisible target
  1224. (replace-match "\\1(INVISIBLE)"))))
  1225. target-alist)
  1226. (defun org-export-target-internal-links (target-alist)
  1227. "Find all internal links and assign targets to them.
  1228. If a link has a fuzzy match (i.e. not a *dedicated* target match),
  1229. let the link point to the corresponding section.
  1230. This function also handles the id links, if they have a match in
  1231. the current file."
  1232. (goto-char (point-min))
  1233. (while (re-search-forward org-bracket-link-regexp nil t)
  1234. (org-if-unprotected
  1235. (let* ((md (match-data))
  1236. (desc (match-end 2))
  1237. (link (org-link-unescape (match-string 1)))
  1238. (slink (org-solidify-link-text link))
  1239. found props pos cref
  1240. (target
  1241. (cond
  1242. ((= (string-to-char link) ?#)
  1243. ;; user wants exactly this link
  1244. link)
  1245. ((cdr (assoc slink target-alist))
  1246. (or (cdr (assoc (assoc slink target-alist)
  1247. org-export-preferred-target-alist))
  1248. (cdr (assoc slink target-alist))))
  1249. ((and (string-match "^id:" link)
  1250. (cdr (assoc (substring link 3) target-alist))))
  1251. ((string-match "^(\\(.*\\))$" link)
  1252. (setq cref (match-string 1 link))
  1253. (concat "coderef:" cref))
  1254. ((string-match org-link-types-re link) nil)
  1255. ((or (file-name-absolute-p link)
  1256. (string-match "^\\." link))
  1257. nil)
  1258. (t
  1259. (save-excursion
  1260. (setq found (condition-case nil (org-link-search link)
  1261. (error nil)))
  1262. (when (and found
  1263. (or (org-on-heading-p)
  1264. (not (eq found 'dedicated))))
  1265. (or (get-text-property (point) 'target)
  1266. (get-text-property
  1267. (max (point-min)
  1268. (1- (or (previous-single-property-change
  1269. (point) 'target) 0)))
  1270. 'target))))))))
  1271. (when target
  1272. (set-match-data md)
  1273. (goto-char (match-beginning 1))
  1274. (setq props (text-properties-at (point)))
  1275. (delete-region (match-beginning 1) (match-end 1))
  1276. (setq pos (point))
  1277. (insert target)
  1278. (unless desc (insert "][" link))
  1279. (add-text-properties pos (point) props))))))
  1280. (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
  1281. "Remove drawers, or extract the content.
  1282. ALL-DRAWERS is a list of all drawer names valid in the current buffer.
  1283. EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
  1284. whose content to keep."
  1285. (unless (eq t exp-drawers)
  1286. (goto-char (point-min))
  1287. (let ((re (concat "^[ \t]*:\\("
  1288. (mapconcat
  1289. 'identity
  1290. (org-delete-all exp-drawers
  1291. (copy-sequence all-drawers))
  1292. "\\|")
  1293. "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
  1294. (while (re-search-forward re nil t)
  1295. (org-if-unprotected
  1296. (replace-match ""))))))
  1297. (defun org-export-handle-export-tags (select-tags exclude-tags)
  1298. "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
  1299. Both arguments are lists of tags.
  1300. If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
  1301. will be removed.
  1302. After that, all subtrees that are marked by EXCLUDE-TAGS will be
  1303. removed as well."
  1304. (remove-text-properties (point-min) (point-max) '(:org-delete t))
  1305. (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
  1306. select-tags "\\|")
  1307. "\\):"))
  1308. (re-excl (concat ":\\(" (mapconcat 'regexp-quote
  1309. exclude-tags "\\|")
  1310. "\\):"))
  1311. beg end cont)
  1312. (goto-char (point-min))
  1313. (when (and select-tags
  1314. (re-search-forward
  1315. (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
  1316. ;; At least one tree is marked for export, this means
  1317. ;; all the unmarked stuff needs to go.
  1318. ;; Dig out the trees that should be exported
  1319. (goto-char (point-min))
  1320. (outline-next-heading)
  1321. (setq beg (point))
  1322. (put-text-property beg (point-max) :org-delete t)
  1323. (while (re-search-forward re-sel nil t)
  1324. (when (org-on-heading-p)
  1325. (org-back-to-heading)
  1326. (remove-text-properties
  1327. (max (1- (point)) (point-min))
  1328. (setq cont (save-excursion (org-end-of-subtree t t)))
  1329. '(:org-delete t))
  1330. (while (and (org-up-heading-safe)
  1331. (get-text-property (point) :org-delete))
  1332. (remove-text-properties (max (1- (point)) (point-min))
  1333. (point-at-eol) '(:org-delete t)))
  1334. (goto-char cont))))
  1335. ;; Remove the trees explicitly marked for noexport
  1336. (when exclude-tags
  1337. (goto-char (point-min))
  1338. (while (re-search-forward re-excl nil t)
  1339. (when (org-at-heading-p)
  1340. (org-back-to-heading t)
  1341. (setq beg (point))
  1342. (org-end-of-subtree t)
  1343. (delete-region beg (point)))))
  1344. ;; Remove everything that is now still marked for deletion
  1345. (goto-char (point-min))
  1346. (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
  1347. (setq end (or (next-single-property-change beg :org-delete)
  1348. (point-max)))
  1349. (delete-region beg end))))
  1350. (defun org-export-remove-archived-trees (export-archived-trees)
  1351. "Remove archived trees.
  1352. When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
  1353. When it is t, the entire archived tree will be exported.
  1354. When it is nil the entire tree including the headline will be removed
  1355. from the buffer."
  1356. (let ((re-archive (concat ":" org-archive-tag ":"))
  1357. a b)
  1358. (when (not (eq export-archived-trees t))
  1359. (goto-char (point-min))
  1360. (while (re-search-forward re-archive nil t)
  1361. (if (not (org-on-heading-p t))
  1362. (org-end-of-subtree t)
  1363. (beginning-of-line 1)
  1364. (setq a (if export-archived-trees
  1365. (1+ (point-at-eol)) (point))
  1366. b (org-end-of-subtree t))
  1367. (if (> b a) (delete-region a b)))))))
  1368. (defun org-export-remove-headline-metadata (opts)
  1369. "Remove meta data from the headline, according to user options."
  1370. (let ((re org-complex-heading-regexp)
  1371. (todo (plist-get opts :todo-keywords))
  1372. (tags (plist-get opts :tags))
  1373. (pri (plist-get opts :priority))
  1374. (elts '(1 2 3 4 5))
  1375. rpl)
  1376. (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
  1377. (when (or (not todo) (not tags) (not pri))
  1378. (goto-char (point-min))
  1379. (while (re-search-forward re nil t)
  1380. (org-if-unprotected
  1381. (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
  1382. elts " "))
  1383. (replace-match rpl t t))))))
  1384. (defun org-export-remove-timestamps ()
  1385. "Remove timestamps and keywords for export."
  1386. (goto-char (point-min))
  1387. (while (re-search-forward org-maybe-keyword-time-regexp nil t)
  1388. (backward-char 1)
  1389. (org-if-unprotected
  1390. (unless (save-match-data (org-at-table-p))
  1391. (replace-match "")
  1392. (beginning-of-line 1)
  1393. (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
  1394. (replace-match ""))))))
  1395. (defun org-export-remove-clock-lines ()
  1396. "Remove clock lines for export."
  1397. (goto-char (point-min))
  1398. (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
  1399. (while (re-search-forward re nil t)
  1400. (org-if-unprotected
  1401. (replace-match "")))))
  1402. (defun org-export-protect-quoted-subtrees ()
  1403. "Mark quoted subtrees with the protection property."
  1404. (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
  1405. (goto-char (point-min))
  1406. (while (re-search-forward re-quote nil t)
  1407. (goto-char (match-beginning 0))
  1408. (end-of-line 1)
  1409. (add-text-properties (point) (org-end-of-subtree t)
  1410. '(org-protected t)))))
  1411. (defun org-export-protect-verbatim ()
  1412. "Mark verbatim snippets with the protection property."
  1413. (goto-char (point-min))
  1414. (while (re-search-forward org-verbatim-re nil t)
  1415. (add-text-properties (match-beginning 4) (match-end 4)
  1416. '(org-protected t))
  1417. (goto-char (1+ (match-end 4)))))
  1418. (defun org-export-protect-colon-examples ()
  1419. "Protect lines starting with a colon."
  1420. (goto-char (point-min))
  1421. (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
  1422. (while (re-search-forward re nil t)
  1423. (beginning-of-line 1)
  1424. (setq beg (point))
  1425. (while (looking-at re)
  1426. (end-of-line 1)
  1427. (or (eobp) (forward-char 1)))
  1428. (add-text-properties beg (if (bolp) (1- (point)) (point))
  1429. '(org-protected t)))))
  1430. (defun org-export-select-backend-specific-text (backend)
  1431. (let ((formatters
  1432. '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
  1433. (html "HTML" "BEGIN_HTML" "END_HTML")
  1434. (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
  1435. (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1436. (case-fold-search t)
  1437. fmt)
  1438. (while formatters
  1439. (setq fmt (pop formatters))
  1440. (when (eq (car fmt) backend)
  1441. ;; This is selected code, put it into the file for real
  1442. (goto-char (point-min))
  1443. (while (re-search-forward (concat "^#\\+" (cadr fmt)
  1444. ":[ \t]*\\(.*\\)") nil t)
  1445. (replace-match "\\1" t)
  1446. (add-text-properties
  1447. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1448. '(org-protected t))))
  1449. (goto-char (point-min))
  1450. (while (re-search-forward
  1451. (concat "^#\\+"
  1452. (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
  1453. (cadddr fmt) "\\>.*\n?") nil t)
  1454. (if (eq (car fmt) backend)
  1455. ;; yes, keep this
  1456. (add-text-properties (match-beginning 1) (1+ (match-end 1))
  1457. '(org-protected t))
  1458. ;; No, this is for a different backend, kill it
  1459. (delete-region (match-beginning 0) (match-end 0)))))))
  1460. (defun org-export-mark-blockquote-verse-center ()
  1461. "Mark block quote and verse environments with special cookies.
  1462. These special cookies will later be interpreted by the backend."
  1463. ;; Blockquotes
  1464. (goto-char (point-min))
  1465. (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
  1466. nil t)
  1467. (replace-match (if (equal (downcase (match-string 1)) "end")
  1468. "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
  1469. t t))
  1470. ;; Verse
  1471. (goto-char (point-min))
  1472. (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
  1473. (replace-match (if (equal (downcase (match-string 1)) "end")
  1474. "ORG-VERSE-END" "ORG-VERSE-START")
  1475. t t))
  1476. ;; Center
  1477. (goto-char (point-min))
  1478. (while (re-search-forward "^#\\+\\(begin\\|end\\)_center\\>.*" nil t)
  1479. (replace-match (if (equal (downcase (match-string 1)) "end")
  1480. "ORG-CENTER-END" "ORG-CENTER-START")
  1481. t t)))
  1482. (defun org-export-attach-captions-and-attributes (backend target-alist)
  1483. "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
  1484. If the next thing following is a table, add the text properties to the first
  1485. table line. If it is a link, add it to the line containing the link."
  1486. (goto-char (point-min))
  1487. (remove-text-properties (point-min) (point-max)
  1488. '(org-caption nil org-attributes nil))
  1489. (let ((case-fold-search t)
  1490. (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
  1491. "\\|"
  1492. "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
  1493. "\\|"
  1494. "^#\\+label:[ \t]+\\(.*\\)"
  1495. "\\|"
  1496. "^[ \t]*|[^-]"
  1497. "\\|"
  1498. "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
  1499. cap attr label)
  1500. (while (re-search-forward re nil t)
  1501. (cond
  1502. ((match-end 1)
  1503. (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
  1504. ((match-end 2)
  1505. (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
  1506. ((match-end 3)
  1507. (setq label (org-trim (match-string 3))))
  1508. (t
  1509. (add-text-properties (point-at-bol) (point-at-eol)
  1510. (list 'org-caption cap
  1511. 'org-attributes attr
  1512. 'org-label label))
  1513. (if label (push (cons label label) target-alist))
  1514. (setq cap nil attr nil label nil)))))
  1515. target-alist)
  1516. (defun org-export-remove-comment-blocks-and-subtrees ()
  1517. "Remove the comment environment, and also commented subtrees."
  1518. (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  1519. (case-fold-search nil))
  1520. ;; Remove comment environment
  1521. (goto-char (point-min))
  1522. (while (re-search-forward
  1523. "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
  1524. (replace-match "" t t))
  1525. ;; Remove subtrees that are commented
  1526. (goto-char (point-min))
  1527. (while (re-search-forward re-commented nil t)
  1528. (goto-char (match-beginning 0))
  1529. (delete-region (point) (org-end-of-subtree t)))))
  1530. (defun org-export-handle-comments (commentsp)
  1531. "Remove comments, or convert to backend-specific format.
  1532. COMMENTSP can be a format string for publishing comments.
  1533. When it is nil, all comments will be removed."
  1534. (let ((re "^#\\(.*\n?\\)")
  1535. pos)
  1536. (goto-char (point-min))
  1537. (while (or (looking-at re)
  1538. (re-search-forward re nil t))
  1539. (setq pos (match-beginning 0))
  1540. (if commentsp
  1541. (progn (add-text-properties
  1542. (match-beginning 0) (match-end 0) '(org-protected t))
  1543. (replace-match (format commentsp (match-string 1)) t t))
  1544. (goto-char (1+ pos))
  1545. (org-if-unprotected
  1546. (replace-match "")
  1547. (goto-char (max (point-min) (1- pos))))))))
  1548. (defun org-export-mark-radio-links ()
  1549. "Find all matches for radio targets and turn them into internal links."
  1550. (let ((re-radio (and org-target-link-regexp
  1551. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
  1552. (goto-char (point-min))
  1553. (when re-radio
  1554. (while (re-search-forward re-radio nil t)
  1555. (org-if-unprotected
  1556. (replace-match "\\1[[\\2]]"))))))
  1557. (defun org-export-remove-special-table-lines ()
  1558. "Remove tables lines that are used for internal purposes."
  1559. (goto-char (point-min))
  1560. (while (re-search-forward "^[ \t]*|" nil t)
  1561. (beginning-of-line 1)
  1562. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1563. (and (looking-at ".*?| *<[0-9]+> *|")
  1564. (not (looking-at ".*?| *[^ <|]"))))
  1565. (delete-region (max (point-min) (1- (point-at-bol)))
  1566. (point-at-eol))
  1567. (end-of-line 1))))
  1568. (defun org-export-normalize-links ()
  1569. "Convert all links to bracket links, and expand link abbreviations."
  1570. (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  1571. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
  1572. (goto-char (point-min))
  1573. (while (re-search-forward re-plain-link nil t)
  1574. (goto-char (1- (match-end 0)))
  1575. (org-if-unprotected-at (1+ (match-beginning 0))
  1576. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1577. ":" (match-string 3) "]]")))
  1578. ;; added 'org-link face to links
  1579. (put-text-property 0 (length s) 'face 'org-link s)
  1580. (replace-match s t t))))
  1581. (goto-char (point-min))
  1582. (while (re-search-forward re-angle-link nil t)
  1583. (goto-char (1- (match-end 0)))
  1584. (org-if-unprotected
  1585. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1586. ":" (match-string 3) "]]")))
  1587. (put-text-property 0 (length s) 'face 'org-link s)
  1588. (replace-match s t t))))
  1589. (goto-char (point-min))
  1590. (while (re-search-forward org-bracket-link-regexp nil t)
  1591. (goto-char (1- (match-end 0)))
  1592. (org-if-unprotected
  1593. (let* ((xx (save-match-data
  1594. (org-translate-link
  1595. (org-link-expand-abbrev (match-string 1)))))
  1596. (s (concat
  1597. "[[" (org-add-props (copy-sequence xx)
  1598. nil 'org-protected t)
  1599. "]"
  1600. (if (match-end 3)
  1601. (match-string 2)
  1602. (concat "[" (org-add-props
  1603. (copy-sequence xx)
  1604. '(org-protected t))
  1605. "]"))
  1606. "]")))
  1607. (put-text-property 0 (length s) 'face 'org-link s)
  1608. (replace-match s t t))))))
  1609. (defun org-export-concatenate-multiline-links ()
  1610. "Find multi-line links and put it all into a single line.
  1611. This is to make sure that the line-processing export backends
  1612. can work correctly."
  1613. (goto-char (point-min))
  1614. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1615. (org-if-unprotected
  1616. (replace-match "\\1 \\3")
  1617. (goto-char (match-beginning 0)))))
  1618. (defun org-export-concatenate-multiline-emphasis ()
  1619. "Find multi-line emphasis and put it all into a single line.
  1620. This is to make sure that the line-processing export backends
  1621. can work correctly."
  1622. (goto-char (point-min))
  1623. (while (re-search-forward org-emph-re nil t)
  1624. (if (and (not (= (char-after (match-beginning 3))
  1625. (char-after (match-beginning 4))))
  1626. (save-excursion (goto-char (match-beginning 0))
  1627. (save-match-data (not (org-at-table-p)))))
  1628. (org-if-unprotected
  1629. (subst-char-in-region (match-beginning 0) (match-end 0)
  1630. ?\n ?\ t)
  1631. (goto-char (1- (match-end 0))))
  1632. (goto-char (1+ (match-beginning 0))))))
  1633. (defun org-export-grab-title-from-buffer ()
  1634. "Get a title for the current document, from looking at the buffer."
  1635. (let ((inhibit-read-only t))
  1636. (save-excursion
  1637. (goto-char (point-min))
  1638. (let ((end (if (looking-at org-outline-regexp)
  1639. (point)
  1640. (save-excursion (outline-next-heading) (point)))))
  1641. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1642. ;; Mark the line so that it will not be exported as normal text.
  1643. (org-unmodified
  1644. (add-text-properties (match-beginning 0) (match-end 0)
  1645. (list :org-license-to-kill t)))
  1646. ;; Return the title string
  1647. (org-trim (match-string 0)))))))
  1648. (defun org-export-get-title-from-subtree ()
  1649. "Return subtree title and exclude it from export."
  1650. (let (title (rbeg (region-beginning)) (rend (region-end)))
  1651. (save-excursion
  1652. (goto-char rbeg)
  1653. (when (and (org-at-heading-p)
  1654. (>= (org-end-of-subtree t t) rend))
  1655. ;; This is a subtree, we take the title from the first heading
  1656. (goto-char rbeg)
  1657. (looking-at org-todo-line-regexp)
  1658. (setq title (match-string 3))
  1659. (org-unmodified
  1660. (add-text-properties (point) (1+ (point-at-eol))
  1661. (list :org-license-to-kill t)))
  1662. (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
  1663. title))
  1664. (defun org-solidify-link-text (s &optional alist)
  1665. "Take link text and make a safe target out of it."
  1666. (save-match-data
  1667. (let* ((rtn
  1668. (mapconcat
  1669. 'identity
  1670. (org-split-string s "[ \t\r\n]+") "=="))
  1671. (a (assoc rtn alist)))
  1672. (or (cdr a) rtn))))
  1673. (defun org-get-min-level (lines &optional offset)
  1674. "Get the minimum level in LINES."
  1675. (let ((re "^\\(\\*+\\) ") l)
  1676. (catch 'exit
  1677. (while (setq l (pop lines))
  1678. (if (string-match re l)
  1679. (throw 'exit (org-tr-level (- (length (match-string 1 l))
  1680. (or offset 0))))))
  1681. 1)))
  1682. ;; Variable holding the vector with section numbers
  1683. (defvar org-section-numbers (make-vector org-level-max 0))
  1684. (defun org-init-section-numbers ()
  1685. "Initialize the vector for the section numbers."
  1686. (let* ((level -1)
  1687. (numbers (nreverse (org-split-string "" "\\.")))
  1688. (depth (1- (length org-section-numbers)))
  1689. (i depth) number-string)
  1690. (while (>= i 0)
  1691. (if (> i level)
  1692. (aset org-section-numbers i 0)
  1693. (setq number-string (or (car numbers) "0"))
  1694. (if (string-match "\\`[A-Z]\\'" number-string)
  1695. (aset org-section-numbers i
  1696. (- (string-to-char number-string) ?A -1))
  1697. (aset org-section-numbers i (string-to-number number-string)))
  1698. (pop numbers))
  1699. (setq i (1- i)))))
  1700. (defun org-section-number (&optional level)
  1701. "Return a string with the current section number.
  1702. When LEVEL is non-nil, increase section numbers on that level."
  1703. (let* ((depth (1- (length org-section-numbers)))
  1704. (string "")
  1705. (fmts (car org-export-section-number-format))
  1706. (term (cdr org-export-section-number-format))
  1707. (sep "")
  1708. ctype fmt idx n)
  1709. (when level
  1710. (when (> level -1)
  1711. (aset org-section-numbers
  1712. level (1+ (aref org-section-numbers level))))
  1713. (setq idx (1+ level))
  1714. (while (<= idx depth)
  1715. (if (not (= idx 1))
  1716. (aset org-section-numbers idx 0))
  1717. (setq idx (1+ idx))))
  1718. (setq idx 0)
  1719. (while (<= idx depth)
  1720. (when (> (aref org-section-numbers idx) 0)
  1721. (setq fmt (or (pop fmts) fmt)
  1722. ctype (car fmt)
  1723. n (aref org-section-numbers idx)
  1724. string (if (> n 0)
  1725. (concat string sep (org-number-to-counter n ctype))
  1726. (concat string ".0"))
  1727. sep (nth 1 fmt)))
  1728. (setq idx (1+ idx)))
  1729. (save-match-data
  1730. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1731. (setq string (replace-match "" t nil string)))
  1732. (if (string-match "\\(\\.0\\)+\\'" string)
  1733. (setq string (replace-match "" t nil string))))
  1734. (concat string term)))
  1735. (defun org-number-to-counter (n type)
  1736. "Concert number N to a string counter, according to TYPE.
  1737. TYPE must be a string, any of:
  1738. 1 number
  1739. A A,B,....
  1740. a a,b,....
  1741. I upper case roman numeral
  1742. i lower case roman numeral"
  1743. (cond
  1744. ((equal type "1") (number-to-string n))
  1745. ((equal type "A") (char-to-string (+ ?A n -1)))
  1746. ((equal type "a") (char-to-string (+ ?a n -1)))
  1747. ((equal type "I") (org-number-to-roman n))
  1748. ((equal type "i") (downcase (org-number-to-roman n)))
  1749. (t (error "Invalid counter type `%s'" type))))
  1750. (defun org-number-to-roman (n)
  1751. "Convert integer N into a roman numeral."
  1752. (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
  1753. ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
  1754. ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
  1755. ( 1 . "I")))
  1756. (res ""))
  1757. (if (<= n 0)
  1758. (number-to-string n)
  1759. (while roman
  1760. (if (>= n (caar roman))
  1761. (setq n (- n (caar roman))
  1762. res (concat res (cdar roman)))
  1763. (pop roman)))
  1764. res)))
  1765. ;;; Macros
  1766. (defun org-export-preprocess-apply-macros ()
  1767. "Replace macro references."
  1768. (goto-char (point-min))
  1769. (let (sy val key)
  1770. (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t)
  1771. (setq key (downcase (match-string 1)))
  1772. (when (setq val (or (plist-get org-export-opt-plist
  1773. (intern (concat ":macro-" key)))
  1774. (plist-get org-export-opt-plist
  1775. (intern (concat ":" key)))))
  1776. (and (stringp val)
  1777. (replace-match val t t))))))
  1778. (defun org-export-apply-macros-in-string (s)
  1779. "Apply the macros in string S."
  1780. (when s
  1781. (with-temp-buffer
  1782. (insert s)
  1783. (org-export-preprocess-apply-macros)
  1784. (buffer-string))))
  1785. ;;; Include files
  1786. (defun org-export-handle-include-files ()
  1787. "Include the contents of include files, with proper formatting."
  1788. (let ((case-fold-search t)
  1789. params file markup lang start end prefix prefix1 switches)
  1790. (goto-char (point-min))
  1791. (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
  1792. (setq params (read (concat "(" (match-string 1) ")"))
  1793. prefix (org-get-and-remove-property 'params :prefix)
  1794. prefix1 (org-get-and-remove-property 'params :prefix1)
  1795. file (org-symname-or-string (pop params))
  1796. markup (org-symname-or-string (pop params))
  1797. lang (and (member markup '("src" "SRC"))
  1798. (org-symname-or-string (pop params)))
  1799. switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
  1800. (delete-region (match-beginning 0) (match-end 0))
  1801. (if (or (not file)
  1802. (not (file-exists-p file))
  1803. (not (file-readable-p file)))
  1804. (insert (format "CANNOT INCLUDE FILE %s" file))
  1805. (when markup
  1806. (if (equal (downcase markup) "src")
  1807. (setq start (format "#+begin_src %s %s\n"
  1808. (or lang "fundamental")
  1809. (or switches ""))
  1810. end "#+end_src")
  1811. (setq start (format "#+begin_%s %s\n" markup switches)
  1812. end (format "#+end_%s" markup))))
  1813. (insert (or start ""))
  1814. (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
  1815. (or (bolp) (newline))
  1816. (insert (or end ""))))))
  1817. (defun org-get-file-contents (file &optional prefix prefix1)
  1818. "Get the contents of FILE and return them as a string.
  1819. If PREFIX is a string, prepend it to each line. If PREFIX1
  1820. is a string, prepend it to the first line instead of PREFIX."
  1821. (with-temp-buffer
  1822. (insert-file-contents file)
  1823. (when (or prefix prefix1)
  1824. (goto-char (point-min))
  1825. (while (not (eobp))
  1826. (insert (or prefix1 prefix))
  1827. (setq prefix1 nil)
  1828. (beginning-of-line 2)))
  1829. (buffer-string)))
  1830. (defun org-get-and-remove-property (listvar prop)
  1831. "Check if the value of LISTVAR contains PROP as a property.
  1832. If yes, return the value of that property (i.e. the element following
  1833. in the list) and remove property and value from the list in LISTVAR."
  1834. (let ((list (symbol-value listvar)) m v)
  1835. (when (setq m (member prop list))
  1836. (setq v (nth 1 m))
  1837. (if (equal (car list) prop)
  1838. (set listvar (cddr list))
  1839. (setcdr (nthcdr (- (length list) (length m) 1) list)
  1840. (cddr m))
  1841. (set listvar list)))
  1842. v))
  1843. (defun org-symname-or-string (s)
  1844. (if (symbolp s)
  1845. (if s (symbol-name s) s)
  1846. s))
  1847. ;;; Fontification and line numbers for code examples
  1848. (defvar org-export-last-code-line-counter-value 0)
  1849. (defun org-export-replace-src-segments-and-examples (backend)
  1850. "Replace source code segments with special code for export."
  1851. (setq org-export-last-code-line-counter-value 0)
  1852. (let ((case-fold-search t)
  1853. lang code trans opts)
  1854. (goto-char (point-min))
  1855. (while (re-search-forward
  1856. "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
  1857. nil t)
  1858. (if (match-end 1)
  1859. ;; src segments
  1860. (setq lang (match-string 2)
  1861. opts (match-string 3)
  1862. code (match-string 4))
  1863. (setq lang nil
  1864. opts (match-string 6)
  1865. code (match-string 7)))
  1866. (setq trans (org-export-format-source-code-or-example
  1867. backend lang code opts))
  1868. (replace-match trans t t))))
  1869. (defvar htmlp) ;; dynamically scoped
  1870. (defvar latexp) ;; dynamically scoped
  1871. (defun org-export-format-source-code-or-example (backend
  1872. lang code &optional opts)
  1873. "Format CODE from language LANG and return it formatted for export.
  1874. If LANG is nil, do not add any fontification.
  1875. OPTS contains formatting optons, like `-n' for triggering numbering lines,
  1876. and `+n' for continuing previous numering.
  1877. Code formatting according to language currently only works for HTML.
  1878. Numbering lines works for all three major backends (html, latex, and ascii)."
  1879. (save-match-data
  1880. (let (num cont rtn rpllbl keepp textareap cols rows fmt)
  1881. (setq opts (or opts "")
  1882. num (string-match "[-+]n\\>" opts)
  1883. cont (string-match "\\+n\\>" opts)
  1884. rpllbl (string-match "-r\\>" opts)
  1885. keepp (string-match "-k\\>" opts)
  1886. textareap (string-match "-t\\>" opts)
  1887. cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
  1888. (string-to-number (match-string 1 opts))
  1889. 80)
  1890. rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
  1891. (string-to-number (match-string 1 opts))
  1892. (org-count-lines code))
  1893. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  1894. (match-string 1 opts)))
  1895. (when (and textareap (eq backend 'html))
  1896. ;; we cannot use numbering or highlighting.
  1897. (setq num nil cont nil lang nil))
  1898. (if keepp (setq rpllbl 'keep))
  1899. (setq rtn code)
  1900. (when (equal lang "org")
  1901. (setq rtn (with-temp-buffer
  1902. (insert rtn)
  1903. ;; Free up the protected lines
  1904. (goto-char (point-min))
  1905. (while (re-search-forward "^," nil t)
  1906. (replace-match "")
  1907. (end-of-line 1))
  1908. (buffer-string))))
  1909. ;; Now backend-specific coding
  1910. (cond
  1911. ((eq backend 'docbook)
  1912. (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
  1913. (concat "\n#+BEGIN_DOCBOOK\n"
  1914. (org-add-props (concat "<programlisting><![CDATA["
  1915. rtn
  1916. "]]>\n</programlisting>\n")
  1917. '(org-protected t))
  1918. "#+END_DOCBOOK\n"))
  1919. ((eq backend 'html)
  1920. ;; We are exporting to HTML
  1921. (when lang
  1922. (require 'htmlize nil t)
  1923. (when (not (fboundp 'htmlize-region-for-paste))
  1924. ;; we do not have htmlize.el, or an old version of it
  1925. (setq lang nil)
  1926. (message
  1927. "htmlize.el 1.34 or later is needed for source code formatting")))
  1928. (if lang
  1929. (let* ((mode (and lang (intern (concat lang "-mode"))))
  1930. (org-inhibit-startup t)
  1931. (org-startup-folded nil))
  1932. (setq rtn
  1933. (with-temp-buffer
  1934. (insert rtn)
  1935. (if (functionp mode)
  1936. (funcall mode)
  1937. (fundamental-mode))
  1938. (font-lock-fontify-buffer)
  1939. (set-buffer-modified-p nil)
  1940. (org-export-htmlize-region-for-paste
  1941. (point-min) (point-max))))
  1942. (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
  1943. (setq rtn (replace-match
  1944. (format "<pre class=\"src src-%s\">\n" lang)
  1945. t t rtn))))
  1946. (if textareap
  1947. (setq rtn (concat
  1948. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
  1949. cols rows)
  1950. rtn "</textarea>\n</p>\n"))
  1951. (with-temp-buffer
  1952. (insert rtn)
  1953. (goto-char (point-min))
  1954. (while (re-search-forward "[<>&]" nil t)
  1955. (replace-match (cdr (assq (char-before)
  1956. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  1957. t t))
  1958. (setq rtn (buffer-string)))
  1959. (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
  1960. (unless textareap
  1961. (setq rtn (org-export-number-lines rtn 'html 1 1 num
  1962. cont rpllbl fmt)))
  1963. (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
  1964. ((eq backend 'latex)
  1965. (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
  1966. (concat "\n#+BEGIN_LaTeX\n"
  1967. (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
  1968. '(org-protected t))
  1969. "#+END_LaTeX\n\n"))
  1970. ((eq backend 'ascii)
  1971. ;; This is not HTML or LaTeX, so just make it an example.
  1972. (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
  1973. (concat "#+BEGIN_ASCII\n"
  1974. (org-add-props
  1975. (concat
  1976. (mapconcat
  1977. (lambda (l) (concat " " l))
  1978. (org-split-string rtn "\n")
  1979. "\n")
  1980. "\n")
  1981. '(org-protected t))
  1982. "#+END_ASCII\n"))))))
  1983. (defun org-export-number-lines (text backend
  1984. &optional skip1 skip2 number cont
  1985. replace-labels label-format)
  1986. (if (and (not number) (not (eq replace-labels 'keep)))
  1987. (setq replace-labels nil)) ;; must use names if no numbers
  1988. (setq skip1 (or skip1 0) skip2 (or skip2 0))
  1989. (if (not cont) (setq org-export-last-code-line-counter-value 0))
  1990. (with-temp-buffer
  1991. (insert text)
  1992. (goto-char (point-max))
  1993. (skip-chars-backward " \t\n\r")
  1994. (delete-region (point) (point-max))
  1995. (beginning-of-line (- 1 skip2))
  1996. (let* ((last (org-current-line))
  1997. (n org-export-last-code-line-counter-value)
  1998. (nmax (+ n (- last skip1)))
  1999. (fmt (format "%%%dd: " (length (number-to-string nmax))))
  2000. (fm
  2001. (cond
  2002. ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
  2003. fmt))
  2004. ((eq backend 'ascii) fmt)
  2005. ((eq backend 'latex) fmt)
  2006. ((eq backend 'docbook) fmt)
  2007. (t "")))
  2008. (label-format (or label-format org-coderef-label-format))
  2009. (label-pre (if (string-match "%s" label-format)
  2010. (substring label-format 0 (match-beginning 0))
  2011. label-format))
  2012. (label-post (if (string-match "%s" label-format)
  2013. (substring label-format (match-end 0))
  2014. ""))
  2015. (lbl-re
  2016. (concat
  2017. ".*?\\S-.*?\\([ \t]*\\("
  2018. (regexp-quote label-pre)
  2019. "\\([-a-zA-Z0-9_]+\\)"
  2020. (regexp-quote label-post)
  2021. "\\)\\)"))
  2022. ref)
  2023. (goto-line (1+ skip1))
  2024. (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
  2025. (if number
  2026. (insert (format fm (incf n)))
  2027. (forward-char 1))
  2028. (when (and (not (eq replace-labels 'keep))
  2029. (looking-at lbl-re))
  2030. (setq ref (match-string 3))
  2031. (if replace-labels
  2032. (progn
  2033. (delete-region (match-beginning 1) (match-end 1))
  2034. (push (cons ref n) org-export-code-refs))
  2035. (goto-char (match-beginning 2))
  2036. (delete-region (match-beginning 2) (match-end 2))
  2037. (insert "(" ref ")")
  2038. (push (cons ref (concat "(" ref ")")) org-export-code-refs))
  2039. (when (eq backend 'html)
  2040. (save-excursion
  2041. (beginning-of-line 1)
  2042. (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
  2043. ref))
  2044. (end-of-line 1)
  2045. (insert "</span>")))))
  2046. (setq org-export-last-code-line-counter-value n)
  2047. (goto-char (point-max))
  2048. (newline)
  2049. (buffer-string))))
  2050. (defun org-search-todo-below (line lines level)
  2051. "Search the subtree below LINE for any TODO entries."
  2052. (let ((rest (cdr (memq line lines)))
  2053. (re org-todo-line-regexp)
  2054. line lv todo)
  2055. (catch 'exit
  2056. (while (setq line (pop rest))
  2057. (if (string-match re line)
  2058. (progn
  2059. (setq lv (- (match-end 1) (match-beginning 1))
  2060. todo (and (match-beginning 2)
  2061. (not (member (match-string 2 line)
  2062. org-done-keywords))))
  2063. ; TODO, not DONE
  2064. (if (<= lv level) (throw 'exit nil))
  2065. (if todo (throw 'exit t))))))))
  2066. ;;;###autoload
  2067. (defun org-export-visible (type arg)
  2068. "Create a copy of the visible part of the current buffer, and export it.
  2069. The copy is created in a temporary buffer and removed after use.
  2070. TYPE is the final key (as a string) that also select the export command in
  2071. the `C-c C-e' export dispatcher.
  2072. As a special case, if the you type SPC at the prompt, the temporary
  2073. org-mode file will not be removed but presented to you so that you can
  2074. continue to use it. The prefix arg ARG is passed through to the exporting
  2075. command."
  2076. (interactive
  2077. (list (progn
  2078. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
  2079. (read-char-exclusive))
  2080. current-prefix-arg))
  2081. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
  2082. (error "Invalid export key"))
  2083. (let* ((binding (cdr (assoc type
  2084. '((?a . org-export-as-ascii)
  2085. (?\C-a . org-export-as-ascii)
  2086. (?b . org-export-as-html-and-open)
  2087. (?\C-b . org-export-as-html-and-open)
  2088. (?h . org-export-as-html)
  2089. (?H . org-export-as-html-to-buffer)
  2090. (?R . org-export-region-as-html)
  2091. (?D . org-export-as-docbook)
  2092. (?x . org-export-as-xoxo)))))
  2093. (keepp (equal type ?\ ))
  2094. (file buffer-file-name)
  2095. (buffer (get-buffer-create "*Org Export Visible*"))
  2096. s e)
  2097. ;; Need to hack the drawers here.
  2098. (save-excursion
  2099. (goto-char (point-min))
  2100. (while (re-search-forward org-drawer-regexp nil t)
  2101. (goto-char (match-beginning 1))
  2102. (or (org-invisible-p) (org-flag-drawer nil))))
  2103. (with-current-buffer buffer (erase-buffer))
  2104. (save-excursion
  2105. (setq s (goto-char (point-min)))
  2106. (while (not (= (point) (point-max)))
  2107. (goto-char (org-find-invisible))
  2108. (append-to-buffer buffer s (point))
  2109. (setq s (goto-char (org-find-visible))))
  2110. (org-cycle-hide-drawers 'all)
  2111. (goto-char (point-min))
  2112. (unless keepp
  2113. ;; Copy all comment lines to the end, to make sure #+ settings are
  2114. ;; still available for the second export step. Kind of a hack, but
  2115. ;; does do the trick.
  2116. (if (looking-at "#[^\r\n]*")
  2117. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  2118. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  2119. (append-to-buffer buffer (1+ (match-beginning 0))
  2120. (min (point-max) (1+ (match-end 0))))))
  2121. (set-buffer buffer)
  2122. (let ((buffer-file-name file)
  2123. (org-inhibit-startup t))
  2124. (org-mode)
  2125. (show-all)
  2126. (unless keepp (funcall binding arg))))
  2127. (if (not keepp)
  2128. (kill-buffer buffer)
  2129. (switch-to-buffer-other-window buffer)
  2130. (goto-char (point-min)))))
  2131. (defun org-find-visible ()
  2132. (let ((s (point)))
  2133. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2134. (get-char-property s 'invisible)))
  2135. s))
  2136. (defun org-find-invisible ()
  2137. (let ((s (point)))
  2138. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2139. (not (get-char-property s 'invisible))))
  2140. s))
  2141. (defvar org-archive-location) ;; gets loaded with the org-archive require.
  2142. (defun org-get-current-options ()
  2143. "Return a string with current options as keyword options.
  2144. Does include HTML export options as well as TODO and CATEGORY stuff."
  2145. (require 'org-archive)
  2146. (format
  2147. "#+TITLE: %s
  2148. #+AUTHOR: %s
  2149. #+EMAIL: %s
  2150. #+DATE: %s
  2151. #+DESCRIPTION:
  2152. #+KEYWORDS:
  2153. #+LANGUAGE: %s
  2154. #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
  2155. #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
  2156. %s
  2157. #+EXPORT_SELECT_TAGS: %s
  2158. #+EXPORT_EXCLUDE_TAGS: %s
  2159. #+LINK_UP: %s
  2160. #+LINK_HOME: %s
  2161. #+CATEGORY: %s
  2162. #+SEQ_TODO: %s
  2163. #+TYP_TODO: %s
  2164. #+PRIORITIES: %c %c %c
  2165. #+DRAWERS: %s
  2166. #+STARTUP: %s %s %s %s %s
  2167. #+TAGS: %s
  2168. #+FILETAGS: %s
  2169. #+ARCHIVE: %s
  2170. #+LINK: %s
  2171. "
  2172. (buffer-name) (user-full-name) user-mail-address
  2173. (format-time-string (substring (car org-time-stamp-formats) 1 -1))
  2174. org-export-default-language
  2175. org-export-headline-levels
  2176. org-export-with-section-numbers
  2177. org-export-with-toc
  2178. org-export-preserve-breaks
  2179. org-export-html-expand
  2180. org-export-with-fixed-width
  2181. org-export-with-tables
  2182. org-export-with-sub-superscripts
  2183. org-export-with-special-strings
  2184. org-export-with-footnotes
  2185. org-export-with-emphasize
  2186. org-export-with-timestamps
  2187. org-export-with-TeX-macros
  2188. org-export-with-LaTeX-fragments
  2189. org-export-skip-text-before-1st-heading
  2190. org-export-with-drawers
  2191. org-export-with-todo-keywords
  2192. org-export-with-priority
  2193. org-export-with-tags
  2194. (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
  2195. (mapconcat 'identity org-export-select-tags " ")
  2196. (mapconcat 'identity org-export-exclude-tags " ")
  2197. org-export-html-link-up
  2198. org-export-html-link-home
  2199. (or (ignore-errors
  2200. (file-name-sans-extension
  2201. (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
  2202. "NOFILENAME")
  2203. "TODO FEEDBACK VERIFY DONE"
  2204. "Me Jason Marie DONE"
  2205. org-highest-priority org-lowest-priority org-default-priority
  2206. (mapconcat 'identity org-drawers " ")
  2207. (cdr (assoc org-startup-folded
  2208. '((nil . "showall") (t . "overview") (content . "content"))))
  2209. (if org-odd-levels-only "odd" "oddeven")
  2210. (if org-hide-leading-stars "hidestars" "showstars")
  2211. (if org-startup-align-all-tables "align" "noalign")
  2212. (cond ((eq org-log-done t) "logdone")
  2213. ((equal org-log-done 'note) "lognotedone")
  2214. ((not org-log-done) "nologdone"))
  2215. (or (mapconcat (lambda (x)
  2216. (cond
  2217. ((equal '(:startgroup) x) "{")
  2218. ((equal '(:endgroup) x) "}")
  2219. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  2220. (t (car x))))
  2221. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  2222. (mapconcat 'identity org-file-tags " ")
  2223. org-archive-location
  2224. "org file:~/org/%s.org"
  2225. ))
  2226. ;;;###autoload
  2227. (defun org-insert-export-options-template ()
  2228. "Insert into the buffer a template with information for exporting."
  2229. (interactive)
  2230. (if (not (bolp)) (newline))
  2231. (let ((s (org-get-current-options)))
  2232. (and (string-match "#\\+CATEGORY" s)
  2233. (setq s (substring s 0 (match-beginning 0))))
  2234. (insert s)))
  2235. (defvar org-table-colgroup-info nil)
  2236. (defun org-table-clean-before-export (lines &optional maybe-quoted)
  2237. "Check if the table has a marking column.
  2238. If yes remove the column and the special lines."
  2239. (setq org-table-colgroup-info nil)
  2240. (if (memq nil
  2241. (mapcar
  2242. (lambda (x) (or (string-match "^[ \t]*|-" x)
  2243. (string-match
  2244. (if maybe-quoted
  2245. "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
  2246. "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
  2247. x)))
  2248. lines))
  2249. (progn
  2250. (setq org-table-clean-did-remove-column nil)
  2251. (delq nil
  2252. (mapcar
  2253. (lambda (x)
  2254. (cond
  2255. ((string-match "^[ \t]*| */ *|" x)
  2256. (setq org-table-colgroup-info
  2257. (mapcar (lambda (x)
  2258. (cond ((member x '("<" "&lt;")) :start)
  2259. ((member x '(">" "&gt;")) :end)
  2260. ((member x '("<>" "&lt;&gt;")) :startend)
  2261. (t nil)))
  2262. (org-split-string x "[ \t]*|[ \t]*")))
  2263. nil)
  2264. (t x)))
  2265. lines)))
  2266. (setq org-table-clean-did-remove-column t)
  2267. (delq nil
  2268. (mapcar
  2269. (lambda (x)
  2270. (cond
  2271. ((string-match "^[ \t]*| */ *|" x)
  2272. (setq org-table-colgroup-info
  2273. (mapcar (lambda (x)
  2274. (cond ((member x '("<" "&lt;")) :start)
  2275. ((member x '(">" "&gt;")) :end)
  2276. ((member x '("<>" "&lt;&gt;")) :startend)
  2277. (t nil)))
  2278. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  2279. nil)
  2280. ((string-match "^[ \t]*| *[!_^/] *|" x)
  2281. nil) ; ignore this line
  2282. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  2283. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  2284. ;; remove the first column
  2285. (replace-match "\\1|" t nil x))))
  2286. lines))))
  2287. (defun org-export-cleanup-toc-line (s)
  2288. "Remove tags and timestamps from lines going into the toc."
  2289. (when (memq org-export-with-tags '(not-in-toc nil))
  2290. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  2291. (setq s (replace-match "" t t s))))
  2292. (when org-export-remove-timestamps-from-toc
  2293. (while (string-match org-maybe-keyword-time-regexp s)
  2294. (setq s (replace-match "" t t s))))
  2295. (while (string-match org-bracket-link-regexp s)
  2296. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  2297. t t s)))
  2298. s)
  2299. (defun org-create-multibrace-regexp (left right n)
  2300. "Create a regular expression which will match a balanced sexp.
  2301. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  2302. as single character strings.
  2303. The regexp returned will match the entire expression including the
  2304. delimiters. It will also define a single group which contains the
  2305. match except for the outermost delimiters. The maximum depth of
  2306. stacked delimiters is N. Escaping delimiters is not possible."
  2307. (let* ((nothing (concat "[^" left right "]*?"))
  2308. (or "\\|")
  2309. (re nothing)
  2310. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  2311. (while (> n 1)
  2312. (setq n (1- n)
  2313. re (concat re or next)
  2314. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  2315. (concat left "\\(" re "\\)" right)))
  2316. (defvar org-match-substring-regexp
  2317. (concat
  2318. "\\([^\\]\\)\\([_^]\\)\\("
  2319. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2320. "\\|"
  2321. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  2322. "\\|"
  2323. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  2324. "The regular expression matching a sub- or superscript.")
  2325. (defvar org-match-substring-with-braces-regexp
  2326. (concat
  2327. "\\([^\\]\\)\\([_^]\\)\\("
  2328. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2329. "\\)")
  2330. "The regular expression matching a sub- or superscript, forcing braces.")
  2331. (defun org-get-text-property-any (pos prop &optional object)
  2332. (or (get-text-property pos prop object)
  2333. (and (setq pos (next-single-property-change pos prop object))
  2334. (get-text-property pos prop object))))
  2335. (defun org-export-get-coderef-format (path desc)
  2336. (save-match-data
  2337. (if (and desc (string-match
  2338. (regexp-quote (concat "(" path ")"))
  2339. desc))
  2340. (replace-match "%s" t t desc)
  2341. "%s")))
  2342. (provide 'org-exp)
  2343. ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
  2344. ;;; org-exp.el ends here