org-exp.el 102 KB

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