org-exp.el 93 KB

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