org-exp.el 95 KB

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