org-exp.el 120 KB

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