org-exp.el 102 KB

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