org-exp.el 103 KB

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