org-exp.el 99 KB

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