org-exp.el 94 KB

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