org-exp.el 103 KB

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