org-exp.el 104 KB

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