org-exp.el 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170
  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 "\\(\\`\\|[ \t]\\)"
  754. (regexp-quote (nth 1 o))
  755. ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
  756. options))
  757. (setq p (plist-put p (car o)
  758. (car (read-from-string
  759. (match-string 2 options))))))))))
  760. p)
  761. (defun org-export-add-subtree-options (p pos)
  762. "Add options in subtree at position POS to property list P."
  763. (save-excursion
  764. (goto-char pos)
  765. (when (org-at-heading-p)
  766. (let (a)
  767. ;; This is actually read in `org-export-get-title-from-subtree'
  768. ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
  769. ;; (setq p (plist-put p :title a)))
  770. (when (setq a (org-entry-get pos "EXPORT_TEXT"))
  771. (setq p (plist-put p :text a)))
  772. (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
  773. (setq p (plist-put p :author a)))
  774. (when (setq a (org-entry-get pos "EXPORT_DATE"))
  775. (setq p (plist-put p :date a)))
  776. (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
  777. (setq p (org-export-add-options-to-plist p a)))))
  778. p))
  779. (defun org-export-directory (type plist)
  780. (let* ((val (plist-get plist :publishing-directory))
  781. (dir (if (listp val)
  782. (or (cdr (assoc type val)) ".")
  783. val)))
  784. dir))
  785. (defun org-export-process-option-filters (plist)
  786. (let ((functions org-export-options-filters) f)
  787. (while (setq f (pop functions))
  788. (setq plist (funcall f plist))))
  789. plist)
  790. ;;;###autoload
  791. (defun org-export (&optional arg)
  792. "Export dispatcher for Org-mode.
  793. When `org-export-run-in-background' is non-nil, try to run the command
  794. in the background. This will be done only for commands that write
  795. to a file. For details see the docstring of `org-export-run-in-background'.
  796. The prefix argument ARG will be passed to the exporter. However, if
  797. ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
  798. that means to inverse the
  799. value of `org-export-run-in-background'.
  800. If `org-export-initial-scope' is set to 'subtree, try to export
  801. the current subtree, otherwise try to export the whole buffer.
  802. Pressing `1' will switch between these two options."
  803. (interactive "P")
  804. (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
  805. (subtree-p (or (org-region-active-p)
  806. (eq org-export-initial-scope 'subtree)))
  807. (help "[t] insert the export option template
  808. \[v] limit export to visible part of outline tree
  809. \[1] switch buffer/subtree export
  810. \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
  811. \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
  812. \[h] export as HTML [H] to temporary buffer [R] export region
  813. \[b] export as HTML and open in browser
  814. \[l] export as LaTeX [L] to temporary buffer
  815. \[p] export as LaTeX and process to PDF [d] ... and open PDF file
  816. \[D] export as DocBook [V] export as DocBook, process to PDF, and open
  817. \[j] export as TaskJuggler [J] ... and open
  818. \[m] export as Freemind mind map
  819. \[x] export as XOXO
  820. \[g] export using Wes Hardaker's generic exporter
  821. \[i] export current file as iCalendar file
  822. \[I] export all agenda files as iCalendar files [c] ...as one combined file
  823. \[F] publish current file [P] publish current project
  824. \[X] publish a project... [E] publish every projects")
  825. (cmds
  826. '((?t org-insert-export-options-template nil)
  827. (?v org-export-visible nil)
  828. (?a org-export-as-ascii t)
  829. (?A org-export-as-ascii-to-buffer t)
  830. (?n org-export-as-latin1 t)
  831. (?N org-export-as-latin1-to-buffer t)
  832. (?u org-export-as-utf8 t)
  833. (?U org-export-as-utf8-to-buffer t)
  834. (?h org-export-as-html t)
  835. (?b org-export-as-html-and-open t)
  836. (?H org-export-as-html-to-buffer nil)
  837. (?R org-export-region-as-html nil)
  838. (?x org-export-as-xoxo t)
  839. (?g org-export-generic t)
  840. (?D org-export-as-docbook t)
  841. (?V org-export-as-docbook-pdf-and-open t)
  842. (?j org-export-as-taskjuggler t)
  843. (?J org-export-as-taskjuggler-and-open t)
  844. (?m org-export-as-freemind t)
  845. (?l org-export-as-latex t)
  846. (?p org-export-as-pdf t)
  847. (?d org-export-as-pdf-and-open t)
  848. (?L org-export-as-latex-to-buffer nil)
  849. (?i org-export-icalendar-this-file t)
  850. (?I org-export-icalendar-all-agenda-files t)
  851. (?c org-export-icalendar-combine-agenda-files t)
  852. (?F org-publish-current-file t)
  853. (?P org-publish-current-project t)
  854. (?X org-publish t)
  855. (?E org-publish-all t)))
  856. r1 r2 ass
  857. (cpos (point)) (cbuf (current-buffer)) bpos)
  858. (save-excursion
  859. (save-window-excursion
  860. (if subtree-p
  861. (message "Export subtree: ")
  862. (message "Export buffer: "))
  863. (delete-other-windows)
  864. (with-output-to-temp-buffer "*Org Export/Publishing Help*"
  865. (princ help))
  866. (org-fit-window-to-buffer (get-buffer-window
  867. "*Org Export/Publishing Help*"))
  868. (while (eq (setq r1 (read-char-exclusive)) ?1)
  869. (cond (subtree-p
  870. (setq subtree-p nil)
  871. (message "Export buffer: "))
  872. ((not subtree-p)
  873. (setq subtree-p t)
  874. (message "Export subtree: "))))
  875. (when (eq r1 ?\ )
  876. (let ((case-fold-search t)
  877. (end (save-excursion (while (org-up-heading-safe)) (point))))
  878. (outline-next-heading)
  879. (if (re-search-backward
  880. "^[ \t]+\\(:latex_class:\\|:export_title:\\|:export_file_name:\\)[ \t]+\\S-"
  881. end t)
  882. (progn
  883. (org-back-to-heading t)
  884. (setq subtree-p t)
  885. (setq bpos (point))
  886. (message "Select command (for subtree): ")
  887. (setq r1 (read-char-exclusive)))
  888. (error "No enclosing node with LaTeX_CLASS or EXPORT_TITLE or EXPORT_FILE_NAME")
  889. )))))
  890. (redisplay)
  891. (and bpos (goto-char bpos))
  892. (setq r2 (if (< r1 27) (+ r1 96) r1))
  893. (unless (setq ass (assq r2 cmds))
  894. (error "No command associated with key %c" r1))
  895. (if (and bg (nth 2 ass)
  896. (not (buffer-base-buffer))
  897. (not (org-region-active-p)))
  898. ;; execute in background
  899. (let ((p (start-process
  900. (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
  901. "*Org Processes*"
  902. (expand-file-name invocation-name invocation-directory)
  903. "-batch"
  904. "-l" user-init-file
  905. "--eval" "(require 'org-exp)"
  906. "--eval" "(setq org-wait .2)"
  907. (buffer-file-name)
  908. "-f" (symbol-name (nth 1 ass)))))
  909. (set-process-sentinel p 'org-export-process-sentinel)
  910. (message "Background process \"%s\": started" p))
  911. ;; background processing not requested, or not possible
  912. (if subtree-p (progn (org-mark-subtree) (org-activate-mark)))
  913. (call-interactively (nth 1 ass))
  914. (when (and bpos (get-buffer-window cbuf))
  915. (let ((cw (selected-window)))
  916. (select-window (get-buffer-window cbuf))
  917. (goto-char cpos)
  918. (deactivate-mark)
  919. (select-window cw))))))
  920. (defun org-export-process-sentinel (process status)
  921. (if (string-match "\n+\\'" status)
  922. (setq status (substring status 0 -1)))
  923. (message "Background process \"%s\": %s" process status))
  924. ;;; General functions for all backends
  925. (defvar org-export-target-aliases nil
  926. "Alist of targets with invisible aliases.")
  927. (defvar org-export-preferred-target-alist nil
  928. "Alist of section id's with preferred aliases.")
  929. (defvar org-export-id-target-alist nil
  930. "Alist of section id's with preferred aliases.")
  931. (defvar org-export-code-refs nil
  932. "Alist of code references and line numbers.")
  933. (defun org-export-preprocess-string (string &rest parameters)
  934. "Cleanup STRING so that the true exported has a more consistent source.
  935. This function takes STRING, which should be a buffer-string of an org-file
  936. to export. It then creates a temporary buffer where it does its job.
  937. The result is then again returned as a string, and the exporter works
  938. on this string to produce the exported version."
  939. (interactive)
  940. (let* ((org-export-current-backend (plist-get parameters :for-backend))
  941. (archived-trees (plist-get parameters :archived-trees))
  942. (inhibit-read-only t)
  943. (drawers org-drawers)
  944. (outline-regexp "\\*+ ")
  945. (source-buffer (current-buffer))
  946. target-alist rtn)
  947. (setq org-export-target-aliases nil
  948. org-export-preferred-target-alist nil
  949. org-export-id-target-alist nil
  950. org-export-code-refs nil)
  951. (with-current-buffer (get-buffer-create " org-mode-tmp")
  952. (erase-buffer)
  953. (insert string)
  954. (setq case-fold-search t)
  955. (let ((inhibit-read-only t))
  956. (remove-text-properties (point-min) (point-max)
  957. '(read-only t)))
  958. ;; Remove license-to-kill stuff
  959. ;; The caller marks some stuff for killing, stuff that has been
  960. ;; used to create the page title, for example.
  961. (org-export-kill-licensed-text)
  962. (let ((org-inhibit-startup t)) (org-mode))
  963. (setq case-fold-search t)
  964. (org-clone-local-variables source-buffer "^\\(org-\\|orgtbl-\\)")
  965. (org-install-letbind)
  966. ;; Call the hook
  967. (run-hooks 'org-export-preprocess-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. ;; Change lists ending. Other parts of export may insert blank
  973. ;; lines and lists' structure could be altered.
  974. (org-export-mark-list-end)
  975. ;; Process the macros
  976. (org-export-preprocess-apply-macros)
  977. (run-hooks 'org-export-preprocess-after-macros-hook)
  978. ;; Get rid of archived trees
  979. (org-export-remove-archived-trees archived-trees)
  980. ;; Remove comment environment and comment subtrees
  981. (org-export-remove-comment-blocks-and-subtrees)
  982. ;; Get rid of excluded trees, and call a hook
  983. (org-export-handle-export-tags (plist-get parameters :select-tags)
  984. (plist-get parameters :exclude-tags))
  985. (run-hooks 'org-export-preprocess-after-tree-selection-hook)
  986. ;; Get rid of tasks, depending on configuration
  987. (org-export-remove-tasks (plist-get parameters :tasks))
  988. ;; Export code blocks
  989. (org-export-blocks-preprocess)
  990. ;; Mark lists with properties
  991. (org-export-mark-list-properties)
  992. ;; Handle source code snippets
  993. (org-export-replace-src-segments-and-examples)
  994. ;; Protect short examples marked by a leading colon
  995. (org-export-protect-colon-examples)
  996. ;; Protected spaces
  997. (org-export-convert-protected-spaces)
  998. ;; Normalize footnotes
  999. (when (plist-get parameters :footnotes)
  1000. (org-footnote-normalize nil t))
  1001. ;; Find all headings and compute the targets for them
  1002. (setq target-alist (org-export-define-heading-targets target-alist))
  1003. (run-hooks 'org-export-preprocess-after-headline-targets-hook)
  1004. ;; Find HTML special classes for headlines
  1005. (org-export-remember-html-container-classes)
  1006. ;; Get rid of drawers
  1007. (org-export-remove-or-extract-drawers
  1008. drawers (plist-get parameters :drawers))
  1009. ;; Get the correct stuff before the first headline
  1010. (when (plist-get parameters :skip-before-1st-heading)
  1011. (goto-char (point-min))
  1012. (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
  1013. (delete-region (point-min) (match-beginning 0))
  1014. (goto-char (point-min))
  1015. (insert "\n")))
  1016. (when (plist-get parameters :add-text)
  1017. (goto-char (point-min))
  1018. (insert (plist-get parameters :add-text) "\n"))
  1019. ;; Remove todo-keywords before exporting, if the user has requested so
  1020. (org-export-remove-headline-metadata parameters)
  1021. ;; Find targets in comments and move them out of comments,
  1022. ;; but mark them as targets that should be invisible
  1023. (setq target-alist (org-export-handle-invisible-targets target-alist))
  1024. ;; Select and protect backend specific stuff, throw away stuff
  1025. ;; that is specific for other backends
  1026. (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
  1027. (org-export-select-backend-specific-text)
  1028. ;; Protect quoted subtrees
  1029. (org-export-protect-quoted-subtrees)
  1030. ;; Remove clock lines
  1031. (org-export-remove-clock-lines)
  1032. ;; Protect verbatim elements
  1033. (org-export-protect-verbatim)
  1034. ;; Blockquotes, verse, and center
  1035. (org-export-mark-blockquote-verse-center)
  1036. (run-hooks 'org-export-preprocess-after-blockquote-hook)
  1037. ;; Remove timestamps, if the user has requested so
  1038. (unless (plist-get parameters :timestamps)
  1039. (org-export-remove-timestamps))
  1040. ;; Attach captions to the correct object
  1041. (setq target-alist (org-export-attach-captions-and-attributes target-alist))
  1042. ;; Find matches for radio targets and turn them into internal links
  1043. (org-export-mark-radio-links)
  1044. (run-hooks 'org-export-preprocess-after-radio-targets-hook)
  1045. ;; Find all links that contain a newline and put them into a single line
  1046. (org-export-concatenate-multiline-links)
  1047. ;; Normalize links: Convert angle and plain links into bracket links
  1048. ;; and expand link abbreviations
  1049. (run-hooks 'org-export-preprocess-before-normalizing-links-hook)
  1050. (org-export-normalize-links)
  1051. ;; Find all internal links. If they have a fuzzy match (i.e. not
  1052. ;; a *dedicated* target match, let the link point to the
  1053. ;; corresponding section.
  1054. (org-export-target-internal-links target-alist)
  1055. ;; Find multiline emphasis and put them into single line
  1056. (when (plist-get parameters :emph-multiline)
  1057. (org-export-concatenate-multiline-emphasis))
  1058. ;; Remove special table lines, and store alignment information
  1059. (org-store-forced-table-alignment)
  1060. (when org-export-table-remove-special-lines
  1061. (org-export-remove-special-table-lines))
  1062. ;; Another hook
  1063. (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
  1064. ;; Backend-specific preprocessing
  1065. (let* ((backend-name (symbol-name org-export-current-backend))
  1066. (f (intern (format "org-export-%s-preprocess" backend-name))))
  1067. (require (intern (concat "org-" backend-name)) nil)
  1068. (funcall f parameters))
  1069. ;; Remove or replace comments
  1070. (org-export-handle-comments (plist-get parameters :comments))
  1071. ;; Remove #+TBLFM and #+TBLNAME lines
  1072. (org-export-handle-table-metalines)
  1073. ;; Run the final hook
  1074. (run-hooks 'org-export-preprocess-final-hook)
  1075. (setq rtn (buffer-string)))
  1076. (kill-buffer " org-mode-tmp")
  1077. rtn))
  1078. (defun org-export-kill-licensed-text ()
  1079. "Remove all text that is marked with a :org-license-to-kill property."
  1080. (let (p)
  1081. (while (setq p (text-property-any (point-min) (point-max)
  1082. :org-license-to-kill t))
  1083. (delete-region
  1084. p (or (next-single-property-change p :org-license-to-kill)
  1085. (point-max))))))
  1086. (defvar org-export-define-heading-targets-headline-hook nil
  1087. "Hook that is run when a headline was matched during target search.
  1088. This is part of the preprocessing for export.")
  1089. (defun org-export-define-heading-targets (target-alist)
  1090. "Find all headings and define the targets for them.
  1091. The new targets are added to TARGET-ALIST, which is also returned.
  1092. Also find all ID and CUSTOM_ID properties and store them."
  1093. (goto-char (point-min))
  1094. (org-init-section-numbers)
  1095. (let ((re (concat "^" org-outline-regexp
  1096. "\\|"
  1097. "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
  1098. level target last-section-target a id)
  1099. (while (re-search-forward re nil t)
  1100. (org-if-unprotected-at (match-beginning 0)
  1101. (if (match-end 2)
  1102. (progn
  1103. (setq id (org-match-string-no-properties 2))
  1104. (push (cons id target) target-alist)
  1105. (setq a (or (assoc last-section-target org-export-target-aliases)
  1106. (progn
  1107. (push (list last-section-target)
  1108. org-export-target-aliases)
  1109. (car org-export-target-aliases))))
  1110. (push (caar target-alist) (cdr a))
  1111. (when (equal (match-string 1) "CUSTOM_ID")
  1112. (if (not (assoc last-section-target
  1113. org-export-preferred-target-alist))
  1114. (push (cons last-section-target id)
  1115. org-export-preferred-target-alist)))
  1116. (when (equal (match-string 1) "ID")
  1117. (if (not (assoc last-section-target
  1118. org-export-id-target-alist))
  1119. (push (cons last-section-target (concat "ID-" id))
  1120. org-export-id-target-alist))))
  1121. (setq level (org-reduced-level
  1122. (save-excursion (goto-char (point-at-bol))
  1123. (org-outline-level))))
  1124. (setq target (org-solidify-link-text
  1125. (format "sec-%s" (replace-regexp-in-string
  1126. "\\." "-"
  1127. (org-section-number level)))))
  1128. (setq last-section-target target)
  1129. (push (cons target target) target-alist)
  1130. (add-text-properties
  1131. (point-at-bol) (point-at-eol)
  1132. (list 'target target))
  1133. (run-hooks 'org-export-define-heading-targets-headline-hook)))))
  1134. target-alist)
  1135. (defun org-export-handle-invisible-targets (target-alist)
  1136. "Find targets in comments and move them out of comments.
  1137. Mark them as invisible targets."
  1138. (let (target tmp a)
  1139. (goto-char (point-min))
  1140. (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
  1141. ;; Check if the line before or after is a headline with a target
  1142. (if (setq target (or (get-text-property (point-at-bol 0) 'target)
  1143. (get-text-property (point-at-bol 2) 'target)))
  1144. (progn
  1145. ;; use the existing target in a neighboring line
  1146. (setq tmp (match-string 2))
  1147. (replace-match "")
  1148. (and (looking-at "\n") (delete-char 1))
  1149. (push (cons (setq tmp (org-solidify-link-text tmp)) target)
  1150. target-alist)
  1151. (setq a (or (assoc target org-export-target-aliases)
  1152. (progn
  1153. (push (list target) org-export-target-aliases)
  1154. (car org-export-target-aliases))))
  1155. (push tmp (cdr a)))
  1156. ;; Make an invisible target
  1157. (replace-match "\\1(INVISIBLE)"))))
  1158. target-alist)
  1159. (defun org-export-target-internal-links (target-alist)
  1160. "Find all internal links and assign targets to them.
  1161. If a link has a fuzzy match (i.e. not a *dedicated* target match),
  1162. let the link point to the corresponding section.
  1163. This function also handles the id links, if they have a match in
  1164. the current file."
  1165. (goto-char (point-min))
  1166. (while (re-search-forward org-bracket-link-regexp nil t)
  1167. (org-if-unprotected-at (1+ (match-beginning 0))
  1168. (let* ((org-link-search-must-match-exact-headline t)
  1169. (md (match-data))
  1170. (desc (match-end 2))
  1171. (link (org-link-unescape (match-string 1)))
  1172. (slink (org-solidify-link-text link))
  1173. found props pos cref
  1174. (target
  1175. (cond
  1176. ((= (string-to-char link) ?#)
  1177. ;; user wants exactly this link
  1178. link)
  1179. ((cdr (assoc slink target-alist))
  1180. (or (cdr (assoc (assoc slink target-alist)
  1181. org-export-preferred-target-alist))
  1182. (cdr (assoc slink target-alist))))
  1183. ((and (string-match "^id:" link)
  1184. (cdr (assoc (substring link 3) target-alist))))
  1185. ((string-match "^(\\(.*\\))$" link)
  1186. (setq cref (match-string 1 link))
  1187. (concat "coderef:" cref))
  1188. ((string-match org-link-types-re link) nil)
  1189. ((or (file-name-absolute-p link)
  1190. (string-match "^\\." link))
  1191. nil)
  1192. (t
  1193. (let ((org-link-search-inhibit-query t))
  1194. (save-excursion
  1195. (setq found (condition-case nil (org-link-search link)
  1196. (error nil)))
  1197. (when (and found
  1198. (or (org-on-heading-p)
  1199. (not (eq found 'dedicated))))
  1200. (or (get-text-property (point) 'target)
  1201. (get-text-property
  1202. (max (point-min)
  1203. (1- (or (previous-single-property-change
  1204. (point) 'target) 0)))
  1205. 'target)))))))))
  1206. (when target
  1207. (set-match-data md)
  1208. (goto-char (match-beginning 1))
  1209. (setq props (text-properties-at (point)))
  1210. (delete-region (match-beginning 1) (match-end 1))
  1211. (setq pos (point))
  1212. (insert target)
  1213. (unless desc (insert "][" link))
  1214. (add-text-properties pos (point) props))))))
  1215. (defun org-export-remember-html-container-classes ()
  1216. "Store the HTML_CONTAINER_CLASS properties in a text property."
  1217. (goto-char (point-min))
  1218. (let (class)
  1219. (while (re-search-forward
  1220. "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t)
  1221. (setq class (match-string 1))
  1222. (save-excursion
  1223. (org-back-to-heading t)
  1224. (put-text-property (point-at-bol) (point-at-eol) 'html-container-class class)))))
  1225. (defvar org-export-format-drawer-function nil
  1226. "Function to be called to format the contents of a drawer.
  1227. The function must accept three parameters:
  1228. NAME the drawer name, like \"PROPERTIES\"
  1229. CONTENT the content of the drawer.
  1230. You can check the export backend through `org-export-current-backend'.
  1231. The function should return the text to be inserted into the buffer.
  1232. If this is nil, `org-export-format-drawer' is used as a default.")
  1233. (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
  1234. "Remove drawers, or extract and format the content.
  1235. ALL-DRAWERS is a list of all drawer names valid in the current buffer.
  1236. EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
  1237. whose content to keep. Any drawers that are in ALL-DRAWERS but not in
  1238. EXP-DRAWERS will be removed."
  1239. (goto-char (point-min))
  1240. (let ((re (concat "^[ \t]*:\\("
  1241. (mapconcat 'identity all-drawers "\\|")
  1242. "\\):[ \t]*$"))
  1243. name beg beg-content eol content)
  1244. (while (re-search-forward re nil t)
  1245. (org-if-unprotected
  1246. (setq name (match-string 1))
  1247. (setq beg (match-beginning 0)
  1248. beg-content (1+ (point-at-eol))
  1249. eol (point-at-eol))
  1250. (if (not (and (re-search-forward
  1251. "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t)
  1252. (match-end 1)))
  1253. (goto-char eol)
  1254. (goto-char (match-beginning 0))
  1255. (and (looking-at ".*\n?") (replace-match ""))
  1256. (setq content (buffer-substring beg-content (point)))
  1257. (delete-region beg (point))
  1258. (when (or (eq exp-drawers t)
  1259. (member name exp-drawers))
  1260. (setq content (funcall (or org-export-format-drawer-function
  1261. 'org-export-format-drawer)
  1262. name content))
  1263. (insert content)))))))
  1264. (defun org-export-format-drawer (name content)
  1265. "Format the content of a drawer as a colon example."
  1266. (if (string-match "[ \t]+\\'" content)
  1267. (setq content (substring content (match-beginning 0))))
  1268. (while (string-match "\\`[ \t]*\n" content)
  1269. (setq content (substring content (match-end 0))))
  1270. (setq content (org-remove-indentation content))
  1271. (setq content (concat ": " (mapconcat 'identity
  1272. (org-split-string content "\n")
  1273. "\n: ")
  1274. "\n"))
  1275. (setq content (concat " : " (upcase name) "\n" content))
  1276. (org-add-props content nil 'org-protected t))
  1277. (defun org-export-handle-export-tags (select-tags exclude-tags)
  1278. "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
  1279. Both arguments are lists of tags.
  1280. If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
  1281. will be removed.
  1282. After that, all subtrees that are marked by EXCLUDE-TAGS will be
  1283. removed as well."
  1284. (remove-text-properties (point-min) (point-max) '(:org-delete t))
  1285. (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
  1286. select-tags "\\|")
  1287. "\\):"))
  1288. (re-excl (concat ":\\(" (mapconcat 'regexp-quote
  1289. exclude-tags "\\|")
  1290. "\\):"))
  1291. beg end cont)
  1292. (goto-char (point-min))
  1293. (when (and select-tags
  1294. (re-search-forward
  1295. (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
  1296. ;; At least one tree is marked for export, this means
  1297. ;; all the unmarked stuff needs to go.
  1298. ;; Dig out the trees that should be exported
  1299. (goto-char (point-min))
  1300. (outline-next-heading)
  1301. (setq beg (point))
  1302. (put-text-property beg (point-max) :org-delete t)
  1303. (while (re-search-forward re-sel nil t)
  1304. (when (org-on-heading-p)
  1305. (org-back-to-heading)
  1306. (remove-text-properties
  1307. (max (1- (point)) (point-min))
  1308. (setq cont (save-excursion (org-end-of-subtree t t)))
  1309. '(:org-delete t))
  1310. (while (and (org-up-heading-safe)
  1311. (get-text-property (point) :org-delete))
  1312. (remove-text-properties (max (1- (point)) (point-min))
  1313. (point-at-eol) '(:org-delete t)))
  1314. (goto-char cont))))
  1315. ;; Remove the trees explicitly marked for noexport
  1316. (when exclude-tags
  1317. (goto-char (point-min))
  1318. (while (re-search-forward re-excl nil t)
  1319. (when (org-at-heading-p)
  1320. (org-back-to-heading t)
  1321. (setq beg (point))
  1322. (org-end-of-subtree t t)
  1323. (delete-region beg (point))
  1324. (when (featurep 'org-inlinetask)
  1325. (org-inlinetask-remove-END-maybe)))))
  1326. ;; Remove everything that is now still marked for deletion
  1327. (goto-char (point-min))
  1328. (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
  1329. (setq end (or (next-single-property-change beg :org-delete)
  1330. (point-max)))
  1331. (delete-region beg end))))
  1332. (defun org-export-remove-tasks (keep)
  1333. "Remove tasks depending on configuration.
  1334. When KEEP is nil, remove all tasks.
  1335. When KEEP is `todo', remove the tasks that are DONE.
  1336. When KEEP is `done', remove the tasks that are not yet done.
  1337. When it is a list of strings, keep only tasks with these TODO keywords."
  1338. (when (or (listp keep) (memq keep '(todo done nil)))
  1339. (let ((re (concat "^\\*+[ \t]+\\("
  1340. (mapconcat
  1341. 'regexp-quote
  1342. (cond ((not keep) org-todo-keywords-1)
  1343. ((eq keep 'todo) org-done-keywords)
  1344. ((eq keep 'done) org-not-done-keywords)
  1345. ((listp keep)
  1346. (org-delete-all keep (copy-sequence
  1347. org-todo-keywords-1))))
  1348. "\\|")
  1349. "\\)\\($\\|[ \t]\\)"))
  1350. (case-fold-search nil)
  1351. beg)
  1352. (goto-char (point-min))
  1353. (while (re-search-forward re nil t)
  1354. (org-if-unprotected
  1355. (setq beg (match-beginning 0))
  1356. (org-end-of-subtree t t)
  1357. (if (looking-at "^\\*+[ \t]+END[ \t]*$")
  1358. ;; Kill the END line of the inline task
  1359. (goto-char (min (point-max) (1+ (match-end 0)))))
  1360. (delete-region beg (point)))))))
  1361. (defun org-export-remove-archived-trees (export-archived-trees)
  1362. "Remove archived trees.
  1363. When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
  1364. When it is t, the entire archived tree will be exported.
  1365. When it is nil the entire tree including the headline will be removed
  1366. from the buffer."
  1367. (let ((re-archive (concat ":" org-archive-tag ":"))
  1368. a b)
  1369. (when (not (eq export-archived-trees t))
  1370. (goto-char (point-min))
  1371. (while (re-search-forward re-archive nil t)
  1372. (if (not (org-on-heading-p t))
  1373. (goto-char (point-at-eol))
  1374. (beginning-of-line 1)
  1375. (setq a (if export-archived-trees
  1376. (1+ (point-at-eol)) (point))
  1377. b (org-end-of-subtree t))
  1378. (if (> b a) (delete-region a b)))))))
  1379. (defun org-export-remove-headline-metadata (opts)
  1380. "Remove meta data from the headline, according to user options."
  1381. (let ((re org-complex-heading-regexp)
  1382. (todo (plist-get opts :todo-keywords))
  1383. (tags (plist-get opts :tags))
  1384. (pri (plist-get opts :priority))
  1385. (elts '(1 2 3 4 5))
  1386. (case-fold-search nil)
  1387. rpl)
  1388. (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
  1389. (when (or (not todo) (not tags) (not pri))
  1390. (goto-char (point-min))
  1391. (while (re-search-forward re nil t)
  1392. (org-if-unprotected
  1393. (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
  1394. elts " "))
  1395. (replace-match rpl t t))))))
  1396. (defun org-export-remove-timestamps ()
  1397. "Remove timestamps and keywords for export."
  1398. (goto-char (point-min))
  1399. (while (re-search-forward org-maybe-keyword-time-regexp nil t)
  1400. (backward-char 1)
  1401. (org-if-unprotected
  1402. (unless (save-match-data (org-at-table-p))
  1403. (replace-match "")
  1404. (beginning-of-line 1)
  1405. (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
  1406. (replace-match ""))))))
  1407. (defun org-export-remove-clock-lines ()
  1408. "Remove clock lines for export."
  1409. (goto-char (point-min))
  1410. (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
  1411. (while (re-search-forward re nil t)
  1412. (org-if-unprotected
  1413. (replace-match "")))))
  1414. (defun org-export-protect-quoted-subtrees ()
  1415. "Mark quoted subtrees with the protection property."
  1416. (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
  1417. (goto-char (point-min))
  1418. (while (re-search-forward re-quote nil t)
  1419. (goto-char (match-beginning 0))
  1420. (end-of-line 1)
  1421. (add-text-properties (point) (org-end-of-subtree t)
  1422. '(org-protected t)))))
  1423. (defun org-export-convert-protected-spaces ()
  1424. "Convert strings like \\____ to protected spaces in all backends."
  1425. (goto-char (point-min))
  1426. (while (re-search-forward "\\\\__+" nil t)
  1427. (org-if-unprotected-1
  1428. (replace-match
  1429. (org-add-props
  1430. (cond
  1431. ((eq org-export-current-backend 'latex)
  1432. (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
  1433. ((eq org-export-current-backend 'html)
  1434. (org-add-props (match-string 0) nil
  1435. 'org-whitespace (- (match-end 0) (match-beginning 0))))
  1436. ;; ((eq org-export-current-backend 'docbook))
  1437. ((eq org-export-current-backend 'ascii)
  1438. (org-add-props (match-string 0) '(org-whitespace t)))
  1439. (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
  1440. '(org-protected t))
  1441. t t))))
  1442. (defun org-export-protect-verbatim ()
  1443. "Mark verbatim snippets with the protection property."
  1444. (goto-char (point-min))
  1445. (while (re-search-forward org-verbatim-re nil t)
  1446. (org-if-unprotected
  1447. (add-text-properties (match-beginning 4) (match-end 4)
  1448. '(org-protected t org-verbatim-emph t))
  1449. (goto-char (1+ (match-end 4))))))
  1450. (defun org-export-protect-colon-examples ()
  1451. "Protect lines starting with a colon."
  1452. (goto-char (point-min))
  1453. (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
  1454. (while (re-search-forward re nil t)
  1455. (beginning-of-line 1)
  1456. (setq beg (point))
  1457. (while (looking-at re)
  1458. (end-of-line 1)
  1459. (or (eobp) (forward-char 1)))
  1460. (add-text-properties beg (if (bolp) (1- (point)) (point))
  1461. '(org-protected t)))))
  1462. (defun org-export-select-backend-specific-text ()
  1463. (let ((formatters
  1464. '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
  1465. (html "HTML" "BEGIN_HTML" "END_HTML")
  1466. (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER")
  1467. (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
  1468. (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1469. (case-fold-search t)
  1470. fmt beg beg-content end end-content ind)
  1471. (while formatters
  1472. (setq fmt (pop formatters))
  1473. ;; Handle #+backend: stuff
  1474. (goto-char (point-min))
  1475. (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
  1476. ":[ \t]*\\(.*\\)") nil t)
  1477. (if (not (eq (car fmt) org-export-current-backend))
  1478. (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
  1479. (replace-match "\\1\\2" t)
  1480. (add-text-properties
  1481. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1482. `(org-protected t original-indentation ,ind))))
  1483. ;; Delete #+attr_Backend: stuff of another backend. Those
  1484. ;; matching the current backend will be taken care of by
  1485. ;; `org-export-attach-captions-and-attributes'
  1486. (goto-char (point-min))
  1487. (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt)
  1488. ":[ \t]*\\(.*\\)") nil t)
  1489. (setq ind (org-get-indentation))
  1490. (when (not (eq (car fmt) org-export-current-backend))
  1491. (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
  1492. ;; Handle #+begin_backend and #+end_backend stuff
  1493. (goto-char (point-min))
  1494. (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?")
  1495. nil t)
  1496. (setq beg (match-beginning 0) beg-content (match-end 0))
  1497. (setq ind (save-excursion (goto-char beg) (org-get-indentation)))
  1498. (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
  1499. nil t)
  1500. (setq end (match-end 0) end-content (match-beginning 0))
  1501. (if (eq (car fmt) org-export-current-backend)
  1502. ;; yes, keep this
  1503. (progn
  1504. (add-text-properties
  1505. beg-content end-content
  1506. `(org-protected t original-indentation ,ind))
  1507. (delete-region (match-beginning 0) (match-end 0))
  1508. (save-excursion
  1509. (goto-char beg)
  1510. (delete-region (point) (1+ (point-at-eol)))))
  1511. ;; No, this is for a different backend, kill it
  1512. (delete-region beg end)))))))
  1513. (defun org-export-mark-blockquote-verse-center ()
  1514. "Mark block quote and verse environments with special cookies.
  1515. These special cookies will later be interpreted by the backend."
  1516. ;; Blockquotes
  1517. (let (type t1 ind beg end beg1 end1 content)
  1518. (goto-char (point-min))
  1519. (while (re-search-forward
  1520. "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
  1521. nil t)
  1522. (setq ind (length (match-string 1))
  1523. type (downcase (match-string 3))
  1524. t1 (if (equal type "quote") "blockquote" type))
  1525. (setq beg (match-beginning 0)
  1526. beg1 (1+ (match-end 0)))
  1527. (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
  1528. (setq end1 (1- (match-beginning 0))
  1529. end (+ (point-at-eol) (if (looking-at "\n$") 1 0)))
  1530. (setq content (org-remove-indentation (buffer-substring beg1 end1)))
  1531. (setq content (concat "ORG-" (upcase t1) "-START\n"
  1532. content "\n"
  1533. "ORG-" (upcase t1) "-END\n"))
  1534. (delete-region beg end)
  1535. (insert (org-add-props content nil 'original-indentation ind))))))
  1536. (defun org-export-mark-list-end ()
  1537. "Mark all list endings with a special string."
  1538. (unless (eq org-export-current-backend 'ascii)
  1539. (mapc
  1540. (lambda (e)
  1541. ;; For each type allowing list export, find every list, remove
  1542. ;; ending regexp if needed, and insert org-list-end.
  1543. (goto-char (point-min))
  1544. (while (re-search-forward (org-item-beginning-re) nil t)
  1545. (when (eq (nth 2 (org-list-context)) e)
  1546. (let* ((struct (org-list-struct))
  1547. (bottom (org-list-get-bottom-point struct))
  1548. (top (point-at-bol))
  1549. (top-ind (org-list-get-ind top struct)))
  1550. (goto-char bottom)
  1551. (when (and (not (eq org-list-ending-method 'indent))
  1552. (looking-at org-list-end-re))
  1553. (replace-match ""))
  1554. (unless (bolp) (insert "\n"))
  1555. ;; As org-list-end is inserted at column 0, it would end
  1556. ;; by indentation any list. It can be problematic when
  1557. ;; there are lists within lists: the inner list end would
  1558. ;; also become the outer list end. To avoid this, text
  1559. ;; property `original-indentation' is added, as
  1560. ;; `org-list-struct' pays attention to it when reading a
  1561. ;; list.
  1562. (insert (org-add-props
  1563. "ORG-LIST-END-MARKER\n"
  1564. (list 'original-indentation top-ind)))))))
  1565. (cons nil org-list-export-context))))
  1566. (defun org-export-mark-list-properties ()
  1567. "Mark list with special properties.
  1568. These special properties will later be interpreted by the backend."
  1569. (let ((mark-list
  1570. (function
  1571. ;; Mark a list with 3 properties: `list-item' which is
  1572. ;; position at beginning of line, `list-struct' which is
  1573. ;; list structure, and `list-prevs' which is the alist of
  1574. ;; item and its predecessor. Leave point at list ending.
  1575. (lambda (ctxt)
  1576. (let* ((struct (org-list-struct))
  1577. (top (org-list-get-top-point struct))
  1578. (bottom (org-list-get-bottom-point struct))
  1579. (prevs (org-list-prevs-alist struct))
  1580. poi)
  1581. ;; Get every item and ending position, without dups and
  1582. ;; without bottom point of list.
  1583. (mapc (lambda (e)
  1584. (let ((pos (car e))
  1585. (end (nth 6 e)))
  1586. (unless (memq pos poi)
  1587. (push pos poi))
  1588. (unless (or (= end bottom) (memq end poi))
  1589. (push end poi))))
  1590. struct)
  1591. (setq poi (sort poi '<))
  1592. ;; For every point of interest, mark the whole line with
  1593. ;; its position in list.
  1594. (mapc
  1595. (lambda (e)
  1596. (goto-char e)
  1597. (add-text-properties (point-at-bol) (point-at-eol)
  1598. (list 'list-item (point-at-bol)
  1599. 'list-struct struct
  1600. 'list-prevs prevs)))
  1601. poi)
  1602. ;; Take care of bottom point. As babel may have inserted
  1603. ;; a new list in buffer, list ending isn't always
  1604. ;; marked. Now mark every list ending and add properties
  1605. ;; useful to line processing exporters.
  1606. (goto-char bottom)
  1607. (when (or (looking-at "^ORG-LIST-END-MARKER\n")
  1608. (and (not (eq org-list-ending-method 'indent))
  1609. (looking-at org-list-end-re)))
  1610. (replace-match ""))
  1611. (unless (bolp) (insert "\n"))
  1612. (insert
  1613. (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
  1614. 'list-struct struct
  1615. 'list-prevs prevs)))
  1616. ;; Following property is used by LaTeX exporter.
  1617. (add-text-properties top (point) (list 'list-context ctxt)))))))
  1618. ;; Mark lists except for backends not interpreting them.
  1619. (unless (eq org-export-current-backend 'ascii)
  1620. (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
  1621. (mapc
  1622. (lambda (e)
  1623. (goto-char (point-min))
  1624. (while (re-search-forward (org-item-beginning-re) nil t)
  1625. (let ((context (nth 2 (org-list-context))))
  1626. (if (eq context e)
  1627. (funcall mark-list e)
  1628. (put-text-property (point-at-bol) (point-at-eol)
  1629. 'list-context context)))))
  1630. (cons nil org-list-export-context))))))
  1631. (defun org-export-attach-captions-and-attributes (target-alist)
  1632. "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
  1633. If the next thing following is a table, add the text properties to the first
  1634. table line. If it is a link, add it to the line containing the link."
  1635. (goto-char (point-min))
  1636. (remove-text-properties (point-min) (point-max)
  1637. '(org-caption nil org-attributes nil))
  1638. (let ((case-fold-search t)
  1639. (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
  1640. "\\|"
  1641. "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \t]+\\(.*\\)"
  1642. "\\|"
  1643. "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
  1644. "\\|"
  1645. "^[ \t]*\\(|[^-]\\)"
  1646. "\\|"
  1647. "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
  1648. cap shortn attr label end)
  1649. (while (re-search-forward re nil t)
  1650. (cond
  1651. ;; there is a caption
  1652. ((match-end 1)
  1653. (progn
  1654. (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))
  1655. (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap)
  1656. (setq shortn (match-string 1 cap)
  1657. cap (match-string 2 cap)))
  1658. (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
  1659. ;; there is an attribute
  1660. ((match-end 2)
  1661. (progn
  1662. (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))
  1663. (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
  1664. ;; there is a label
  1665. ((match-end 3)
  1666. (progn
  1667. (setq label (org-trim (match-string 3)))
  1668. (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
  1669. (t
  1670. (setq end (if (match-end 4)
  1671. (let ((ee (org-table-end)))
  1672. (prog1 (1- (marker-position ee)) (move-marker ee nil)))
  1673. (point-at-eol)))
  1674. (add-text-properties (point-at-bol) end
  1675. (list 'org-caption cap
  1676. 'org-caption-shortn shortn
  1677. 'org-attributes attr
  1678. 'org-label label))
  1679. (if label (push (cons label label) target-alist))
  1680. (goto-char end)
  1681. (setq cap nil shortn nil attr nil label nil)))))
  1682. target-alist)
  1683. (defun org-export-remove-comment-blocks-and-subtrees ()
  1684. "Remove the comment environment, and also commented subtrees."
  1685. (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  1686. case-fold-search)
  1687. ;; Remove comment environment
  1688. (goto-char (point-min))
  1689. (setq case-fold-search t)
  1690. (while (re-search-forward
  1691. "^#\\+begin_comment[ \t]*\n[^\000]*?\n#\\+end_comment\\>.*" nil t)
  1692. (replace-match "" t t))
  1693. ;; Remove subtrees that are commented
  1694. (goto-char (point-min))
  1695. (setq case-fold-search nil)
  1696. (while (re-search-forward re-commented nil t)
  1697. (goto-char (match-beginning 0))
  1698. (delete-region (point) (org-end-of-subtree t)))))
  1699. (defun org-export-handle-comments (commentsp)
  1700. "Remove comments, or convert to backend-specific format.
  1701. COMMENTSP can be a format string for publishing comments.
  1702. When it is nil, all comments will be removed."
  1703. (let ((re "^\\(#\\|[ \t]*#\\+ \\)\\(.*\n?\\)")
  1704. pos)
  1705. (goto-char (point-min))
  1706. (while (or (looking-at re)
  1707. (re-search-forward re nil t))
  1708. (setq pos (match-beginning 0))
  1709. (if (get-text-property pos 'org-protected)
  1710. (goto-char (1+ pos))
  1711. (if (and commentsp
  1712. (not (equal (char-before (match-end 1)) ?+)))
  1713. (progn (add-text-properties
  1714. (match-beginning 0) (match-end 0) '(org-protected t))
  1715. (replace-match (org-add-props
  1716. (format commentsp (match-string 2))
  1717. nil 'org-protected t)
  1718. t t))
  1719. (goto-char (1+ pos))
  1720. (replace-match "")
  1721. (goto-char (max (point-min) (1- pos))))))))
  1722. (defun org-export-handle-table-metalines ()
  1723. "Remove table specific metalines #+TBLNAME: and #+TBLFM:."
  1724. (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)")
  1725. pos)
  1726. (goto-char (point-min))
  1727. (while (or (looking-at re)
  1728. (re-search-forward re nil t))
  1729. (setq pos (match-beginning 0))
  1730. (if (get-text-property (match-beginning 1) 'org-protected)
  1731. (goto-char (1+ pos))
  1732. (goto-char (1+ pos))
  1733. (replace-match "")
  1734. (goto-char (max (point-min) (1- pos)))))))
  1735. (defun org-export-mark-radio-links ()
  1736. "Find all matches for radio targets and turn them into internal links."
  1737. (let ((re-radio (and org-target-link-regexp
  1738. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
  1739. (goto-char (point-min))
  1740. (when re-radio
  1741. (while (re-search-forward re-radio nil t)
  1742. (unless
  1743. (save-match-data
  1744. (or (org-in-regexp org-bracket-link-regexp)
  1745. (org-in-regexp org-plain-link-re)
  1746. (org-in-regexp "<<[^<>]+>>")))
  1747. (org-if-unprotected
  1748. (replace-match "\\1[[\\2]]")))))))
  1749. (defun org-store-forced-table-alignment ()
  1750. "Find table lines which force alignment, store the results in properties."
  1751. (let (line cnt aligns)
  1752. (goto-char (point-min))
  1753. (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t)
  1754. ;; OK, this looks like a table line with an alignment cookie
  1755. (org-if-unprotected
  1756. (setq line (buffer-substring (point-at-bol) (point-at-eol)))
  1757. (when (and (org-at-table-p)
  1758. (org-table-cookie-line-p line))
  1759. (setq cnt 0 aligns nil)
  1760. (mapc
  1761. (lambda (x)
  1762. (setq cnt (1+ cnt))
  1763. (if (string-match "\\`<\\([lrc]\\)" x)
  1764. (push (cons cnt (downcase (match-string 1 x))) aligns)))
  1765. (org-split-string line "[ \t]*|[ \t]*"))
  1766. (add-text-properties (org-table-begin) (org-table-end)
  1767. (list 'org-forced-aligns aligns))))
  1768. (goto-char (point-at-eol)))))
  1769. (defun org-export-remove-special-table-lines ()
  1770. "Remove tables lines that are used for internal purposes.
  1771. Also, store forced alignment information found in such lines."
  1772. (goto-char (point-min))
  1773. (while (re-search-forward "^[ \t]*|" nil t)
  1774. (org-if-unprotected-at (1- (point))
  1775. (beginning-of-line 1)
  1776. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1777. (not
  1778. (memq
  1779. nil
  1780. (mapcar
  1781. (lambda (f)
  1782. (or (and org-export-table-remove-empty-lines (= (length f) 0))
  1783. (string-match
  1784. "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f)))
  1785. (org-split-string ;; FIXME, can't we do without splitting???
  1786. (buffer-substring (point-at-bol) (point-at-eol))
  1787. "[ \t]*|[ \t]*")))))
  1788. (delete-region (max (point-min) (1- (point-at-bol)))
  1789. (point-at-eol))
  1790. (end-of-line 1)))))
  1791. (defun org-export-protect-sub-super (s)
  1792. (save-match-data
  1793. (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s)
  1794. (setq s (replace-match "\\1\\\\\\2" nil nil s)))
  1795. s))
  1796. (defun org-export-normalize-links ()
  1797. "Convert all links to bracket links, and expand link abbreviations."
  1798. (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  1799. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
  1800. nodesc)
  1801. (goto-char (point-min))
  1802. (while (re-search-forward re-plain-link nil t)
  1803. (unless (org-string-match-p
  1804. "\\[\\[\\S-+:\\S-*?\\<"
  1805. (buffer-substring (point-at-bol) (match-beginning 0)))
  1806. (goto-char (1- (match-end 0)))
  1807. (org-if-unprotected-at (1+ (match-beginning 0))
  1808. (let* ((s (concat (match-string 1)
  1809. "[[" (match-string 2) ":" (match-string 3)
  1810. "][" (match-string 2) ":" (org-export-protect-sub-super
  1811. (match-string 3))
  1812. "]]")))
  1813. ;; added 'org-link face to links
  1814. (put-text-property 0 (length s) 'face 'org-link s)
  1815. (replace-match s t t)))))
  1816. (goto-char (point-min))
  1817. (while (re-search-forward re-angle-link nil t)
  1818. (goto-char (1- (match-end 0)))
  1819. (org-if-unprotected
  1820. (let* ((s (concat (match-string 1)
  1821. "[[" (match-string 2) ":" (match-string 3)
  1822. "][" (match-string 2) ":" (org-export-protect-sub-super
  1823. (match-string 3))
  1824. "]]")))
  1825. (put-text-property 0 (length s) 'face 'org-link s)
  1826. (replace-match s t t))))
  1827. (goto-char (point-min))
  1828. (while (re-search-forward org-bracket-link-regexp nil t)
  1829. (goto-char (1- (match-end 0)))
  1830. (setq nodesc (not (match-end 3)))
  1831. (org-if-unprotected
  1832. (let* ((xx (save-match-data
  1833. (org-translate-link
  1834. (org-link-expand-abbrev (match-string 1)))))
  1835. (s (concat
  1836. "[[" (org-add-props (copy-sequence xx)
  1837. nil 'org-protected t 'org-no-description nodesc)
  1838. "]"
  1839. (if (match-end 3)
  1840. (match-string 2)
  1841. (concat "[" (copy-sequence xx)
  1842. "]"))
  1843. "]")))
  1844. (put-text-property 0 (length s) 'face 'org-link s)
  1845. (replace-match s t t))))))
  1846. (defun org-export-concatenate-multiline-links ()
  1847. "Find multi-line links and put it all into a single line.
  1848. This is to make sure that the line-processing export backends
  1849. can work correctly."
  1850. (goto-char (point-min))
  1851. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1852. (org-if-unprotected-at (match-beginning 1)
  1853. (replace-match "\\1 \\3")
  1854. (goto-char (match-beginning 0)))))
  1855. (defun org-export-concatenate-multiline-emphasis ()
  1856. "Find multi-line emphasis and put it all into a single line.
  1857. This is to make sure that the line-processing export backends
  1858. can work correctly."
  1859. (goto-char (point-min))
  1860. (while (re-search-forward org-emph-re nil t)
  1861. (if (and (not (= (char-after (match-beginning 3))
  1862. (char-after (match-beginning 4))))
  1863. (save-excursion (goto-char (match-beginning 0))
  1864. (save-match-data
  1865. (and (not (org-at-table-p))
  1866. (not (org-at-heading-p))))))
  1867. (org-if-unprotected
  1868. (subst-char-in-region (match-beginning 0) (match-end 0)
  1869. ?\n ?\ t)
  1870. (goto-char (1- (match-end 0))))
  1871. (goto-char (1+ (match-beginning 0))))))
  1872. (defun org-export-grab-title-from-buffer ()
  1873. "Get a title for the current document, from looking at the buffer."
  1874. (let ((inhibit-read-only t))
  1875. (save-excursion
  1876. (goto-char (point-min))
  1877. (let ((end (if (looking-at org-outline-regexp)
  1878. (point)
  1879. (save-excursion (outline-next-heading) (point)))))
  1880. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1881. ;; Mark the line so that it will not be exported as normal text.
  1882. (org-unmodified
  1883. (add-text-properties (match-beginning 0) (match-end 0)
  1884. (list :org-license-to-kill t)))
  1885. ;; Return the title string
  1886. (org-trim (match-string 0)))))))
  1887. (defun org-export-get-title-from-subtree ()
  1888. "Return subtree title and exclude it from export."
  1889. (let ((rbeg (region-beginning)) (rend (region-end))
  1890. (inhibit-read-only t) title)
  1891. (save-excursion
  1892. (goto-char rbeg)
  1893. (when (and (org-at-heading-p)
  1894. (>= (org-end-of-subtree t t) rend))
  1895. ;; This is a subtree, we take the title from the first heading
  1896. (goto-char rbeg)
  1897. (looking-at org-todo-line-regexp)
  1898. (setq title (match-string 3))
  1899. (org-unmodified
  1900. (add-text-properties (point) (1+ (point-at-eol))
  1901. (list :org-license-to-kill t)))
  1902. (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
  1903. title))
  1904. (defun org-solidify-link-text (s &optional alist)
  1905. "Take link text and make a safe target out of it."
  1906. (save-match-data
  1907. (let* ((rtn
  1908. (mapconcat
  1909. 'identity
  1910. (org-split-string s "[^a-zA-Z0-9_\\.-]+") "-"))
  1911. (a (assoc rtn alist)))
  1912. (or (cdr a) rtn))))
  1913. (defun org-get-min-level (lines &optional offset)
  1914. "Get the minimum level in LINES."
  1915. (let ((re "^\\(\\*+\\) ") l)
  1916. (catch 'exit
  1917. (while (setq l (pop lines))
  1918. (if (string-match re l)
  1919. (throw 'exit (org-tr-level (- (length (match-string 1 l))
  1920. (or offset 0))))))
  1921. 1)))
  1922. ;; Variable holding the vector with section numbers
  1923. (defvar org-section-numbers (make-vector org-level-max 0))
  1924. (defun org-init-section-numbers ()
  1925. "Initialize the vector for the section numbers."
  1926. (let* ((level -1)
  1927. (numbers (nreverse (org-split-string "" "\\.")))
  1928. (depth (1- (length org-section-numbers)))
  1929. (i depth) number-string)
  1930. (while (>= i 0)
  1931. (if (> i level)
  1932. (aset org-section-numbers i 0)
  1933. (setq number-string (or (car numbers) "0"))
  1934. (if (string-match "\\`[A-Z]\\'" number-string)
  1935. (aset org-section-numbers i
  1936. (- (string-to-char number-string) ?A -1))
  1937. (aset org-section-numbers i (string-to-number number-string)))
  1938. (pop numbers))
  1939. (setq i (1- i)))))
  1940. (defun org-section-number (&optional level)
  1941. "Return a string with the current section number.
  1942. When LEVEL is non-nil, increase section numbers on that level."
  1943. (let* ((depth (1- (length org-section-numbers)))
  1944. (string "")
  1945. (fmts (car org-export-section-number-format))
  1946. (term (cdr org-export-section-number-format))
  1947. (sep "")
  1948. ctype fmt idx n)
  1949. (when level
  1950. (when (> level -1)
  1951. (aset org-section-numbers
  1952. level (1+ (aref org-section-numbers level))))
  1953. (setq idx (1+ level))
  1954. (while (<= idx depth)
  1955. (if (not (= idx 1))
  1956. (aset org-section-numbers idx 0))
  1957. (setq idx (1+ idx))))
  1958. (setq idx 0)
  1959. (while (<= idx depth)
  1960. (when (> (aref org-section-numbers idx) 0)
  1961. (setq fmt (or (pop fmts) fmt)
  1962. ctype (car fmt)
  1963. n (aref org-section-numbers idx)
  1964. string (if (> n 0)
  1965. (concat string sep (org-number-to-counter n ctype))
  1966. (concat string ".0"))
  1967. sep (nth 1 fmt)))
  1968. (setq idx (1+ idx)))
  1969. (save-match-data
  1970. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1971. (setq string (replace-match "" t nil string)))
  1972. (if (string-match "\\(\\.0\\)+\\'" string)
  1973. (setq string (replace-match "" t nil string))))
  1974. (concat string term)))
  1975. (defun org-number-to-counter (n type)
  1976. "Concert number N to a string counter, according to TYPE.
  1977. TYPE must be a string, any of:
  1978. 1 number
  1979. A A,B,....
  1980. a a,b,....
  1981. I upper case roman numeral
  1982. i lower case roman numeral"
  1983. (cond
  1984. ((equal type "1") (number-to-string n))
  1985. ((equal type "A") (char-to-string (+ ?A n -1)))
  1986. ((equal type "a") (char-to-string (+ ?a n -1)))
  1987. ((equal type "I") (org-number-to-roman n))
  1988. ((equal type "i") (downcase (org-number-to-roman n)))
  1989. (t (error "Invalid counter type `%s'" type))))
  1990. (defun org-number-to-roman (n)
  1991. "Convert integer N into a roman numeral."
  1992. (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
  1993. ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
  1994. ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
  1995. ( 1 . "I")))
  1996. (res ""))
  1997. (if (<= n 0)
  1998. (number-to-string n)
  1999. (while roman
  2000. (if (>= n (caar roman))
  2001. (setq n (- n (caar roman))
  2002. res (concat res (cdar roman)))
  2003. (pop roman)))
  2004. res)))
  2005. ;;; Macros
  2006. (defun org-export-preprocess-apply-macros ()
  2007. "Replace macro references."
  2008. (goto-char (point-min))
  2009. (let (sy val key args args2 ind-str s n)
  2010. (while (re-search-forward
  2011. "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
  2012. nil t)
  2013. (unless (save-match-data (save-excursion
  2014. (goto-char (point-at-bol))
  2015. (looking-at "[ \t]*#\\+macro")))
  2016. ;; Get macro name (KEY), arguments (ARGS), and indentation of
  2017. ;; current line (IND-STR) as strings.
  2018. (setq key (downcase (match-string 1))
  2019. args (match-string 3)
  2020. ind-str (save-match-data (save-excursion
  2021. (beginning-of-line)
  2022. (looking-at "^\\([ \t]*\\).*")
  2023. (match-string 1))))
  2024. ;; When macro is defined, retrieve replacement text in VAL,
  2025. ;; and proceed with expansion.
  2026. (when (setq val (or (plist-get org-export-opt-plist
  2027. (intern (concat ":macro-" key)))
  2028. (plist-get org-export-opt-plist
  2029. (intern (concat ":" key)))))
  2030. (save-match-data
  2031. ;; If arguments are provided, first retreive them properly
  2032. ;; (in ARGS, as a list), then replace them in VAL.
  2033. (when args
  2034. (setq args (org-split-string args ",") args2 nil)
  2035. (while args
  2036. (while (string-match "\\\\\\'" (car args))
  2037. ;; Repair bad splits.
  2038. (setcar (cdr args) (concat (substring (car args) 0 -1)
  2039. "," (nth 1 args)))
  2040. (pop args))
  2041. (push (pop args) args2))
  2042. (setq args (mapcar 'org-trim (nreverse args2)))
  2043. (setq s 0)
  2044. (while (string-match "\\$\\([0-9]+\\)" val s)
  2045. (setq s (1+ (match-beginning 0))
  2046. n (string-to-number (match-string 1 val)))
  2047. (and (>= (length args) n)
  2048. (setq val (replace-match (nth (1- n) args) t t val)))))
  2049. ;; VAL starts with "(eval": it is a sexp, `eval' it.
  2050. (when (string-match "\\`(eval\\>" val)
  2051. (setq val (eval (read val))))
  2052. ;; Ensure VAL is a string (or nil) and that each new line
  2053. ;; is indented as the first one.
  2054. (setq val (and val
  2055. (mapconcat 'identity
  2056. (org-split-string
  2057. (if (stringp val) val (format "%s" val))
  2058. "\n")
  2059. (concat "\n" ind-str)))))
  2060. ;; Eventually do the replacement, if VAL isn't nil. Move
  2061. ;; point at beginning of macro for recursive expansions.
  2062. (when val
  2063. (replace-match val t t)
  2064. (goto-char (match-beginning 0))))))))
  2065. (defun org-export-apply-macros-in-string (s)
  2066. "Apply the macros in string S."
  2067. (when s
  2068. (with-temp-buffer
  2069. (insert s)
  2070. (org-export-preprocess-apply-macros)
  2071. (buffer-string))))
  2072. ;;; Include files
  2073. (defun org-export-handle-include-files ()
  2074. "Include the contents of include files, with proper formatting."
  2075. (let ((case-fold-search t)
  2076. params file markup lang start end prefix prefix1 switches all minlevel lines)
  2077. (goto-char (point-min))
  2078. (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
  2079. (setq params (read (concat "(" (match-string 1) ")"))
  2080. prefix (org-get-and-remove-property 'params :prefix)
  2081. prefix1 (org-get-and-remove-property 'params :prefix1)
  2082. minlevel (org-get-and-remove-property 'params :minlevel)
  2083. lines (org-get-and-remove-property 'params :lines)
  2084. file (org-symname-or-string (pop params))
  2085. markup (org-symname-or-string (pop params))
  2086. lang (and (member markup '("src" "SRC"))
  2087. (org-symname-or-string (pop params)))
  2088. switches (mapconcat '(lambda (x) (format "%s" x)) params " ")
  2089. start nil end nil)
  2090. (delete-region (match-beginning 0) (match-end 0))
  2091. (if (or (not file)
  2092. (not (file-exists-p file))
  2093. (not (file-readable-p file)))
  2094. (insert (format "CANNOT INCLUDE FILE %s" file))
  2095. (setq all (cons file all))
  2096. (when markup
  2097. (if (equal (downcase markup) "src")
  2098. (setq start (format "#+begin_src %s %s\n"
  2099. (or lang "fundamental")
  2100. (or switches ""))
  2101. end "#+end_src")
  2102. (setq start (format "#+begin_%s %s\n" markup switches)
  2103. end (format "#+end_%s" markup))))
  2104. (insert (or start ""))
  2105. (insert (org-get-file-contents (expand-file-name file)
  2106. prefix prefix1 markup minlevel lines))
  2107. (or (bolp) (newline))
  2108. (insert (or end ""))))
  2109. all))
  2110. (defun org-export-handle-include-files-recurse ()
  2111. "Recursively include files aborting on circular inclusion."
  2112. (let ((now (list org-current-export-file)) all)
  2113. (while now
  2114. (setq all (append now all))
  2115. (setq now (org-export-handle-include-files))
  2116. (let ((intersection
  2117. (delq nil
  2118. (mapcar (lambda (el) (when (member el all) el)) now))))
  2119. (when intersection
  2120. (error "Recursive #+INCLUDE: %S" intersection))))))
  2121. (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel lines)
  2122. "Get the contents of FILE and return them as a string.
  2123. If PREFIX is a string, prepend it to each line. If PREFIX1
  2124. is a string, prepend it to the first line instead of PREFIX.
  2125. If MARKUP, don't protect org-like lines, the exporter will
  2126. take care of the block they are in. If LINES is a string
  2127. specifying a range of lines, include only those lines ."
  2128. (if (stringp markup) (setq markup (downcase markup)))
  2129. (with-temp-buffer
  2130. (insert-file-contents file)
  2131. (when lines
  2132. (let* ((lines (split-string lines "-"))
  2133. (lbeg (string-to-number (car lines)))
  2134. (lend (string-to-number (cadr lines)))
  2135. (beg (if (zerop lbeg) (point-min)
  2136. (goto-char (point-min))
  2137. (forward-line (1- lbeg))
  2138. (point)))
  2139. (end (if (zerop lend) (point-max)
  2140. (goto-char (point-min))
  2141. (forward-line (1- lend))
  2142. (point))))
  2143. (narrow-to-region beg end)))
  2144. (when (or prefix prefix1)
  2145. (goto-char (point-min))
  2146. (while (not (eobp))
  2147. (insert (or prefix1 prefix))
  2148. (setq prefix1 "")
  2149. (beginning-of-line 2)))
  2150. (buffer-string)
  2151. (when (member markup '("src" "example"))
  2152. (goto-char (point-min))
  2153. (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t)
  2154. (goto-char (match-beginning 0))
  2155. (insert ",")
  2156. (end-of-line 1)))
  2157. (when minlevel
  2158. (dotimes (lvl minlevel)
  2159. (org-map-region 'org-demote (point-min) (point-max))))
  2160. (buffer-string)))
  2161. (defun org-get-and-remove-property (listvar prop)
  2162. "Check if the value of LISTVAR contains PROP as a property.
  2163. If yes, return the value of that property (i.e. the element following
  2164. in the list) and remove property and value from the list in LISTVAR."
  2165. (let ((list (symbol-value listvar)) m v)
  2166. (when (setq m (member prop list))
  2167. (setq v (nth 1 m))
  2168. (if (equal (car list) prop)
  2169. (set listvar (cddr list))
  2170. (setcdr (nthcdr (- (length list) (length m) 1) list)
  2171. (cddr m))
  2172. (set listvar list)))
  2173. v))
  2174. (defun org-symname-or-string (s)
  2175. (if (symbolp s)
  2176. (if s (symbol-name s) s)
  2177. s))
  2178. ;;; Fontification and line numbers for code examples
  2179. (defvar org-export-last-code-line-counter-value 0)
  2180. (defun org-export-replace-src-segments-and-examples ()
  2181. "Replace source code segments with special code for export."
  2182. (setq org-export-last-code-line-counter-value 0)
  2183. (let ((case-fold-search t)
  2184. lang code trans opts indent caption)
  2185. (goto-char (point-min))
  2186. (while (re-search-forward
  2187. "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
  2188. nil t)
  2189. (if (match-end 1)
  2190. (if (not (match-string 4))
  2191. (error "Source block missing language specification: %s"
  2192. (let* ((body (match-string 6))
  2193. (nothing (message "body:%s" body))
  2194. (preview (or (and (string-match
  2195. "^[ \t]*\\([^\n\r]*\\)" body)
  2196. (match-string 1 body)) body)))
  2197. (if (> (length preview) 35)
  2198. (concat (substring preview 0 32) "...")
  2199. preview)))
  2200. ;; src segments
  2201. (setq lang (match-string 4)
  2202. opts (match-string 5)
  2203. code (match-string 6)
  2204. indent (length (match-string 2))
  2205. caption (get-text-property 0 'org-caption (match-string 0))))
  2206. (setq lang nil
  2207. opts (match-string 9)
  2208. code (match-string 10)
  2209. indent (length (match-string 8))
  2210. caption (get-text-property 0 'org-caption (match-string 0))))
  2211. (setq trans (org-export-format-source-code-or-example
  2212. lang code opts indent caption))
  2213. (replace-match trans t t))))
  2214. (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
  2215. (defvar org-export-latex-listings) ;; defined in org-latex.el
  2216. (defvar org-export-latex-listings-langs) ;; defined in org-latex.el
  2217. (defvar org-export-latex-listings-w-names) ;; defined in org-latex.el
  2218. (defvar org-export-latex-minted-langs) ;; defined in org-latex.el
  2219. (defvar org-export-latex-custom-lang-environments) ;; defined in org-latex.el
  2220. (defvar org-export-latex-listings-options) ;; defined in org-latex.el
  2221. (defvar org-export-latex-minted-options) ;; defined in org-latex.el
  2222. (defun org-remove-formatting-on-newlines-in-region (beg end)
  2223. "Remove formatting on newline characters"
  2224. (interactive "r")
  2225. (save-excursion
  2226. (goto-char beg)
  2227. (while (progn (end-of-line) (< (point) end))
  2228. (put-text-property (point) (1+ (point)) 'face nil)
  2229. (forward-char 1))))
  2230. (defun org-export-format-source-code-or-example
  2231. (lang code &optional opts indent caption)
  2232. "Format CODE from language LANG and return it formatted for export.
  2233. If LANG is nil, do not add any fontification.
  2234. OPTS contains formatting options, like `-n' for triggering numbering lines,
  2235. and `+n' for continuing previous numbering.
  2236. Code formatting according to language currently only works for HTML.
  2237. Numbering lines works for all three major backends (html, latex, and ascii).
  2238. INDENT was the original indentation of the block."
  2239. (save-match-data
  2240. (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
  2241. (setq opts (or opts "")
  2242. num (string-match "[-+]n\\>" opts)
  2243. cont (string-match "\\+n\\>" opts)
  2244. rpllbl (string-match "-r\\>" opts)
  2245. keepp (string-match "-k\\>" opts)
  2246. textareap (string-match "-t\\>" opts)
  2247. preserve-indentp (or org-src-preserve-indentation
  2248. (string-match "-i\\>" opts))
  2249. cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
  2250. (string-to-number (match-string 1 opts))
  2251. 80)
  2252. rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
  2253. (string-to-number (match-string 1 opts))
  2254. (org-count-lines code))
  2255. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  2256. (match-string 1 opts)))
  2257. (when (and textareap (eq org-export-current-backend 'html))
  2258. ;; we cannot use numbering or highlighting.
  2259. (setq num nil cont nil lang nil))
  2260. (if keepp (setq rpllbl 'keep))
  2261. (setq rtn (if preserve-indentp code (org-remove-indentation code)))
  2262. (when (string-match "^," rtn)
  2263. (setq rtn (with-temp-buffer
  2264. (insert rtn)
  2265. ;; Free up the protected lines
  2266. (goto-char (point-min))
  2267. (while (re-search-forward "^," nil t)
  2268. (if (or (equal lang "org")
  2269. (save-match-data
  2270. (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
  2271. (replace-match ""))
  2272. (end-of-line 1))
  2273. (buffer-string))))
  2274. ;; Now backend-specific coding
  2275. (setq rtn
  2276. (cond
  2277. ((eq org-export-current-backend 'docbook)
  2278. (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
  2279. (concat "\n#+BEGIN_DOCBOOK\n"
  2280. (org-add-props (concat "<programlisting><![CDATA["
  2281. rtn
  2282. "]]></programlisting>\n")
  2283. '(org-protected t org-example t))
  2284. "#+END_DOCBOOK\n"))
  2285. ((eq org-export-current-backend 'html)
  2286. ;; We are exporting to HTML
  2287. (when lang
  2288. (if (featurep 'xemacs)
  2289. (require 'htmlize)
  2290. (require 'htmlize nil t))
  2291. (when (not (fboundp 'htmlize-region-for-paste))
  2292. ;; we do not have htmlize.el, or an old version of it
  2293. (setq lang nil)
  2294. (message
  2295. "htmlize.el 1.34 or later is needed for source code formatting")))
  2296. (if lang
  2297. (let* ((lang-m (when lang
  2298. (or (cdr (assoc lang org-src-lang-modes))
  2299. lang)))
  2300. (mode (and lang-m (intern
  2301. (concat
  2302. (if (symbolp lang-m)
  2303. (symbol-name lang-m)
  2304. lang-m)
  2305. "-mode"))))
  2306. (org-inhibit-startup t)
  2307. (org-startup-folded nil))
  2308. (setq rtn
  2309. (with-temp-buffer
  2310. (insert rtn)
  2311. (if (functionp mode)
  2312. (funcall mode)
  2313. (fundamental-mode))
  2314. (font-lock-fontify-buffer)
  2315. ;; markup each line separately
  2316. (org-remove-formatting-on-newlines-in-region (point-min) (point-max))
  2317. (org-src-mode)
  2318. (set-buffer-modified-p nil)
  2319. (org-export-htmlize-region-for-paste
  2320. (point-min) (point-max))))
  2321. (if (string-match "<pre\\([^>]*\\)>\n*" rtn)
  2322. (setq rtn
  2323. (concat
  2324. (if caption
  2325. (concat
  2326. "<div class=\"org-src-container\">"
  2327. (format
  2328. "<label class=\"org-src-name\">%s</label>"
  2329. caption))
  2330. "")
  2331. (replace-match
  2332. (format "<pre class=\"src src-%s\">\n" lang)
  2333. t t rtn)
  2334. (if caption "</div>" "")))))
  2335. (if textareap
  2336. (setq rtn (concat
  2337. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
  2338. cols rows)
  2339. rtn "</textarea>\n</p>\n"))
  2340. (with-temp-buffer
  2341. (insert rtn)
  2342. (goto-char (point-min))
  2343. (while (re-search-forward "[<>&]" nil t)
  2344. (replace-match (cdr (assq (char-before)
  2345. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  2346. t t))
  2347. (setq rtn (buffer-string)))
  2348. (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
  2349. (unless textareap
  2350. (setq rtn (org-export-number-lines rtn 1 1 num cont rpllbl fmt)))
  2351. (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
  2352. (setq rtn (replace-match "\\1" t nil rtn)))
  2353. (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t org-example t)) "\n#+END_HTML\n\n"))
  2354. ((eq org-export-current-backend 'latex)
  2355. (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
  2356. (concat
  2357. "#+BEGIN_LaTeX\n"
  2358. (org-add-props
  2359. (cond
  2360. ((and lang org-export-latex-listings)
  2361. (flet ((make-option-string
  2362. (pair)
  2363. (concat (first pair)
  2364. (if (> (length (second pair)) 0)
  2365. (concat "=" (second pair))))))
  2366. (let* ((lang-sym (intern lang))
  2367. (minted-p (eq org-export-latex-listings 'minted))
  2368. (listings-p (not minted-p))
  2369. (backend-lang
  2370. (or (cadr
  2371. (assq
  2372. lang-sym
  2373. (cond
  2374. (minted-p org-export-latex-minted-langs)
  2375. (listings-p org-export-latex-listings-langs))))
  2376. lang))
  2377. (custom-environment
  2378. (cadr
  2379. (assq
  2380. lang-sym
  2381. org-export-latex-custom-lang-environments))))
  2382. (concat
  2383. (when (and listings-p (not custom-environment))
  2384. (format
  2385. "\\lstset{%s}\n"
  2386. (mapconcat
  2387. #'make-option-string
  2388. (append org-export-latex-listings-options
  2389. `(("language" ,backend-lang))) ",")))
  2390. (when (and caption org-export-latex-listings-w-names)
  2391. (format
  2392. "\n%s $\\equiv$ \n"
  2393. (replace-regexp-in-string "_" "\\\\_" caption)))
  2394. (cond
  2395. (custom-environment
  2396. (format "\\begin{%s}\n%s\\end{%s}\n"
  2397. custom-environment rtn custom-environment))
  2398. (listings-p
  2399. (format "\\begin{%s}\n%s\\end{%s}\n"
  2400. "lstlisting" rtn "lstlisting"))
  2401. (minted-p
  2402. (format
  2403. "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
  2404. (mapconcat #'make-option-string
  2405. org-export-latex-minted-options ",")
  2406. backend-lang rtn)))))))
  2407. (t (concat (car org-export-latex-verbatim-wrap)
  2408. rtn (cdr org-export-latex-verbatim-wrap))))
  2409. '(org-protected t org-example t))
  2410. "#+END_LaTeX\n"))
  2411. ((eq org-export-current-backend 'ascii)
  2412. ;; This is not HTML or LaTeX, so just make it an example.
  2413. (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
  2414. (concat caption "\n"
  2415. "#+BEGIN_ASCII\n"
  2416. (org-add-props
  2417. (concat
  2418. (mapconcat
  2419. (lambda (l) (concat " " l))
  2420. (org-split-string rtn "\n")
  2421. "\n")
  2422. "\n")
  2423. '(org-protected t org-example t))
  2424. "#+END_ASCII\n"))))
  2425. (org-add-props rtn nil 'original-indentation indent))))
  2426. (defun org-export-number-lines (text &optional skip1 skip2 number cont
  2427. replace-labels label-format)
  2428. (setq skip1 (or skip1 0) skip2 (or skip2 0))
  2429. (if (not cont) (setq org-export-last-code-line-counter-value 0))
  2430. (with-temp-buffer
  2431. (insert text)
  2432. (goto-char (point-max))
  2433. (skip-chars-backward " \t\n\r")
  2434. (delete-region (point) (point-max))
  2435. (beginning-of-line (- 1 skip2))
  2436. (let* ((last (org-current-line))
  2437. (n org-export-last-code-line-counter-value)
  2438. (nmax (+ n (- last skip1)))
  2439. (fmt (format "%%%dd: " (length (number-to-string nmax))))
  2440. (fm
  2441. (cond
  2442. ((eq org-export-current-backend 'html) (format "<span class=\"linenr\">%s</span>"
  2443. fmt))
  2444. ((eq org-export-current-backend 'ascii) fmt)
  2445. ((eq org-export-current-backend 'latex) fmt)
  2446. ((eq org-export-current-backend 'docbook) fmt)
  2447. (t "")))
  2448. (label-format (or label-format org-coderef-label-format))
  2449. (label-pre (if (string-match "%s" label-format)
  2450. (substring label-format 0 (match-beginning 0))
  2451. label-format))
  2452. (label-post (if (string-match "%s" label-format)
  2453. (substring label-format (match-end 0))
  2454. ""))
  2455. (lbl-re
  2456. (concat
  2457. ".*?\\S-.*?\\([ \t]*\\("
  2458. (regexp-quote label-pre)
  2459. "\\([-a-zA-Z0-9_ ]+\\)"
  2460. (regexp-quote label-post)
  2461. "\\)\\)"))
  2462. ref)
  2463. (org-goto-line (1+ skip1))
  2464. (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
  2465. (if number
  2466. (insert (format fm (incf n)))
  2467. (forward-char 1))
  2468. (when (looking-at lbl-re)
  2469. (setq ref (match-string 3))
  2470. (cond ((numberp replace-labels)
  2471. ;; remove labels; use numbers for references when lines
  2472. ;; are numbered, use labels otherwise
  2473. (delete-region (match-beginning 1) (match-end 1))
  2474. (push (cons ref (if (> n 0) n ref)) org-export-code-refs))
  2475. ((eq replace-labels 'keep)
  2476. ;; don't remove labels; use numbers for references when
  2477. ;; lines are numbered, use labels otherwise
  2478. (goto-char (match-beginning 2))
  2479. (delete-region (match-beginning 2) (match-end 2))
  2480. (insert "(" ref ")")
  2481. (push (cons ref (if (> n 0) n (concat "(" ref ")")))
  2482. org-export-code-refs))
  2483. (t
  2484. ;; don't remove labels and don't use numbers for
  2485. ;; references
  2486. (goto-char (match-beginning 2))
  2487. (delete-region (match-beginning 2) (match-end 2))
  2488. (insert "(" ref ")")
  2489. (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
  2490. (when (eq org-export-current-backend 'html)
  2491. (save-excursion
  2492. (beginning-of-line 1)
  2493. (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
  2494. ref))
  2495. (end-of-line 1)
  2496. (insert "</span>")))))
  2497. (setq org-export-last-code-line-counter-value n)
  2498. (goto-char (point-max))
  2499. (newline)
  2500. (buffer-string))))
  2501. (defun org-search-todo-below (line lines level)
  2502. "Search the subtree below LINE for any TODO entries."
  2503. (let ((rest (cdr (memq line lines)))
  2504. (re org-todo-line-regexp)
  2505. line lv todo)
  2506. (catch 'exit
  2507. (while (setq line (pop rest))
  2508. (if (string-match re line)
  2509. (progn
  2510. (setq lv (- (match-end 1) (match-beginning 1))
  2511. todo (and (match-beginning 2)
  2512. (not (member (match-string 2 line)
  2513. org-done-keywords))))
  2514. ; TODO, not DONE
  2515. (if (<= lv level) (throw 'exit nil))
  2516. (if todo (throw 'exit t))))))))
  2517. ;;;###autoload
  2518. (defun org-export-visible (type arg)
  2519. "Create a copy of the visible part of the current buffer, and export it.
  2520. The copy is created in a temporary buffer and removed after use.
  2521. TYPE is the final key (as a string) that also selects the export command in
  2522. the \\<org-mode-map>\\[org-export] export dispatcher.
  2523. As a special case, if the you type SPC at the prompt, the temporary
  2524. org-mode file will not be removed but presented to you so that you can
  2525. continue to use it. The prefix arg ARG is passed through to the exporting
  2526. command."
  2527. (interactive
  2528. (list (progn
  2529. (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")
  2530. (read-char-exclusive))
  2531. current-prefix-arg))
  2532. (if (not (member type '(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R)))
  2533. (error "Invalid export key"))
  2534. (let* ((binding (cdr (assoc type
  2535. '(
  2536. (?a . org-export-as-ascii)
  2537. (?A . org-export-as-ascii-to-buffer)
  2538. (?n . org-export-as-latin1)
  2539. (?N . org-export-as-latin1-to-buffer)
  2540. (?u . org-export-as-utf8)
  2541. (?U . org-export-as-utf8-to-buffer)
  2542. (?\C-a . org-export-as-ascii)
  2543. (?b . org-export-as-html-and-open)
  2544. (?\C-b . org-export-as-html-and-open)
  2545. (?h . org-export-as-html)
  2546. (?H . org-export-as-html-to-buffer)
  2547. (?R . org-export-region-as-html)
  2548. (?D . org-export-as-docbook)
  2549. (?l . org-export-as-latex)
  2550. (?p . org-export-as-pdf)
  2551. (?d . org-export-as-pdf-and-open)
  2552. (?L . org-export-as-latex-to-buffer)
  2553. (?x . org-export-as-xoxo)))))
  2554. (keepp (equal type ?\ ))
  2555. (file buffer-file-name)
  2556. (buffer (get-buffer-create "*Org Export Visible*"))
  2557. s e)
  2558. ;; Need to hack the drawers here.
  2559. (save-excursion
  2560. (goto-char (point-min))
  2561. (while (re-search-forward org-drawer-regexp nil t)
  2562. (goto-char (match-beginning 1))
  2563. (or (outline-invisible-p) (org-flag-drawer nil))))
  2564. (with-current-buffer buffer (erase-buffer))
  2565. (save-excursion
  2566. (setq s (goto-char (point-min)))
  2567. (while (not (= (point) (point-max)))
  2568. (goto-char (org-find-invisible))
  2569. (append-to-buffer buffer s (point))
  2570. (setq s (goto-char (org-find-visible))))
  2571. (org-cycle-hide-drawers 'all)
  2572. (goto-char (point-min))
  2573. (unless keepp
  2574. ;; Copy all comment lines to the end, to make sure #+ settings are
  2575. ;; still available for the second export step. Kind of a hack, but
  2576. ;; does do the trick.
  2577. (if (looking-at "#[^\r\n]*")
  2578. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  2579. (when (re-search-forward "^\\*+[ \t]+" nil t)
  2580. (while (re-search-backward "[\n\r]#[^\n\r]*" nil t)
  2581. (append-to-buffer buffer (1+ (match-beginning 0))
  2582. (min (point-max) (1+ (match-end 0)))))))
  2583. (set-buffer buffer)
  2584. (let ((buffer-file-name file)
  2585. (org-inhibit-startup t))
  2586. (org-mode)
  2587. (show-all)
  2588. (unless keepp (funcall binding arg))))
  2589. (if (not keepp)
  2590. (kill-buffer buffer)
  2591. (switch-to-buffer-other-window buffer)
  2592. (goto-char (point-min)))))
  2593. (defun org-find-visible ()
  2594. (let ((s (point)))
  2595. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2596. (get-char-property s 'invisible)))
  2597. s))
  2598. (defun org-find-invisible ()
  2599. (let ((s (point)))
  2600. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2601. (not (get-char-property s 'invisible))))
  2602. s))
  2603. (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
  2604. (defun org-export-string (string fmt &optional dir)
  2605. "Export STRING to FMT using existing export facilities.
  2606. During export STRING is saved to a temporary file whose location
  2607. could vary. Optional argument DIR can be used to force the
  2608. directory in which the temporary file is created during export
  2609. which can be useful for resolving relative paths. Dir defaults
  2610. to the value of `temporary-file-directory'."
  2611. (let ((temporary-file-directory (or dir temporary-file-directory))
  2612. (tmp-file (make-temp-file "org-")))
  2613. (unwind-protect
  2614. (with-temp-buffer
  2615. (insert string)
  2616. (write-file tmp-file)
  2617. (org-load-modules-maybe)
  2618. (unless org-local-vars
  2619. (setq org-local-vars (org-get-local-variables)))
  2620. (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
  2621. (list 'let org-local-vars
  2622. (list (intern (format "org-export-as-%s" fmt))
  2623. nil nil nil ''string t))))
  2624. (delete-file tmp-file))))
  2625. ;;;###autoload
  2626. (defun org-export-as-org (arg &optional hidden ext-plist
  2627. to-buffer body-only pub-dir)
  2628. "Make a copy with not-exporting stuff removed.
  2629. The purpose of this function is to provide a way to export the source
  2630. Org file of a webpage in Org format, but with sensitive and/or irrelevant
  2631. stuff removed. This command will remove the following:
  2632. - archived trees (if the variable `org-export-with-archived-trees' is nil)
  2633. - comment blocks and trees starting with the COMMENT keyword
  2634. - only trees that are consistent with `org-export-select-tags'
  2635. and `org-export-exclude-tags'.
  2636. The only arguments that will be used are EXT-PLIST and PUB-DIR,
  2637. all the others will be ignored (but are present so that the general
  2638. mechanism to call publishing functions will work).
  2639. EXT-PLIST is a property list with external parameters overriding
  2640. org-mode's default settings, but still inferior to file-local
  2641. settings. When PUB-DIR is set, use this as the publishing
  2642. directory."
  2643. (interactive "P")
  2644. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  2645. ext-plist
  2646. (org-infile-export-plist)))
  2647. (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2648. (filename (concat (file-name-as-directory
  2649. (or pub-dir
  2650. (org-export-directory :org opt-plist)))
  2651. (file-name-sans-extension
  2652. (file-name-nondirectory bfname))
  2653. ".org"))
  2654. (filename (and filename
  2655. (if (equal (file-truename filename)
  2656. (file-truename bfname))
  2657. (concat (file-name-sans-extension filename)
  2658. "-source."
  2659. (file-name-extension filename))
  2660. filename)))
  2661. (backup-inhibited t)
  2662. (buffer (find-file-noselect filename))
  2663. (region (buffer-string))
  2664. str-ret)
  2665. (save-excursion
  2666. (switch-to-buffer buffer)
  2667. (erase-buffer)
  2668. (insert region)
  2669. (let ((org-inhibit-startup t)) (org-mode))
  2670. (org-install-letbind)
  2671. ;; Get rid of archived trees
  2672. (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
  2673. ;; Remove comment environment and comment subtrees
  2674. (org-export-remove-comment-blocks-and-subtrees)
  2675. ;; Get rid of excluded trees
  2676. (org-export-handle-export-tags (plist-get opt-plist :select-tags)
  2677. (plist-get opt-plist :exclude-tags))
  2678. (when (or (plist-get opt-plist :plain-source)
  2679. (not (or (plist-get opt-plist :plain-source)
  2680. (plist-get opt-plist :htmlized-source))))
  2681. ;; Either nothing special is requested (default call)
  2682. ;; or the plain source is explicitly requested
  2683. ;; so: save it
  2684. (save-buffer))
  2685. (when (plist-get opt-plist :htmlized-source)
  2686. ;; Make the htmlized version
  2687. (require 'htmlize)
  2688. (require 'org-html)
  2689. (font-lock-fontify-buffer)
  2690. (let* ((htmlize-output-type 'css)
  2691. (newbuf (htmlize-buffer)))
  2692. (with-current-buffer newbuf
  2693. (when org-export-htmlized-org-css-url
  2694. (goto-char (point-min))
  2695. (and (re-search-forward
  2696. "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
  2697. nil t)
  2698. (replace-match
  2699. (format
  2700. "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
  2701. org-export-htmlized-org-css-url)
  2702. t t)))
  2703. (write-file (concat filename ".html")))
  2704. (kill-buffer newbuf)))
  2705. (set-buffer-modified-p nil)
  2706. (if (equal to-buffer 'string)
  2707. (progn (setq str-ret (buffer-string))
  2708. (kill-buffer (current-buffer))
  2709. str-ret)
  2710. (kill-buffer (current-buffer))))))
  2711. (defvar org-archive-location) ;; gets loaded with the org-archive require.
  2712. (defun org-get-current-options ()
  2713. "Return a string with current options as keyword options.
  2714. Does include HTML export options as well as TODO and CATEGORY stuff."
  2715. (require 'org-archive)
  2716. (format
  2717. "#+TITLE: %s
  2718. #+AUTHOR: %s
  2719. #+EMAIL: %s
  2720. #+DATE: %s
  2721. #+DESCRIPTION:
  2722. #+KEYWORDS:
  2723. #+LANGUAGE: %s
  2724. #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
  2725. #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
  2726. %s
  2727. #+EXPORT_SELECT_TAGS: %s
  2728. #+EXPORT_EXCLUDE_TAGS: %s
  2729. #+LINK_UP: %s
  2730. #+LINK_HOME: %s
  2731. #+XSLT:
  2732. #+CATEGORY: %s
  2733. #+SEQ_TODO: %s
  2734. #+TYP_TODO: %s
  2735. #+PRIORITIES: %c %c %c
  2736. #+DRAWERS: %s
  2737. #+STARTUP: %s %s %s %s %s
  2738. #+TAGS: %s
  2739. #+FILETAGS: %s
  2740. #+ARCHIVE: %s
  2741. #+LINK: %s
  2742. "
  2743. (buffer-name) (user-full-name) user-mail-address
  2744. (format-time-string (substring (car org-time-stamp-formats) 1 -1))
  2745. org-export-default-language
  2746. org-export-headline-levels
  2747. org-export-with-section-numbers
  2748. org-export-with-toc
  2749. org-export-preserve-breaks
  2750. org-export-html-expand
  2751. org-export-with-fixed-width
  2752. org-export-with-tables
  2753. org-export-with-sub-superscripts
  2754. org-export-with-special-strings
  2755. org-export-with-footnotes
  2756. org-export-with-emphasize
  2757. org-export-with-timestamps
  2758. org-export-with-TeX-macros
  2759. org-export-with-LaTeX-fragments
  2760. org-export-skip-text-before-1st-heading
  2761. org-export-with-drawers
  2762. org-export-with-todo-keywords
  2763. org-export-with-priority
  2764. org-export-with-tags
  2765. (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
  2766. (mapconcat 'identity org-export-select-tags " ")
  2767. (mapconcat 'identity org-export-exclude-tags " ")
  2768. org-export-html-link-up
  2769. org-export-html-link-home
  2770. (or (ignore-errors
  2771. (file-name-sans-extension
  2772. (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
  2773. "NOFILENAME")
  2774. "TODO FEEDBACK VERIFY DONE"
  2775. "Me Jason Marie DONE"
  2776. org-highest-priority org-lowest-priority org-default-priority
  2777. (mapconcat 'identity org-drawers " ")
  2778. (cdr (assoc org-startup-folded
  2779. '((nil . "showall") (t . "overview") (content . "content"))))
  2780. (if org-odd-levels-only "odd" "oddeven")
  2781. (if org-hide-leading-stars "hidestars" "showstars")
  2782. (if org-startup-align-all-tables "align" "noalign")
  2783. (cond ((eq org-log-done t) "logdone")
  2784. ((equal org-log-done 'note) "lognotedone")
  2785. ((not org-log-done) "nologdone"))
  2786. (or (mapconcat (lambda (x)
  2787. (cond
  2788. ((equal :startgroup (car x)) "{")
  2789. ((equal :endgroup (car x)) "}")
  2790. ((equal :newline (car x)) "")
  2791. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  2792. (t (car x))))
  2793. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  2794. (mapconcat 'identity org-file-tags " ")
  2795. org-archive-location
  2796. "org file:~/org/%s.org"
  2797. ))
  2798. ;;;###autoload
  2799. (defun org-insert-export-options-template ()
  2800. "Insert into the buffer a template with information for exporting."
  2801. (interactive)
  2802. (if (not (bolp)) (newline))
  2803. (let ((s (org-get-current-options)))
  2804. (and (string-match "#\\+CATEGORY" s)
  2805. (setq s (substring s 0 (match-beginning 0))))
  2806. (insert s)))
  2807. (defvar org-table-colgroup-info nil)
  2808. (defun org-table-clean-before-export (lines &optional maybe-quoted)
  2809. "Check if the table has a marking column.
  2810. If yes remove the column and the special lines."
  2811. (setq org-table-colgroup-info nil)
  2812. (if (memq nil
  2813. (mapcar
  2814. (lambda (x) (or (string-match "^[ \t]*|-" x)
  2815. (string-match
  2816. (if maybe-quoted
  2817. "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
  2818. "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
  2819. x)))
  2820. lines))
  2821. ;; No special marking column
  2822. (progn
  2823. (setq org-table-clean-did-remove-column nil)
  2824. (delq nil
  2825. (mapcar
  2826. (lambda (x)
  2827. (cond
  2828. ((org-table-colgroup-line-p x)
  2829. ;; This line contains colgroup info, extract it
  2830. ;; and then discard the line
  2831. (setq org-table-colgroup-info
  2832. (mapcar (lambda (x)
  2833. (cond ((member x '("<" "&lt;")) :start)
  2834. ((member x '(">" "&gt;")) :end)
  2835. ((member x '("<>" "&lt;&gt;")) :startend)
  2836. (t nil)))
  2837. (org-split-string x "[ \t]*|[ \t]*")))
  2838. nil)
  2839. ((org-table-cookie-line-p x)
  2840. ;; This line contains formatting cookies, discard it
  2841. nil)
  2842. (t x)))
  2843. lines)))
  2844. ;; there is a special marking column
  2845. (setq org-table-clean-did-remove-column t)
  2846. (delq nil
  2847. (mapcar
  2848. (lambda (x)
  2849. (cond
  2850. ((org-table-colgroup-line-p x)
  2851. ;; This line contains colgroup info, extract it
  2852. ;; and then discard the line
  2853. (setq org-table-colgroup-info
  2854. (mapcar (lambda (x)
  2855. (cond ((member x '("<" "&lt;")) :start)
  2856. ((member x '(">" "&gt;")) :end)
  2857. ((member x '("<>" "&lt;&gt;")) :startend)
  2858. (t nil)))
  2859. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  2860. nil)
  2861. ((org-table-cookie-line-p x)
  2862. ;; This line contains formatting cookies, discard it
  2863. nil)
  2864. ((string-match "^[ \t]*| *[!_^/] *|" x)
  2865. ;; ignore this line
  2866. nil)
  2867. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  2868. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  2869. ;; remove the first column
  2870. (replace-match "\\1|" t nil x))))
  2871. lines))))
  2872. (defun org-export-cleanup-toc-line (s)
  2873. "Remove tags and timestamps from lines going into the toc."
  2874. (when (memq org-export-with-tags '(not-in-toc nil))
  2875. (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s)
  2876. (setq s (replace-match "" t t s))))
  2877. (when org-export-remove-timestamps-from-toc
  2878. (while (string-match org-maybe-keyword-time-regexp s)
  2879. (setq s (replace-match "" t t s))))
  2880. (while (string-match org-bracket-link-regexp s)
  2881. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  2882. t t s)))
  2883. (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s)
  2884. (setq s (replace-match "" t t s)))
  2885. s)
  2886. (defun org-get-text-property-any (pos prop &optional object)
  2887. (or (get-text-property pos prop object)
  2888. (and (setq pos (next-single-property-change pos prop object))
  2889. (get-text-property pos prop object))))
  2890. (defun org-export-get-coderef-format (path desc)
  2891. (save-match-data
  2892. (if (and desc (string-match
  2893. (regexp-quote (concat "(" path ")"))
  2894. desc))
  2895. (replace-match "%s" t t desc)
  2896. (or desc "%s"))))
  2897. (defun org-export-push-to-kill-ring (format)
  2898. "Push buffer content to kill ring.
  2899. The depends on the variable `org-export-copy-to-kill'."
  2900. (when org-export-copy-to-kill-ring
  2901. (org-kill-new (buffer-string))
  2902. (when (fboundp 'x-set-selection)
  2903. (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
  2904. (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
  2905. (message "%s export done, pushed to kill ring and clipboard" format)))
  2906. (provide 'org-exp)
  2907. ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
  2908. ;;; org-exp.el ends here