org-exp.el 102 KB

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