org-exp.el 93 KB

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