org-exp.el 120 KB

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