org-exp.el 120 KB

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