org-exp.el 102 KB

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