org-exp.el 111 KB

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