org-exp.el 116 KB

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