org-exp.el 95 KB

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