org-exp.el 102 KB

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