org-exp.el 100 KB

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