org-exp.el 102 KB

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