org-exp.el 103 KB

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