org-export.el 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278
  1. ;;; org-export.el --- Generic Export Engine For Org
  2. ;; Copyright (C) 2012 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library implements a generic export engine for Org, built on
  17. ;; its syntactical parser: Org Elements.
  18. ;; Besides that parser, the generic exporter is made of three distinct
  19. ;; parts:
  20. ;; - The communication channel consists in a property list, which is
  21. ;; created and updated during the process. Its use is to offer
  22. ;; every piece of information, would it be about initial environment
  23. ;; or contextual data, all in a single place. The exhaustive list
  24. ;; of properties is given in "The Communication Channel" section of
  25. ;; this file.
  26. ;; - The transcoder walks the parse tree, ignores or treat as plain
  27. ;; text elements and objects according to export options, and
  28. ;; eventually calls back-end specific functions to do the real
  29. ;; transcoding, concatenating their return value along the way.
  30. ;; - The filter system is activated at the very beginning and the very
  31. ;; end of the export process, and each time an element or an object
  32. ;; has been converted. It is the entry point to fine-tune standard
  33. ;; output from back-end transcoders.
  34. ;; The core function is `org-export-as'. It returns the transcoded
  35. ;; buffer as a string.
  36. ;; In order to derive an exporter out of this generic implementation,
  37. ;; one can define a transcode function for each element or object.
  38. ;; Such function should return a string for the corresponding element,
  39. ;; without any trailing space, or nil. It must accept three
  40. ;; arguments:
  41. ;; 1. the element or object itself,
  42. ;; 2. its contents, or nil when it isn't recursive,
  43. ;; 3. the property list used as a communication channel.
  44. ;; If no such function is found, that element or object type will
  45. ;; simply be ignored, along with any separating blank line. The same
  46. ;; will happen if the function returns the nil value. If that
  47. ;; function returns the empty string, the type will be ignored, but
  48. ;; the blank lines will be kept.
  49. ;; Contents, when not nil, are stripped from any global indentation
  50. ;; (although the relative one is preserved). They also always end
  51. ;; with a single newline character.
  52. ;; These functions must follow a strict naming convention:
  53. ;; `org-BACKEND-TYPE' where, obviously, BACKEND is the name of the
  54. ;; export back-end and TYPE the type of the element or object handled.
  55. ;; Moreover, two additional functions can be defined. On the one
  56. ;; hand, `org-BACKEND-template' returns the final transcoded string,
  57. ;; and can be used to add a preamble and a postamble to document's
  58. ;; body. It must accept two arguments: the transcoded string and the
  59. ;; property list containing export options. On the other hand,
  60. ;; `org-BACKEND-plain-text', when defined, is to be called on every
  61. ;; text not recognized as an element or an object. It must accept two
  62. ;; arguments: the text string and the information channel.
  63. ;; Any back-end can define its own variables. Among them, those
  64. ;; customizables should belong to the `org-export-BACKEND' group.
  65. ;; Also, a special variable, `org-BACKEND-option-alist', allows to
  66. ;; define buffer keywords and "#+options:" items specific to that
  67. ;; back-end. See `org-export-option-alist' for supported defaults and
  68. ;; syntax.
  69. ;; Tools for common tasks across back-ends are implemented in the
  70. ;; penultimate part of this file. A dispatcher for standard back-ends
  71. ;; is provided in the last one.
  72. ;;; Code:
  73. (eval-when-compile (require 'cl))
  74. (require 'org-element)
  75. ;; Require major back-ends and publishing tools
  76. (require 'org-e-ascii "../../EXPERIMENTAL/org-e-ascii.el")
  77. (require 'org-e-latex "../../EXPERIMENTAL/org-e-latex.el")
  78. (require 'org-e-publish "../../EXPERIMENTAL/org-e-publish.el")
  79. ;;; Internal Variables
  80. ;; Among internal variables, the most important is
  81. ;; `org-export-option-alist'. This variable define the global export
  82. ;; options, shared between every exporter, and how they are acquired.
  83. (defconst org-export-max-depth 19
  84. "Maximum nesting depth for headlines, counting from 0.")
  85. (defconst org-export-option-alist
  86. '((:author "AUTHOR" nil user-full-name t)
  87. (:creator "CREATOR" nil org-export-creator-string)
  88. (:date "DATE" nil nil t)
  89. (:description "DESCRIPTION" nil nil newline)
  90. (:email "EMAIL" nil user-mail-address t)
  91. (:exclude-tags "EXPORT_EXCLUDE_TAGS" nil org-export-exclude-tags split)
  92. (:headline-levels nil "H" org-export-headline-levels)
  93. (:keywords "KEYWORDS" nil nil space)
  94. (:language "LANGUAGE" nil org-export-default-language t)
  95. (:preserve-breaks nil "\\n" org-export-preserve-breaks)
  96. (:section-numbers nil "num" org-export-with-section-numbers)
  97. (:select-tags "EXPORT_SELECT_TAGS" nil org-export-select-tags split)
  98. (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
  99. (:title "TITLE" nil nil space)
  100. (:with-archived-trees nil "arch" org-export-with-archived-trees)
  101. (:with-author nil "author" org-export-with-author)
  102. (:with-creator nil "creator" org-export-with-creator)
  103. (:with-drawers nil "d" org-export-with-drawers)
  104. (:with-email nil "email" org-export-with-email)
  105. (:with-emphasize nil "*" org-export-with-emphasize)
  106. (:with-entities nil "e" org-export-with-entities)
  107. (:with-fixed-width nil ":" org-export-with-fixed-width)
  108. (:with-footnotes nil "f" org-export-with-footnotes)
  109. (:with-priority nil "pri" org-export-with-priority)
  110. (:with-special-strings nil "-" org-export-with-special-strings)
  111. (:with-sub-superscript nil "^" org-export-with-sub-superscripts)
  112. (:with-toc nil "toc" org-export-with-toc)
  113. (:with-tables nil "|" org-export-with-tables)
  114. (:with-tags nil "tags" org-export-with-tags)
  115. (:with-tasks nil "tasks" org-export-with-tasks)
  116. (:with-timestamps nil "<" org-export-with-timestamps)
  117. (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
  118. "Alist between export properties and ways to set them.
  119. The car of the alist is the property name, and the cdr is a list
  120. like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
  121. KEYWORD is a string representing a buffer keyword, or nil.
  122. OPTION is a string that could be found in an #+OPTIONS: line.
  123. DEFAULT is the default value for the property.
  124. BEHAVIOUR determine how Org should handle multiple keywords for
  125. the same property. It is a symbol among:
  126. nil Keep old value and discard the new one.
  127. t Replace old value with the new one.
  128. `space' Concatenate the values, separating them with a space.
  129. `newline' Concatenate the values, separating them with
  130. a newline.
  131. `split' Split values at white spaces, and cons them to the
  132. previous list.
  133. KEYWORD and OPTION have precedence over DEFAULT.
  134. All these properties should be back-end agnostic. For back-end
  135. specific properties, define a similar variable named
  136. `org-BACKEND-option-alist', replacing BACKEND with the name of
  137. the appropriate back-end. You can also redefine properties
  138. there, as they have precedence over these.")
  139. (defconst org-export-special-keywords
  140. '("SETUP_FILE" "OPTIONS" "MACRO")
  141. "List of in-buffer keywords that require special treatment.
  142. These keywords are not directly associated to a property. The
  143. way they are handled must be hard-coded into
  144. `org-export-get-inbuffer-options' function.")
  145. (defconst org-export-filters-alist
  146. '((:filter-babel-call . org-export-filter-babel-call-functions)
  147. (:filter-center-block . org-export-filter-center-block-functions)
  148. (:filter-comment . org-export-filter-comment-functions)
  149. (:filter-comment-block . org-export-filter-comment-block-functions)
  150. (:filter-drawer . org-export-filter-drawer-functions)
  151. (:filter-dynamic-block . org-export-filter-dynamic-block-functions)
  152. (:filter-emphasis . org-export-filter-emphasis-functions)
  153. (:filter-entity . org-export-filter-entity-functions)
  154. (:filter-example-block . org-export-filter-example-block-functions)
  155. (:filter-export-block . org-export-filter-export-block-functions)
  156. (:filter-export-snippet . org-export-filter-export-snippet-functions)
  157. (:filter-final-output . org-export-filter-final-output-functions)
  158. (:filter-fixed-width . org-export-filter-fixed-width-functions)
  159. (:filter-footnote-definition . org-export-filter-footnote-definition-functions)
  160. (:filter-footnote-reference . org-export-filter-footnote-reference-functions)
  161. (:filter-headline . org-export-filter-headline-functions)
  162. (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions)
  163. (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions)
  164. (:filter-inline-src-block . org-export-filter-inline-src-block-functions)
  165. (:filter-inlinetask . org-export-filter-inlinetask-functions)
  166. (:filter-item . org-export-filter-item-functions)
  167. (:filter-keyword . org-export-filter-keyword-functions)
  168. (:filter-latex-environment . org-export-filter-latex-environment-functions)
  169. (:filter-latex-fragment . org-export-filter-latex-fragment-functions)
  170. (:filter-line-break . org-export-filter-line-break-functions)
  171. (:filter-link . org-export-filter-link-functions)
  172. (:filter-macro . org-export-filter-macro-functions)
  173. (:filter-paragraph . org-export-filter-paragraph-functions)
  174. (:filter-parse-tree . org-export-filter-parse-tree-functions)
  175. (:filter-plain-list . org-export-filter-plain-list-functions)
  176. (:filter-plain-text . org-export-filter-plain-text-functions)
  177. (:filter-property-drawer . org-export-filter-property-drawer-functions)
  178. (:filter-quote-block . org-export-filter-quote-block-functions)
  179. (:filter-quote-section . org-export-filter-quote-section-functions)
  180. (:filter-radio-target . org-export-filter-radio-target-functions)
  181. (:filter-section . org-export-filter-section-functions)
  182. (:filter-special-block . org-export-filter-special-block-functions)
  183. (:filter-src-block . org-export-filter-src-block-functions)
  184. (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions)
  185. (:filter-subscript . org-export-filter-subscript-functions)
  186. (:filter-superscript . org-export-filter-superscript-functions)
  187. (:filter-table . org-export-filter-table-functions)
  188. (:filter-target . org-export-filter-target-functions)
  189. (:filter-time-stamp . org-export-filter-time-stamp-functions)
  190. (:filter-verbatim . org-export-filter-verbatim-functions)
  191. (:filter-verse-block . org-export-filter-verse-block-functions))
  192. "Alist between filters properties and initial values.
  193. The key of each association is a property name accessible through
  194. the communication channel its value is a configurable global
  195. variable defining initial filters.
  196. This list is meant to install user specified filters. Back-end
  197. developers may install their own filters using
  198. `org-BACKEND-filters-alist', where BACKEND is the name of the
  199. considered back-end. Filters defined there will always be
  200. prepended to the current list, so they always get applied
  201. first.")
  202. (defconst org-export-default-inline-image-rule
  203. `(("file" .
  204. ,(format "\\.%s\\'"
  205. (regexp-opt
  206. '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
  207. "xpm" "pbm" "pgm" "ppm") t))))
  208. "Default rule for link matching an inline image.
  209. This rule applies to links with no description. By default, it
  210. will be considered as an inline image if it targets a local file
  211. whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
  212. \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
  213. See `org-export-inline-image-p' for more information about
  214. rules.")
  215. ;;; User-configurable Variables
  216. ;; Configuration for the masses.
  217. ;; They should never be evaled directly, as their value is to be
  218. ;; stored in a property list (cf. `org-export-option-alist').
  219. (defgroup org-export nil
  220. "Options for exporting Org mode files."
  221. :tag "Org Export"
  222. :group 'org)
  223. (defgroup org-export-general nil
  224. "General options for export engine."
  225. :tag "Org Export General"
  226. :group 'org-export)
  227. (defcustom org-export-with-archived-trees 'headline
  228. "Whether sub-trees with the ARCHIVE tag should be exported.
  229. This can have three different values:
  230. nil Do not export, pretend this tree is not present.
  231. t Do export the entire tree.
  232. `headline' Only export the headline, but skip the tree below it.
  233. This option can also be set with the #+OPTIONS line,
  234. e.g. \"arch:nil\"."
  235. :group 'org-export-general
  236. :type '(choice
  237. (const :tag "Not at all" nil)
  238. (const :tag "Headline only" 'headline)
  239. (const :tag "Entirely" t)))
  240. (defcustom org-export-with-author t
  241. "Non-nil means insert author name into the exported file.
  242. This option can also be set with the #+OPTIONS line,
  243. e.g. \"author:nil\"."
  244. :group 'org-export-general
  245. :type 'boolean)
  246. (defcustom org-export-with-creator 'comment
  247. "Non-nil means the postamble should contain a creator sentence.
  248. The sentence can be set in `org-export-creator-string' and
  249. defaults to \"Generated by Org mode XX in Emacs XXX.\".
  250. If the value is `comment' insert it as a comment."
  251. :group 'org-export-general
  252. :type '(choice
  253. (const :tag "No creator sentence" nil)
  254. (const :tag "Sentence as a comment" 'comment)
  255. (const :tag "Insert the sentence" t)))
  256. (defcustom org-export-creator-string
  257. (format "Generated by Org mode %s in Emacs %s." org-version emacs-version)
  258. "String to insert at the end of the generated document."
  259. :group 'org-export-general
  260. :type '(string :tag "Creator string"))
  261. (defcustom org-export-with-drawers t
  262. "Non-nil means export contents of standard drawers.
  263. When t, all drawers are exported. This may also be a list of
  264. drawer names to export. This variable doesn't apply to
  265. properties drawers.
  266. This option can also be set with the #+OPTIONS line,
  267. e.g. \"d:nil\"."
  268. :group 'org-export-general
  269. :type '(choice
  270. (const :tag "All drawers" t)
  271. (const :tag "None" nil)
  272. (repeat :tag "Selected drawers"
  273. (string :tag "Drawer name"))))
  274. (defcustom org-export-with-email nil
  275. "Non-nil means insert author email into the exported file.
  276. This option can also be set with the #+OPTIONS line,
  277. e.g. \"email:t\"."
  278. :group 'org-export-general
  279. :type 'boolean)
  280. (defcustom org-export-with-emphasize t
  281. "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
  282. If the export target supports emphasizing text, the word will be
  283. typeset in bold, italic, or underlined, respectively. Not all
  284. export backends support this.
  285. This option can also be set with the #+OPTIONS line, e.g. \"*:nil\"."
  286. :group 'org-export-general
  287. :type 'boolean)
  288. (defcustom org-export-exclude-tags '("noexport")
  289. "Tags that exclude a tree from export.
  290. All trees carrying any of these tags will be excluded from
  291. export. This is without condition, so even subtrees inside that
  292. carry one of the `org-export-select-tags' will be removed."
  293. :group 'org-export-general
  294. :type '(repeat (string :tag "Tag")))
  295. (defcustom org-export-with-fixed-width t
  296. "Non-nil means lines starting with \":\" will be in fixed width font.
  297. This can be used to have pre-formatted text, fragments of code
  298. etc. For example:
  299. : ;; Some Lisp examples
  300. : (while (defc cnt)
  301. : (ding))
  302. will be looking just like this in also HTML. See also the QUOTE
  303. keyword. Not all export backends support this.
  304. This option can also be set with the #+OPTIONS line, e.g. \"::nil\"."
  305. :group 'org-export-translation
  306. :type 'boolean)
  307. (defcustom org-export-with-footnotes t
  308. "Non-nil means Org footnotes should be exported.
  309. This option can also be set with the #+OPTIONS line,
  310. e.g. \"f:nil\"."
  311. :group 'org-export-general
  312. :type 'boolean)
  313. (defcustom org-export-headline-levels 3
  314. "The last level which is still exported as a headline.
  315. Inferior levels will produce itemize lists when exported. Note
  316. that a numeric prefix argument to an exporter function overrides
  317. this setting.
  318. This option can also be set with the #+OPTIONS line, e.g. \"H:2\"."
  319. :group 'org-export-general
  320. :type 'integer)
  321. (defcustom org-export-default-language "en"
  322. "The default language for export and clocktable translations, as a string.
  323. This may have an association in
  324. `org-clock-clocktable-language-setup'."
  325. :group 'org-export-general
  326. :type '(string :tag "Language"))
  327. (defcustom org-export-preserve-breaks nil
  328. "Non-nil means preserve all line breaks when exporting.
  329. Normally, in HTML output paragraphs will be reformatted.
  330. This option can also be set with the #+OPTIONS line,
  331. e.g. \"\\n:t\"."
  332. :group 'org-export-general
  333. :type 'boolean)
  334. (defcustom org-export-with-entities t
  335. "Non-nil means interpret entities when exporting.
  336. For example, HTML export converts \\alpha to &alpha; and \\AA to
  337. &Aring;.
  338. For a list of supported names, see the constant `org-entities'
  339. and the user option `org-entities-user'.
  340. This option can also be set with the #+OPTIONS line,
  341. e.g. \"e:nil\"."
  342. :group 'org-export-general
  343. :type 'boolean)
  344. (defcustom org-export-with-priority nil
  345. "Non-nil means include priority cookies in export.
  346. When nil, remove priority cookies for export."
  347. :group 'org-export-general
  348. :type 'boolean)
  349. (defcustom org-export-with-section-numbers t
  350. "Non-nil means add section numbers to headlines when exporting.
  351. When set to an integer n, numbering will only happen for
  352. headlines whose relative level is higher or equal to n.
  353. This option can also be set with the #+OPTIONS line,
  354. e.g. \"num:t\"."
  355. :group 'org-export-general
  356. :type 'boolean)
  357. (defcustom org-export-select-tags '("export")
  358. "Tags that select a tree for export.
  359. If any such tag is found in a buffer, all trees that do not carry
  360. one of these tags will be deleted before export. Inside trees
  361. that are selected like this, you can still deselect a subtree by
  362. tagging it with one of the `org-export-exclude-tags'."
  363. :group 'org-export-general
  364. :type '(repeat (string :tag "Tag")))
  365. (defcustom org-export-with-special-strings t
  366. "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
  367. When this option is turned on, these strings will be exported as:
  368. Org HTML LaTeX
  369. -----+----------+--------
  370. \\- &shy; \\-
  371. -- &ndash; --
  372. --- &mdash; ---
  373. ... &hellip; \ldots
  374. This option can also be set with the #+OPTIONS line,
  375. e.g. \"-:nil\"."
  376. :group 'org-export-general
  377. :type 'boolean)
  378. (defcustom org-export-with-sub-superscripts t
  379. "Non-nil means interpret \"_\" and \"^\" for export.
  380. When this option is turned on, you can use TeX-like syntax for
  381. sub- and superscripts. Several characters after \"_\" or \"^\"
  382. will be considered as a single item - so grouping with {} is
  383. normally not needed. For example, the following things will be
  384. parsed as single sub- or superscripts.
  385. 10^24 or 10^tau several digits will be considered 1 item.
  386. 10^-12 or 10^-tau a leading sign with digits or a word
  387. x^2-y^3 will be read as x^2 - y^3, because items are
  388. terminated by almost any nonword/nondigit char.
  389. x_{i^2} or x^(2-i) braces or parenthesis do grouping.
  390. Still, ambiguity is possible - so when in doubt use {} to enclose
  391. the sub/superscript. If you set this variable to the symbol
  392. `{}', the braces are *required* in order to trigger
  393. interpretations as sub/superscript. This can be helpful in
  394. documents that need \"_\" frequently in plain text.
  395. This option can also be set with the #+OPTIONS line,
  396. e.g. \"^:nil\"."
  397. :group 'org-export-general
  398. :type '(choice
  399. (const :tag "Interpret them" t)
  400. (const :tag "Curly brackets only" {})
  401. (const :tag "Do not interpret them" nil)))
  402. (defcustom org-export-with-toc t
  403. "Non-nil means create a table of contents in exported files.
  404. The TOC contains headlines with levels up
  405. to`org-export-headline-levels'. When an integer, include levels
  406. up to N in the toc, this may then be different from
  407. `org-export-headline-levels', but it will not be allowed to be
  408. larger than the number of headline levels. When nil, no table of
  409. contents is made.
  410. This option can also be set with the #+OPTIONS line,
  411. e.g. \"toc:nil\" or \"toc:3\"."
  412. :group 'org-export-general
  413. :type '(choice
  414. (const :tag "No Table of Contents" nil)
  415. (const :tag "Full Table of Contents" t)
  416. (integer :tag "TOC to level")))
  417. (defcustom org-export-with-tables t
  418. "If non-nil, lines starting with \"|\" define a table.
  419. For example:
  420. | Name | Address | Birthday |
  421. |-------------+----------+-----------|
  422. | Arthur Dent | England | 29.2.2100 |
  423. This option can also be set with the #+OPTIONS line, e.g. \"|:nil\"."
  424. :group 'org-export-general
  425. :type 'boolean)
  426. (defcustom org-export-with-tags t
  427. "If nil, do not export tags, just remove them from headlines.
  428. If this is the symbol `not-in-toc', tags will be removed from
  429. table of contents entries, but still be shown in the headlines of
  430. the document.
  431. This option can also be set with the #+OPTIONS line,
  432. e.g. \"tags:nil\"."
  433. :group 'org-export-general
  434. :type '(choice
  435. (const :tag "Off" nil)
  436. (const :tag "Not in TOC" not-in-toc)
  437. (const :tag "On" t)))
  438. (defcustom org-export-with-tasks t
  439. "Non-nil means include TODO items for export.
  440. This may have the following values:
  441. t include tasks independent of state.
  442. todo include only tasks that are not yet done.
  443. done include only tasks that are already done.
  444. nil remove all tasks before export
  445. list of keywords keep only tasks with these keywords"
  446. :group 'org-export-general
  447. :type '(choice
  448. (const :tag "All tasks" t)
  449. (const :tag "No tasks" nil)
  450. (const :tag "Not-done tasks" todo)
  451. (const :tag "Only done tasks" done)
  452. (repeat :tag "Specific TODO keywords"
  453. (string :tag "Keyword"))))
  454. (defcustom org-export-time-stamp-file t
  455. "Non-nil means insert a time stamp into the exported file.
  456. The time stamp shows when the file was created.
  457. This option can also be set with the #+OPTIONS line,
  458. e.g. \"timestamp:nil\"."
  459. :group 'org-export-general
  460. :type 'boolean)
  461. (defcustom org-export-with-timestamps t
  462. "If nil, do not export time stamps and associated keywords."
  463. :group 'org-export-general
  464. :type 'boolean)
  465. (defcustom org-export-with-todo-keywords t
  466. "Non-nil means include TODO keywords in export.
  467. When nil, remove all these keywords from the export.")
  468. (defcustom org-export-allow-BIND 'confirm
  469. "Non-nil means allow #+BIND to define local variable values for export.
  470. This is a potential security risk, which is why the user must
  471. confirm the use of these lines."
  472. :group 'org-export-general
  473. :type '(choice
  474. (const :tag "Never" nil)
  475. (const :tag "Always" t)
  476. (const :tag "Ask a confirmation for each file" confirm)))
  477. (defcustom org-export-snippet-translation-alist nil
  478. "Alist between export snippets back-ends and exporter back-ends.
  479. This variable allows to provide shortcuts for export snippets.
  480. For example, with a value of '\(\(\"h\" . \"html\"\)\), the HTML
  481. back-end will recognize the contents of \"@h{<b>}\" as HTML code
  482. while every other back-end will ignore it."
  483. :group 'org-export-general
  484. :type '(repeat
  485. (cons
  486. (string :tag "Shortcut")
  487. (string :tag "Back-end"))))
  488. (defcustom org-export-coding-system nil
  489. "Coding system for the exported file."
  490. :group 'org-export-general
  491. :type 'coding-system)
  492. (defcustom org-export-copy-to-kill-ring t
  493. "Non-nil means exported stuff will also be pushed onto the kill ring."
  494. :group 'org-export-general
  495. :type 'boolean)
  496. (defcustom org-export-initial-scope 'buffer
  497. "The initial scope when exporting with `org-export-dispatch'.
  498. This variable can be either set to `buffer' or `subtree'."
  499. :group 'org-export-general
  500. :type '(choice
  501. (const :tag "Export current buffer" 'buffer)
  502. (const :tag "Export current subtree" 'subtree)))
  503. (defcustom org-export-show-temporary-export-buffer t
  504. "Non-nil means show buffer after exporting to temp buffer.
  505. When Org exports to a file, the buffer visiting that file is ever
  506. shown, but remains buried. However, when exporting to a temporary
  507. buffer, that buffer is popped up in a second window. When this variable
  508. is nil, the buffer remains buried also in these cases."
  509. :group 'org-export-general
  510. :type 'boolean)
  511. (defcustom org-export-dispatch-use-expert-ui nil
  512. "Non-nil means using a non-intrusive `org-export-dispatch'.
  513. In that case, no help buffer is displayed. Though, an indicator
  514. for current export scope is added to the prompt \(i.e. \"b\" when
  515. output is restricted to body only, \"s\" when it is restricted to
  516. the current subtree and \"v\" when only visible elements are
  517. considered for export\). Also, \[?] allows to switch back to
  518. standard mode."
  519. :group 'org-export-general
  520. :type 'boolean)
  521. ;;; The Communication Channel
  522. ;; During export process, every function has access to a number of
  523. ;; properties. They are of three types:
  524. ;; 1. Environment options are collected once at the very beginning of
  525. ;; the process, out of the original buffer and configuration.
  526. ;; Associated to the parse tree, they make an Org closure.
  527. ;; Collecting them is handled by `org-export-get-environment'
  528. ;; function.
  529. ;;
  530. ;; Most environment options are defined through the
  531. ;; `org-export-option-alist' variable.
  532. ;;
  533. ;; 2. Tree properties are extracted directly from the parsed tree,
  534. ;; just before export, by `org-export-collect-tree-properties'.
  535. ;;
  536. ;; 3. Local options are updated during parsing, and their value
  537. ;; depends on the level of recursion. For now, only `:genealogy'
  538. ;; belongs to that category.
  539. ;; Here is the full list of properties available during transcode
  540. ;; process, with their category (option, tree or local) and their
  541. ;; value type.
  542. ;; + `:author' :: Author's name.
  543. ;; - category :: option
  544. ;; - type :: string
  545. ;; + `:back-end' :: Current back-end used for transcoding.
  546. ;; - category :: tree
  547. ;; - type :: symbol
  548. ;; + `:creator' :: String to write as creation information.
  549. ;; - category :: option
  550. ;; - type :: string
  551. ;; + `:date' :: String to use as date.
  552. ;; - category :: option
  553. ;; - type :: string
  554. ;; + `:description' :: Description text for the current data.
  555. ;; - category :: option
  556. ;; - type :: string
  557. ;; + `:email' :: Author's email.
  558. ;; - category :: option
  559. ;; - type :: string
  560. ;; + `:exclude-tags' :: Tags for exclusion of subtrees from export
  561. ;; process.
  562. ;; - category :: option
  563. ;; - type :: list of strings
  564. ;; + `:footnote-definition-alist' :: Alist between footnote labels and
  565. ;; their definition, as parsed data. Only non-inlined footnotes
  566. ;; are represented in this alist. Also, every definition isn't
  567. ;; guaranteed to be referenced in the parse tree. The purpose of
  568. ;; this property is to preserve definitions from oblivion
  569. ;; (i.e. when the parse tree comes from a part of the original
  570. ;; buffer), it isn't meant for direct use in a back-end. To
  571. ;; retrieve a definition relative to a reference, use
  572. ;; `org-export-get-footnote-definition' instead.
  573. ;; - category :: option
  574. ;; - type :: alist (STRING . LIST)
  575. ;; + `:genealogy' :: Flat list of current object or element's parents
  576. ;; from closest to farthest.
  577. ;; - category :: local
  578. ;; - type :: list of elements and objects
  579. ;; + `:headline-levels' :: Maximum level being exported as an
  580. ;; headline. Comparison is done with the relative level of
  581. ;; headlines in the parse tree, not necessarily with their
  582. ;; actual level.
  583. ;; - category :: option
  584. ;; - type :: integer
  585. ;; + `:headline-offset' :: Difference between relative and real level
  586. ;; of headlines in the parse tree. For example, a value of -1
  587. ;; means a level 2 headline should be considered as level
  588. ;; 1 (cf. `org-export-get-relative-level').
  589. ;; - category :: tree
  590. ;; - type :: integer
  591. ;; + `:headline-numbering' :: Alist between headlines' beginning
  592. ;; position and their numbering, as a list of numbers
  593. ;; (cf. `org-export-get-headline-number').
  594. ;; - category :: tree
  595. ;; - type :: alist (INTEGER . LIST)
  596. ;; + `:input-file' :: Full path to input file, if any.
  597. ;; - category :: option
  598. ;; - type :: string or nil
  599. ;; + `:keywords' :: List of keywords attached to data.
  600. ;; - category :: option
  601. ;; - type :: string
  602. ;; + `:language' :: Default language used for translations.
  603. ;; - category :: option
  604. ;; - type :: string
  605. ;; + `:macro-input-file' :: Macro returning file name of input file,
  606. ;; or nil.
  607. ;; - category :: option
  608. ;; - type :: string or nil
  609. ;; + `:parse-tree' :: Whole parse tree, available at any time during
  610. ;; transcoding.
  611. ;; - category :: global
  612. ;; - type :: list (as returned by `org-element-parse-buffer')
  613. ;; + `:preserve-breaks' :: Non-nil means transcoding should preserve
  614. ;; all line breaks.
  615. ;; - category :: option
  616. ;; - type :: symbol (nil, t)
  617. ;; + `:section-numbers' :: Non-nil means transcoding should add
  618. ;; section numbers to headlines.
  619. ;; - category :: option
  620. ;; - type :: symbol (nil, t)
  621. ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees
  622. ;; in transcoding. When such a tag is present,
  623. ;; subtrees without it are de facto excluded from
  624. ;; the process. See `use-select-tags'.
  625. ;; - category :: option
  626. ;; - type :: list of strings
  627. ;; + `:target-list' :: List of targets encountered in the parse tree.
  628. ;; This is used to partly resolve "fuzzy" links
  629. ;; (cf. `org-export-resolve-fuzzy-link').
  630. ;; - category :: tree
  631. ;; - type :: list of strings
  632. ;; + `:time-stamp-file' :: Non-nil means transcoding should insert
  633. ;; a time stamp in the output.
  634. ;; - category :: option
  635. ;; - type :: symbol (nil, t)
  636. ;; + `:use-select-tags' :: When non-nil, a select tags has been found
  637. ;; in the parse tree. Thus, any headline without one will be
  638. ;; filtered out. See `select-tags'.
  639. ;; - category :: tree
  640. ;; - type :: interger or nil
  641. ;; + `:with-archived-trees' :: Non-nil when archived subtrees should
  642. ;; also be transcoded. If it is set to the `headline' symbol,
  643. ;; only the archived headline's name is retained.
  644. ;; - category :: option
  645. ;; - type :: symbol (nil, t, `headline')
  646. ;; + `:with-author' :: Non-nil means author's name should be included
  647. ;; in the output.
  648. ;; - category :: option
  649. ;; - type :: symbol (nil, t)
  650. ;; + `:with-creator' :: Non-nild means a creation sentence should be
  651. ;; inserted at the end of the transcoded string. If the value
  652. ;; is `comment', it should be commented.
  653. ;; - category :: option
  654. ;; - type :: symbol (`comment', nil, t)
  655. ;; + `:with-drawers' :: Non-nil means drawers should be exported. If
  656. ;; its value is a list of names, only drawers with such names
  657. ;; will be transcoded.
  658. ;; - category :: option
  659. ;; - type :: symbol (nil, t) or list of strings
  660. ;; + `:with-email' :: Non-nil means output should contain author's
  661. ;; email.
  662. ;; - category :: option
  663. ;; - type :: symbol (nil, t)
  664. ;; + `:with-emphasize' :: Non-nil means emphasized text should be
  665. ;; interpreted.
  666. ;; - category :: option
  667. ;; - type :: symbol (nil, t)
  668. ;; + `:with-fixed-width' :: Non-nil if transcoder should interpret
  669. ;; strings starting with a colon as a fixed-with (verbatim) area.
  670. ;; - category :: option
  671. ;; - type :: symbol (nil, t)
  672. ;; + `:with-footnotes' :: Non-nil if transcoder should interpret
  673. ;; footnotes.
  674. ;; - category :: option
  675. ;; - type :: symbol (nil, t)
  676. ;; + `:with-priority' :: Non-nil means transcoding should include
  677. ;; priority cookies.
  678. ;; - category :: option
  679. ;; - type :: symbol (nil, t)
  680. ;; + `:with-special-strings' :: Non-nil means transcoding should
  681. ;; interpret special strings in plain text.
  682. ;; - category :: option
  683. ;; - type :: symbol (nil, t)
  684. ;; + `:with-sub-superscript' :: Non-nil means transcoding should
  685. ;; interpret subscript and superscript. With a value of "{}",
  686. ;; only interpret those using curly brackets.
  687. ;; - category :: option
  688. ;; - type :: symbol (nil, {}, t)
  689. ;; + `:with-tables' :: Non-nil means transcoding should interpret
  690. ;; tables.
  691. ;; - category :: option
  692. ;; - type :: symbol (nil, t)
  693. ;; + `:with-tags' :: Non-nil means transcoding should keep tags in
  694. ;; headlines. A `not-in-toc' value will remove them
  695. ;; from the table of contents, if any, nonetheless.
  696. ;; - category :: option
  697. ;; - type :: symbol (nil, t, `not-in-toc')
  698. ;; + `:with-tasks' :: Non-nil means transcoding should include
  699. ;; headlines with a TODO keyword. A `todo' value
  700. ;; will only include headlines with a todo type
  701. ;; keyword while a `done' value will do the
  702. ;; contrary. If a list of strings is provided, only
  703. ;; tasks with keywords belonging to that list will
  704. ;; be kept.
  705. ;; - category :: option
  706. ;; - type :: symbol (t, todo, done, nil) or list of strings
  707. ;; + `:with-timestamps' :: Non-nil means transcoding should include
  708. ;; time stamps and associated keywords. Otherwise, completely
  709. ;; remove them.
  710. ;; - category :: option
  711. ;; - type :: symbol: (t, nil)
  712. ;; + `:with-toc' :: Non-nil means that a table of contents has to be
  713. ;; added to the output. An integer value limits its
  714. ;; depth.
  715. ;; - category :: option
  716. ;; - type :: symbol (nil, t or integer)
  717. ;; + `:with-todo-keywords' :: Non-nil means transcoding should
  718. ;; include TODO keywords.
  719. ;; - category :: option
  720. ;; - type :: symbol (nil, t)
  721. ;;;; Environment Options
  722. ;; Environment options encompass all parameters defined outside the
  723. ;; scope of the parsed data. They come from five sources, in
  724. ;; increasing precedence order:
  725. ;;
  726. ;; - Global variables,
  727. ;; - Options keyword symbols,
  728. ;; - Buffer keywords,
  729. ;; - Subtree properties.
  730. ;; The central internal function with regards to environment options
  731. ;; is `org-export-get-environment'. It updates global variables with
  732. ;; "#+BIND:" keywords, then retrieve and prioritize properties from
  733. ;; the different sources.
  734. ;; The internal functions doing the retrieval are:
  735. ;; `org-export-parse-option-keyword' ,
  736. ;; `org-export-get-subtree-options' ,
  737. ;; `org-export-get-inbuffer-options' and
  738. ;; `org-export-get-global-options'.
  739. ;;
  740. ;; Some properties, which do not rely on the previous sources but
  741. ;; still depend on the original buffer, are taken care of with
  742. ;; `org-export-initial-options'.
  743. ;; Also, `org-export-confirm-letbind' and `org-export-install-letbind'
  744. ;; take care of the part relative to "#+BIND:" keywords.
  745. (defun org-export-get-environment (&optional backend subtreep ext-plist)
  746. "Collect export options from the current buffer.
  747. Optional argument BACKEND is a symbol specifying which back-end
  748. specific options to read, if any.
  749. When optional argument SUBTREEP is non-nil, assume the export is
  750. done against the current sub-tree.
  751. Third optional argument EXT-PLIST is a property list with
  752. external parameters overriding Org default settings, but still
  753. inferior to file-local settings."
  754. ;; First install #+BIND variables.
  755. (org-export-install-letbind-maybe)
  756. ;; Get and prioritize export options...
  757. (let ((options (org-combine-plists
  758. ;; ... from global variables...
  759. (org-export-get-global-options backend)
  760. ;; ... from buffer's name (default title)...
  761. `(:title
  762. ,(or (let ((file (buffer-file-name (buffer-base-buffer))))
  763. (and file
  764. (file-name-sans-extension
  765. (file-name-nondirectory file))))
  766. (buffer-name (buffer-base-buffer))))
  767. ;; ... from an external property list...
  768. ext-plist
  769. ;; ... from in-buffer settings...
  770. (org-export-get-inbuffer-options
  771. backend
  772. (and buffer-file-name
  773. (org-remove-double-quotes buffer-file-name)))
  774. ;; ... and from subtree, when appropriate.
  775. (and subtreep (org-export-get-subtree-options)))))
  776. ;; Add initial options.
  777. (setq options (append (org-export-initial-options) options))
  778. ;; Return plist.
  779. options))
  780. (defun org-export-parse-option-keyword (options &optional backend)
  781. "Parse an OPTIONS line and return values as a plist.
  782. Optional argument BACKEND is a symbol specifying which back-end
  783. specific items to read, if any."
  784. (let* ((all
  785. (append org-export-option-alist
  786. (and backend
  787. (let ((var (intern
  788. (format "org-%s-option-alist" backend))))
  789. (and (boundp var) (eval var))))))
  790. ;; Build an alist between #+OPTION: item and property-name.
  791. (alist (delq nil
  792. (mapcar (lambda (e)
  793. (when (nth 2 e) (cons (regexp-quote (nth 2 e))
  794. (car e))))
  795. all)))
  796. plist)
  797. (mapc (lambda (e)
  798. (when (string-match (concat "\\(\\`\\|[ \t]\\)"
  799. (car e)
  800. ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
  801. options)
  802. (setq plist (plist-put plist
  803. (cdr e)
  804. (car (read-from-string
  805. (match-string 2 options)))))))
  806. alist)
  807. plist))
  808. (defun org-export-get-subtree-options ()
  809. "Get export options in subtree at point.
  810. Assume point is at subtree's beginning.
  811. Return options as a plist."
  812. (let (prop plist)
  813. (when (setq prop (progn (looking-at org-todo-line-regexp)
  814. (or (save-match-data
  815. (org-entry-get (point) "EXPORT_TITLE"))
  816. (org-match-string-no-properties 3))))
  817. (setq plist
  818. (plist-put
  819. plist :title
  820. (org-element-parse-secondary-string
  821. prop
  822. (cdr (assq 'keyword org-element-string-restrictions))))))
  823. (when (setq prop (org-entry-get (point) "EXPORT_TEXT"))
  824. (setq plist (plist-put plist :text prop)))
  825. (when (setq prop (org-entry-get (point) "EXPORT_AUTHOR"))
  826. (setq plist (plist-put plist :author prop)))
  827. (when (setq prop (org-entry-get (point) "EXPORT_DATE"))
  828. (setq plist (plist-put plist :date prop)))
  829. (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
  830. (setq plist (org-export-add-options-to-plist plist prop)))
  831. plist))
  832. (defun org-export-get-inbuffer-options (&optional backend files)
  833. "Return current buffer export options, as a plist.
  834. Optional argument BACKEND, when non-nil, is a symbol specifying
  835. which back-end specific options should also be read in the
  836. process.
  837. Optional argument FILES is a list of setup files names read so
  838. far, used to avoid circular dependencies.
  839. Assume buffer is in Org mode. Narrowing, if any, is ignored."
  840. (org-with-wide-buffer
  841. (goto-char (point-min))
  842. (let ((case-fold-search t) plist)
  843. ;; 1. Special keywords, as in `org-export-special-keywords'.
  844. (let ((special-re (org-make-options-regexp org-export-special-keywords)))
  845. (while (re-search-forward special-re nil t)
  846. (let ((element (org-element-at-point)))
  847. (when (eq (car element) 'keyword)
  848. (let ((key (upcase (org-element-get-property :key element)))
  849. (val (org-element-get-property :value element)))
  850. (setq plist
  851. (org-combine-plists
  852. plist
  853. (cond
  854. ((string= key "SETUP_FILE")
  855. (let ((file
  856. (expand-file-name
  857. (org-remove-double-quotes (org-trim val)))))
  858. ;; Avoid circular dependencies.
  859. (unless (member file files)
  860. (with-temp-buffer
  861. (insert (org-file-contents file 'noerror))
  862. (org-mode)
  863. (org-export-get-inbuffer-options
  864. backend (cons file files))))))
  865. ((string= key "OPTIONS")
  866. (org-export-parse-option-keyword val backend))
  867. ((string= key "MACRO")
  868. (when (string-match
  869. "^\\([-a-zA-Z0-9_]+\\)\\(?:[ \t]+\\(.*?\\)[ \t]*$\\)?"
  870. val)
  871. (let ((key
  872. (intern
  873. (concat ":macro-"
  874. (downcase (match-string 1 val)))))
  875. (value (match-string 2 val)))
  876. (cond
  877. ((not value) "")
  878. ((string-match "\\`(eval\\>" value)
  879. (list key value))
  880. (t
  881. (list
  882. key
  883. ;; If user explicitly asks for a newline, be
  884. ;; sure to preserve it from further filling
  885. ;; with `hard-newline'.
  886. (replace-regexp-in-string
  887. "\\\\n" hard-newline value)))))))))))))))
  888. ;; 2. Standard options, as in `org-export-option-alist'.
  889. (let* ((all (append org-export-option-alist
  890. ;; Also look for back-end specific options
  891. ;; if BACKEND is defined.
  892. (and backend
  893. (let ((var
  894. (intern
  895. (format "org-%s-option-alist" backend))))
  896. (and (boundp var) (eval var))))))
  897. ;; Build alist between keyword name and property name.
  898. (alist
  899. (delq nil (mapcar
  900. (lambda (e) (when (nth 1 e) (cons (nth 1 e) (car e))))
  901. all)))
  902. ;; Build regexp matching all keywords associated to export
  903. ;; options. Note: the search is case insensitive.
  904. (opt-re (org-make-options-regexp
  905. (delq nil (mapcar (lambda (e) (nth 1 e)) all)))))
  906. (goto-char (point-min))
  907. (while (re-search-forward opt-re nil t)
  908. (let ((element (org-element-at-point)))
  909. (when (eq (car element) 'keyword)
  910. (let* ((key (upcase (org-element-get-property :key element)))
  911. (val (org-element-get-property :value element))
  912. (prop (cdr (assoc key alist)))
  913. (behaviour (nth 4 (assq prop all))))
  914. (setq plist
  915. (plist-put
  916. plist prop
  917. ;; Handle value depending on specified BEHAVIOUR.
  918. (case behaviour
  919. (space
  920. (if (not (plist-get plist prop)) (org-trim val)
  921. (concat (plist-get plist prop) " " (org-trim val))))
  922. (newline
  923. (org-trim
  924. (concat (plist-get plist prop) "\n" (org-trim val))))
  925. (split
  926. `(,@(plist-get plist prop) ,@(org-split-string val)))
  927. ('t val)
  928. (otherwise (plist-get plist prop)))))))))
  929. ;; Parse keywords specified in `org-element-parsed-keywords'.
  930. (mapc
  931. (lambda (key)
  932. (let* ((prop (cdr (assoc key alist)))
  933. (value (and prop (plist-get plist prop))))
  934. (when (stringp value)
  935. (setq plist
  936. (plist-put
  937. plist prop
  938. (org-element-parse-secondary-string
  939. value
  940. (cdr (assq 'keyword org-element-string-restrictions))))))))
  941. org-element-parsed-keywords))
  942. ;; 3. Return final value.
  943. plist)))
  944. (defun org-export-get-global-options (&optional backend)
  945. "Return global export options as a plist.
  946. Optional argument BACKEND, if non-nil, is a symbol specifying
  947. which back-end specific export options should also be read in the
  948. process."
  949. (let ((all (append org-export-option-alist
  950. (and backend
  951. (let ((var (intern
  952. (format "org-%s-option-alist" backend))))
  953. (and (boundp var) (eval var))))))
  954. ;; Output value.
  955. plist)
  956. (mapc (lambda (cell)
  957. (setq plist (plist-put plist (car cell) (eval (nth 3 cell)))))
  958. all)
  959. ;; Return value.
  960. plist))
  961. (defun org-export-initial-options ()
  962. "Return a plist with properties related to input buffer."
  963. (let ((visited-file (buffer-file-name (buffer-base-buffer))))
  964. (list
  965. ;; Store full path of input file name, or nil. For internal use.
  966. :input-file visited-file
  967. ;; `:macro-date', `:macro-time' and `:macro-property' could as well
  968. ;; be initialized as tree properties, since they don't depend on
  969. ;; initial environment. Though, it may be more logical to keep
  970. ;; them close to other ":macro-" properties.
  971. :macro-date "(eval (format-time-string \"$1\"))"
  972. :macro-time "(eval (format-time-string \"$1\"))"
  973. :macro-property "(eval (org-entry-get nil \"$1\" 'selective))"
  974. :macro-modification-time
  975. (and visited-file
  976. (file-exists-p visited-file)
  977. (concat "(eval (format-time-string \"$1\" '"
  978. (prin1-to-string (nth 5 (file-attributes visited-file)))
  979. "))"))
  980. ;; Store input file name as a macro.
  981. :macro-input-file (and visited-file (file-name-nondirectory visited-file))
  982. ;; Footnotes definitions must be collected in the original buffer,
  983. ;; as there's no insurance that they will still be in the parse
  984. ;; tree, due to some narrowing.
  985. :footnote-definition-alist
  986. (let (alist)
  987. (org-with-wide-buffer
  988. (goto-char (point-min))
  989. (while (re-search-forward org-footnote-definition-re nil t)
  990. (let ((def (org-footnote-at-definition-p)))
  991. (when def
  992. (org-skip-whitespace)
  993. (push (cons (car def)
  994. (save-restriction
  995. (narrow-to-region (point) (nth 2 def))
  996. ;; Like `org-element-parse-buffer', but
  997. ;; makes sure the definition doesn't start
  998. ;; with a section element.
  999. (nconc
  1000. (list 'org-data nil)
  1001. (org-element-parse-elements
  1002. (point-min) (point-max) nil nil nil nil nil))))
  1003. alist))))
  1004. alist)))))
  1005. (defvar org-export-allow-BIND-local nil)
  1006. (defun org-export-confirm-letbind ()
  1007. "Can we use #+BIND values during export?
  1008. By default this will ask for confirmation by the user, to divert
  1009. possible security risks."
  1010. (cond
  1011. ((not org-export-allow-BIND) nil)
  1012. ((eq org-export-allow-BIND t) t)
  1013. ((local-variable-p 'org-export-allow-BIND-local) org-export-allow-BIND-local)
  1014. (t (org-set-local 'org-export-allow-BIND-local
  1015. (yes-or-no-p "Allow BIND values in this buffer? ")))))
  1016. (defun org-export-install-letbind-maybe ()
  1017. "Install the values from #+BIND lines as local variables.
  1018. Variables must be installed before in-buffer options are
  1019. retrieved."
  1020. (let (letbind pair)
  1021. (org-with-wide-buffer
  1022. (goto-char (point-min))
  1023. (while (re-search-forward (org-make-options-regexp '("BIND")) nil t)
  1024. (when (org-export-confirm-letbind)
  1025. (push (read (concat "(" (org-match-string-no-properties 2) ")"))
  1026. letbind))))
  1027. (while (setq pair (pop letbind))
  1028. (org-set-local (car pair) (nth 1 pair)))))
  1029. ;;;; Tree Properties
  1030. ;; Tree properties are infromation extracted from parse tree. They
  1031. ;; are initialized at the beginning of the transcoding process by
  1032. ;; `org-export-collect-tree-properties'.
  1033. ;; Dedicated functions focus on computing the value of specific tree
  1034. ;; properties during initialization. Thus,
  1035. ;; `org-export-use-select-tag-p' determines if an headline makes use
  1036. ;; of an export tag enforcing inclusion. `org-export-get-min-level'
  1037. ;; gets the minimal exportable level, used as a basis to compute
  1038. ;; relative level for headlines. `org-export-get-point-max' returns
  1039. ;; the maximum exportable ending position in the parse tree.
  1040. ;; Eventually `org-export-collect-headline-numbering' builds an alist
  1041. ;; between headlines' beginning position and their numbering.
  1042. (defun org-export-collect-tree-properties (data info backend)
  1043. "Extract tree properties from parse tree.
  1044. DATA is the parse tree from which information is retrieved. INFO
  1045. is a list holding export options. BACKEND is the back-end called
  1046. for transcoding, as a symbol.
  1047. Following tree properties are set:
  1048. `:back-end' Back-end used for transcoding.
  1049. `:headline-offset' Offset between true level of headlines and
  1050. local level. An offset of -1 means an headline
  1051. of level 2 should be considered as a level
  1052. 1 headline in the context.
  1053. `:headline-numbering' Alist of all headlines' beginning position
  1054. as key an the associated numbering as value.
  1055. `:parse-tree' Whole parse tree.
  1056. `:target-list' List of all targets in the parse tree.
  1057. `:use-select-tags' Non-nil when parsed tree use a special tag to
  1058. enforce transcoding of the headline."
  1059. ;; First, set `:use-select-tags' property, as it will be required
  1060. ;; for further computations.
  1061. (setq info
  1062. (org-combine-plists
  1063. info `(:use-select-tags ,(org-export-use-select-tags-p data info))))
  1064. ;; Then get `:headline-offset' in order to be able to use
  1065. ;; `org-export-get-relative-level'.
  1066. (setq info
  1067. (org-combine-plists
  1068. info `(:headline-offset ,(- 1 (org-export-get-min-level data info)))))
  1069. ;; Now, get the rest of the tree properties, now `:use-select-tags'
  1070. ;; is set...
  1071. (nconc
  1072. `(:parse-tree
  1073. ,data
  1074. :target-list
  1075. ,(org-element-map data 'target (lambda (target local) target) info)
  1076. :headline-numbering ,(org-export-collect-headline-numbering data info)
  1077. :back-end ,backend)
  1078. info))
  1079. (defun org-export-use-select-tags-p (data options)
  1080. "Non-nil when data use a tag enforcing transcoding.
  1081. DATA is parsed data as returned by `org-element-parse-buffer'.
  1082. OPTIONS is a plist holding export options."
  1083. (org-element-map
  1084. data
  1085. 'headline
  1086. (lambda (headline info)
  1087. (let ((tags (org-element-get-property :with-tags headline)))
  1088. (and tags (string-match
  1089. (format ":%s:" (plist-get info :select-tags)) tags))))
  1090. options
  1091. 'stop-at-first-match))
  1092. (defun org-export-get-min-level (data options)
  1093. "Return minimum exportable headline's level in DATA.
  1094. DATA is parsed tree as returned by `org-element-parse-buffer'.
  1095. OPTIONS is a plist holding export options."
  1096. (catch 'exit
  1097. (let ((min-level 10000))
  1098. (mapc (lambda (blob)
  1099. (when (and (eq (car blob) 'headline)
  1100. (not (org-export-skip-p blob options)))
  1101. (setq min-level
  1102. (min (org-element-get-property :level blob) min-level)))
  1103. (when (= min-level 1) (throw 'exit 1)))
  1104. (org-element-get-contents data))
  1105. ;; If no headline was found, for the sake of consistency, set
  1106. ;; minimum level to 1 nonetheless.
  1107. (if (= min-level 10000) 1 min-level))))
  1108. (defun org-export-collect-headline-numbering (data options)
  1109. "Return numbering of all exportable headlines in a parse tree.
  1110. DATA is the parse tree. OPTIONS is the plist holding export
  1111. options.
  1112. Return an alist whose key is an headline and value is its
  1113. associated numbering \(in the shape of a list of numbers\)."
  1114. (let ((numbering (make-vector org-export-max-depth 0)))
  1115. (org-element-map
  1116. data
  1117. 'headline
  1118. (lambda (headline info)
  1119. (let ((relative-level
  1120. (1- (org-export-get-relative-level headline info))))
  1121. (cons
  1122. headline
  1123. (loop for n across numbering
  1124. for idx from 0 to org-export-max-depth
  1125. when (< idx relative-level) collect n
  1126. when (= idx relative-level) collect (aset numbering idx (1+ n))
  1127. when (> idx relative-level) do (aset numbering idx 0)))))
  1128. options)))
  1129. ;;; The Transcoder
  1130. ;; This function reads Org data (obtained with, i.e.
  1131. ;; `org-element-parse-buffer') and transcodes it into a specified
  1132. ;; back-end output. It takes care of updating local properties,
  1133. ;; filtering out elements or objects according to export options and
  1134. ;; organizing the output blank lines and white space are preserved.
  1135. ;; Though, this function is inapropriate for secondary strings, which
  1136. ;; require a fresh copy of the plist passed as INFO argument. Thus,
  1137. ;; `org-export-secondary-string' is provided for that specific task.
  1138. ;; Internally, three functions handle the filtering of objects and
  1139. ;; elements during the export. More precisely, `org-export-skip-p'
  1140. ;; determines if the considered object or element should be ignored
  1141. ;; altogether, `org-export-interpret-p' tells which elements or
  1142. ;; objects should be seen as real Org syntax and `org-export-expand'
  1143. ;; transforms the others back into their original shape.
  1144. (defun org-export-data (data backend info)
  1145. "Convert DATA to a string into BACKEND format.
  1146. DATA is a nested list as returned by `org-element-parse-buffer'.
  1147. BACKEND is a symbol among supported exporters.
  1148. INFO is a plist holding export options and also used as
  1149. a communication channel between elements when walking the nested
  1150. list. See `org-export-update-info' function for more
  1151. details.
  1152. Return transcoded string."
  1153. (mapconcat
  1154. ;; BLOB can be an element, an object, a string, or nil.
  1155. (lambda (blob)
  1156. (cond
  1157. ((not blob) nil)
  1158. ;; BLOB is a string. Check if the optional transcoder for plain
  1159. ;; text exists, and call it in that case. Otherwise, simply
  1160. ;; return string. Also update INFO and call
  1161. ;; `org-export-filter-plain-text-functions'.
  1162. ((stringp blob)
  1163. (let ((transcoder (intern (format "org-%s-plain-text" backend))))
  1164. (org-export-filter-apply-functions
  1165. (plist-get info :filter-plain-text)
  1166. (if (fboundp transcoder) (funcall transcoder blob info) blob)
  1167. backend info)))
  1168. ;; BLOB is an element or an object.
  1169. (t
  1170. (let* ((type (if (stringp blob) 'plain-text (car blob)))
  1171. ;; 1. Determine the appropriate TRANSCODER.
  1172. (transcoder
  1173. (cond
  1174. ;; 1.0 A full Org document is inserted.
  1175. ((eq type 'org-data) 'identity)
  1176. ;; 1.1. BLOB should be ignored.
  1177. ((org-export-skip-p blob info) nil)
  1178. ;; 1.2. BLOB shouldn't be transcoded. Interpret it
  1179. ;; back into Org syntax.
  1180. ((not (org-export-interpret-p blob info))
  1181. 'org-export-expand)
  1182. ;; 1.3. Else apply naming convention.
  1183. (t (let ((trans (intern
  1184. (format "org-%s-%s" backend type))))
  1185. (and (fboundp trans) trans)))))
  1186. ;; 2. Compute CONTENTS of BLOB.
  1187. (contents
  1188. (cond
  1189. ;; Case 0. No transcoder defined: ignore BLOB.
  1190. ((not transcoder) nil)
  1191. ;; Case 1. Transparently export an Org document.
  1192. ((eq type 'org-data) (org-export-data blob backend info))
  1193. ;; Case 2. For a recursive object.
  1194. ((memq type org-element-recursive-objects)
  1195. (org-export-data
  1196. blob backend
  1197. (org-combine-plists
  1198. info
  1199. `(:genealogy ,(cons blob (plist-get info :genealogy))))))
  1200. ;; Case 3. For a recursive element.
  1201. ((memq type org-element-greater-elements)
  1202. ;; Ignore contents of an archived tree
  1203. ;; when `:with-archived-trees' is `headline'.
  1204. (unless (and
  1205. (eq type 'headline)
  1206. (eq (plist-get info :with-archived-trees) 'headline)
  1207. (org-element-get-property :archivedp blob))
  1208. (org-element-normalize-string
  1209. (org-export-data
  1210. blob backend
  1211. (org-combine-plists
  1212. info `(:genealogy
  1213. ,(cons blob (plist-get info :genealogy))))))))
  1214. ;; Case 4. For a paragraph.
  1215. ((eq type 'paragraph)
  1216. (let ((paragraph
  1217. (org-element-normalize-contents
  1218. blob
  1219. ;; When normalizing contents of an item or
  1220. ;; a footnote definition, ignore first line's
  1221. ;; indentation: there is none and it might be
  1222. ;; misleading.
  1223. (and (not (org-export-get-previous-element blob info))
  1224. (let ((parent (caar (plist-get info :genealogy))))
  1225. (memq parent '(footnote-definition item)))))))
  1226. (org-export-data
  1227. paragraph backend
  1228. (org-combine-plists
  1229. info `(:genealogy
  1230. ,(cons paragraph (plist-get info :genealogy)))))))))
  1231. ;; 3. Transcode BLOB into RESULTS string.
  1232. (results (cond
  1233. ((not transcoder) nil)
  1234. ((eq transcoder 'org-export-expand)
  1235. (org-export-data
  1236. `(org-data nil ,(funcall transcoder blob contents))
  1237. backend info))
  1238. (t (funcall transcoder blob contents info)))))
  1239. ;; 4. Discard nil results. Otherwise, update INFO, append
  1240. ;; the same white space between elements or objects as in
  1241. ;; the original buffer, and call appropriate filters.
  1242. (when results
  1243. ;; No filter for a full document.
  1244. (if (eq type 'org-data) results
  1245. (org-export-filter-apply-functions
  1246. (plist-get info (intern (format ":filter-%s" type)))
  1247. (let ((post-blank (org-element-get-property :post-blank blob)))
  1248. (if (memq type org-element-all-elements)
  1249. (concat (org-element-normalize-string results)
  1250. (make-string post-blank ?\n))
  1251. (concat results (make-string post-blank ? ))))
  1252. backend info)))))))
  1253. (org-element-get-contents data) ""))
  1254. (defun org-export-secondary-string (secondary backend info)
  1255. "Convert SECONDARY string into BACKEND format.
  1256. SECONDARY is a nested list as returned by
  1257. `org-element-parse-secondary-string'.
  1258. BACKEND is a symbol among supported exporters. INFO is a plist
  1259. used as a communication channel.
  1260. Return transcoded string."
  1261. ;; Make SECONDARY acceptable for `org-export-data'.
  1262. (let ((s (if (listp secondary) secondary (list secondary))))
  1263. (org-export-data `(org-data nil ,@s) backend (copy-sequence info))))
  1264. (defun org-export-skip-p (blob info)
  1265. "Non-nil when element or object BLOB should be skipped during export.
  1266. INFO is the plist holding export options."
  1267. ;; Check headline.
  1268. (unless (stringp blob)
  1269. (case (car blob)
  1270. ('headline
  1271. (let ((with-tasks (plist-get info :with-tasks))
  1272. (todo (org-element-get-property :todo-keyword blob))
  1273. (todo-type (org-element-get-property :todo-type blob))
  1274. (archived (plist-get info :with-archived-trees))
  1275. (tag-list (let ((tags (org-element-get-property :tags blob)))
  1276. (and tags (org-split-string tags ":")))))
  1277. (or
  1278. ;; Ignore subtrees with an exclude tag.
  1279. (loop for k in (plist-get info :exclude-tags)
  1280. thereis (member k tag-list))
  1281. ;; Ignore subtrees without a select tag, when such tag is found
  1282. ;; in the buffer.
  1283. (and (plist-get info :use-select-tags)
  1284. (loop for k in (plist-get info :select-tags)
  1285. never (member k tag-list)))
  1286. ;; Ignore commented sub-trees.
  1287. (org-element-get-property :commentedp blob)
  1288. ;; Ignore archived subtrees if `:with-archived-trees' is nil.
  1289. (and (not archived) (org-element-get-property :archivedp blob))
  1290. ;; Ignore tasks, if specified by `:with-tasks' property.
  1291. (and todo (not with-tasks))
  1292. (and todo
  1293. (memq with-tasks '(todo done))
  1294. (not (eq todo-type with-tasks)))
  1295. (and todo
  1296. (consp with-tasks)
  1297. (not (member todo with-tasks))))))
  1298. ;; Check time-stamp.
  1299. ('time-stamp (not (plist-get info :with-timestamps)))
  1300. ;; Check drawer.
  1301. ('drawer
  1302. (or (not (plist-get info :with-drawers))
  1303. (and (consp (plist-get info :with-drawers))
  1304. (not (member (org-element-get-property :drawer-name blob)
  1305. (plist-get info :with-drawers))))))
  1306. ;; Check export snippet.
  1307. ('export-snippet
  1308. (let* ((raw-back-end (org-element-get-property :back-end blob))
  1309. (true-back-end
  1310. (or (cdr (assoc raw-back-end org-export-snippet-translation-alist))
  1311. raw-back-end)))
  1312. (not (string= (symbol-name (plist-get info :back-end))
  1313. true-back-end)))))))
  1314. (defun org-export-interpret-p (blob info)
  1315. "Non-nil if element or object BLOB should be interpreted as Org syntax.
  1316. Check is done according to export options INFO, stored as
  1317. a plist."
  1318. (case (car blob)
  1319. ;; ... entities...
  1320. (entity (plist-get info :with-entities))
  1321. ;; ... emphasis...
  1322. (emphasis (plist-get info :with-emphasize))
  1323. ;; ... fixed-width areas.
  1324. (fixed-width (plist-get info :with-fixed-width))
  1325. ;; ... footnotes...
  1326. ((footnote-definition footnote-reference)
  1327. (plist-get info :with-footnotes))
  1328. ;; ... sub/superscripts...
  1329. ((subscript superscript)
  1330. (let ((sub/super-p (plist-get info :with-sub-superscript)))
  1331. (if (eq sub/super-p '{})
  1332. (org-element-get-property :use-brackets-p blob)
  1333. sub/super-p)))
  1334. ;; ... tables...
  1335. (table (plist-get info :with-tables))
  1336. (otherwise t)))
  1337. (defsubst org-export-expand (blob contents)
  1338. "Expand a parsed element or object to its original state.
  1339. BLOB is either an element or an object. CONTENTS is its
  1340. contents, as a string or nil."
  1341. (funcall
  1342. (intern (format "org-element-%s-interpreter" (car blob))) blob contents))
  1343. ;;; The Filter System
  1344. ;; Filters allow end-users to tweak easily the transcoded output.
  1345. ;; They are the functional counterpart of hooks, as every filter in
  1346. ;; a set is applied to the return value of the previous one.
  1347. ;; Every set is back-end agnostic. Although, a filter is always
  1348. ;; called, in addition to the string it applies to, with the back-end
  1349. ;; used as argument, so it's easy enough for the end-user to add
  1350. ;; back-end specific filters in the set. The communication channel,
  1351. ;; as a plist, is required as the third argument.
  1352. ;; Filters sets are defined below. There are of four types:
  1353. ;; - `org-export-filter-parse-tree-functions' applies directly on the
  1354. ;; complete parsed tree. It's the only filters set that doesn't
  1355. ;; apply to a string.
  1356. ;; - `org-export-filter-final-output-functions' applies to the final
  1357. ;; transcoded string.
  1358. ;; - `org-export-filter-plain-text-functions' applies to any string
  1359. ;; not recognized as Org syntax.
  1360. ;; - `org-export-filter-TYPE-functions' applies on the string returned
  1361. ;; after an element or object of type TYPE has been transcoded.
  1362. ;; All filters sets are applied through
  1363. ;; `org-export-filter-apply-functions' function. Filters in a set are
  1364. ;; applied in a LIFO fashion. It allows developers to be sure that
  1365. ;; their filters will be applied first.
  1366. ;; Filters properties are installed in communication channel just
  1367. ;; before parsing, with `org-export-install-filters' function.
  1368. ;;;; Special Filters
  1369. (defvar org-export-filter-parse-tree-functions nil
  1370. "Filter, or list of filters, applied to the parsed tree.
  1371. Each filter is called with three arguments: the parse tree, as
  1372. returned by `org-element-parse-buffer', the back-end, as
  1373. a symbol, and the communication channel, as a plist. It must
  1374. return the modified parse tree to transcode.")
  1375. (defvar org-export-filter-final-output-functions nil
  1376. "Filter, or list of filters, applied to the transcoded string.
  1377. Each filter is called with three arguments: the full transcoded
  1378. string, the back-end, as a symbol, and the communication channel,
  1379. as a plist. It must return a string that will be used as the
  1380. final export output.")
  1381. (defvar org-export-filter-plain-text-functions nil
  1382. "Filter, or list of filters, applied to plain text.
  1383. Each filter is called with three arguments: a string which
  1384. contains no Org syntax, the back-end, as a symbol, and the
  1385. communication channel, as a plist. It must return a string or
  1386. nil.")
  1387. ;;;; Elements Filters
  1388. (defvar org-export-filter-center-block-functions nil
  1389. "List of functions applied to a transcoded center block.
  1390. Each filter is called with three arguments: the transcoded center
  1391. block, as a string, the back-end, as a symbol, and the
  1392. communication channel, as a plist. It must return a string or
  1393. nil.")
  1394. (defvar org-export-filter-drawer-functions nil
  1395. "List of functions applied to a transcoded drawer.
  1396. Each filter is called with three arguments: the transcoded
  1397. drawer, as a string, the back-end, as a symbol, and the
  1398. communication channel, as a plist. It must return a string or
  1399. nil.")
  1400. (defvar org-export-filter-dynamic-block-functions nil
  1401. "List of functions applied to a transcoded dynamic-block.
  1402. Each filter is called with three arguments: the transcoded
  1403. dynamic-block, as a string, the back-end, as a symbol, and the
  1404. communication channel, as a plist. It must return a string or
  1405. nil.")
  1406. (defvar org-export-filter-headline-functions nil
  1407. "List of functions applied to a transcoded headline.
  1408. Each filter is called with three arguments: the transcoded
  1409. headline, as a string, the back-end, as a symbol, and the
  1410. communication channel, as a plist. It must return a string or
  1411. nil.")
  1412. (defvar org-export-filter-inlinetask-functions nil
  1413. "List of functions applied to a transcoded inlinetask.
  1414. Each filter is called with three arguments: the transcoded
  1415. inlinetask, as a string, the back-end, as a symbol, and the
  1416. communication channel, as a plist. It must return a string or
  1417. nil.")
  1418. (defvar org-export-filter-plain-list-functions nil
  1419. "List of functions applied to a transcoded plain-list.
  1420. Each filter is called with three arguments: the transcoded
  1421. plain-list, as a string, the back-end, as a symbol, and the
  1422. communication channel, as a plist. It must return a string or
  1423. nil.")
  1424. (defvar org-export-filter-item-functions nil
  1425. "List of functions applied to a transcoded item.
  1426. Each filter is called with three arguments: the transcoded item,
  1427. as a string, the back-end, as a symbol, and the communication
  1428. channel, as a plist. It must return a string or nil.")
  1429. (defvar org-export-filter-comment-functions nil
  1430. "List of functions applied to a transcoded comment.
  1431. Each filter is called with three arguments: the transcoded
  1432. comment, as a string, the back-end, as a symbol, and the
  1433. communication channel, as a plist. It must return a string or
  1434. nil.")
  1435. (defvar org-export-filter-comment-block-functions nil
  1436. "List of functions applied to a transcoded comment-comment.
  1437. Each filter is called with three arguments: the transcoded
  1438. comment-block, as a string, the back-end, as a symbol, and the
  1439. communication channel, as a plist. It must return a string or
  1440. nil.")
  1441. (defvar org-export-filter-example-block-functions nil
  1442. "List of functions applied to a transcoded example-block.
  1443. Each filter is called with three arguments: the transcoded
  1444. example-block, as a string, the back-end, as a symbol, and the
  1445. communication channel, as a plist. It must return a string or
  1446. nil.")
  1447. (defvar org-export-filter-export-block-functions nil
  1448. "List of functions applied to a transcoded export-block.
  1449. Each filter is called with three arguments: the transcoded
  1450. export-block, as a string, the back-end, as a symbol, and the
  1451. communication channel, as a plist. It must return a string or
  1452. nil.")
  1453. (defvar org-export-filter-fixed-width-functions nil
  1454. "List of functions applied to a transcoded fixed-width.
  1455. Each filter is called with three arguments: the transcoded
  1456. fixed-width, as a string, the back-end, as a symbol, and the
  1457. communication channel, as a plist. It must return a string or
  1458. nil.")
  1459. (defvar org-export-filter-footnote-definition-functions nil
  1460. "List of functions applied to a transcoded footnote-definition.
  1461. Each filter is called with three arguments: the transcoded
  1462. footnote-definition, as a string, the back-end, as a symbol, and
  1463. the communication channel, as a plist. It must return a string
  1464. or nil.")
  1465. (defvar org-export-filter-horizontal-rule-functions nil
  1466. "List of functions applied to a transcoded horizontal-rule.
  1467. Each filter is called with three arguments: the transcoded
  1468. horizontal-rule, as a string, the back-end, as a symbol, and the
  1469. communication channel, as a plist. It must return a string or
  1470. nil.")
  1471. (defvar org-export-filter-keyword-functions nil
  1472. "List of functions applied to a transcoded keyword.
  1473. Each filter is called with three arguments: the transcoded
  1474. keyword, as a string, the back-end, as a symbol, and the
  1475. communication channel, as a plist. It must return a string or
  1476. nil.")
  1477. (defvar org-export-filter-latex-environment-functions nil
  1478. "List of functions applied to a transcoded latex-environment.
  1479. Each filter is called with three arguments: the transcoded
  1480. latex-environment, as a string, the back-end, as a symbol, and
  1481. the communication channel, as a plist. It must return a string
  1482. or nil.")
  1483. (defvar org-export-filter-babel-call-functions nil
  1484. "List of functions applied to a transcoded babel-call.
  1485. Each filter is called with three arguments: the transcoded
  1486. babel-call, as a string, the back-end, as a symbol, and the
  1487. communication channel, as a plist. It must return a string or
  1488. nil.")
  1489. (defvar org-export-filter-paragraph-functions nil
  1490. "List of functions applied to a transcoded paragraph.
  1491. Each filter is called with three arguments: the transcoded
  1492. paragraph, as a string, the back-end, as a symbol, and the
  1493. communication channel, as a plist. It must return a string or
  1494. nil.")
  1495. (defvar org-export-filter-property-drawer-functions nil
  1496. "List of functions applied to a transcoded property-drawer.
  1497. Each filter is called with three arguments: the transcoded
  1498. property-drawer, as a string, the back-end, as a symbol, and the
  1499. communication channel, as a plist. It must return a string or
  1500. nil.")
  1501. (defvar org-export-filter-quote-block-functions nil
  1502. "List of functions applied to a transcoded quote block.
  1503. Each filter is called with three arguments: the transcoded quote
  1504. block, as a string, the back-end, as a symbol, and the
  1505. communication channel, as a plist. It must return a string or
  1506. nil.")
  1507. (defvar org-export-filter-quote-section-functions nil
  1508. "List of functions applied to a transcoded quote-section.
  1509. Each filter is called with three arguments: the transcoded
  1510. quote-section, as a string, the back-end, as a symbol, and the
  1511. communication channel, as a plist. It must return a string or
  1512. nil.")
  1513. (defvar org-export-filter-section-functions nil
  1514. "List of functions applied to a transcoded section.
  1515. Each filter is called with three arguments: the transcoded
  1516. section, as a string, the back-end, as a symbol, and the
  1517. communication channel, as a plist. It must return a string or
  1518. nil.")
  1519. (defvar org-export-filter-special-block-functions nil
  1520. "List of functions applied to a transcoded special block.
  1521. Each filter is called with three arguments: the transcoded
  1522. special block, as a string, the back-end, as a symbol, and the
  1523. communication channel, as a plist. It must return a string or
  1524. nil.")
  1525. (defvar org-export-filter-src-block-functions nil
  1526. "List of functions applied to a transcoded src-block.
  1527. Each filter is called with three arguments: the transcoded
  1528. src-block, as a string, the back-end, as a symbol, and the
  1529. communication channel, as a plist. It must return a string or
  1530. nil.")
  1531. (defvar org-export-filter-table-functions nil
  1532. "List of functions applied to a transcoded table.
  1533. Each filter is called with three arguments: the transcoded table,
  1534. as a string, the back-end, as a symbol, and the communication
  1535. channel, as a plist. It must return a string or nil.")
  1536. (defvar org-export-filter-verse-block-functions nil
  1537. "List of functions applied to a transcoded verse block.
  1538. Each filter is called with three arguments: the transcoded verse
  1539. block, as a string, the back-end, as a symbol, and the
  1540. communication channel, as a plist. It must return a string or
  1541. nil.")
  1542. ;;;; Objects Filters
  1543. (defvar org-export-filter-emphasis-functions nil
  1544. "List of functions applied to a transcoded emphasis.
  1545. Each filter is called with three arguments: the transcoded
  1546. emphasis, as a string, the back-end, as a symbol, and the
  1547. communication channel, as a plist. It must return a string or
  1548. nil.")
  1549. (defvar org-export-filter-entity-functions nil
  1550. "List of functions applied to a transcoded entity.
  1551. Each filter is called with three arguments: the transcoded
  1552. entity, as a string, the back-end, as a symbol, and the
  1553. communication channel, as a plist. It must return a string or
  1554. nil.")
  1555. (defvar org-export-filter-export-snippet-functions nil
  1556. "List of functions applied to a transcoded export-snippet.
  1557. Each filter is called with three arguments: the transcoded
  1558. export-snippet, as a string, the back-end, as a symbol, and the
  1559. communication channel, as a plist. It must return a string or
  1560. nil.")
  1561. (defvar org-export-filter-footnote-reference-functions nil
  1562. "List of functions applied to a transcoded footnote-reference.
  1563. Each filter is called with three arguments: the transcoded
  1564. footnote-reference, as a string, the back-end, as a symbol, and
  1565. the communication channel, as a plist. It must return a string
  1566. or nil.")
  1567. (defvar org-export-filter-inline-babel-call-functions nil
  1568. "List of functions applied to a transcoded inline-babel-call.
  1569. Each filter is called with three arguments: the transcoded
  1570. inline-babel-call, as a string, the back-end, as a symbol, and
  1571. the communication channel, as a plist. It must return a string
  1572. or nil.")
  1573. (defvar org-export-filter-inline-src-block-functions nil
  1574. "List of functions applied to a transcoded inline-src-block.
  1575. Each filter is called with three arguments: the transcoded
  1576. inline-src-block, as a string, the back-end, as a symbol, and the
  1577. communication channel, as a plist. It must return a string or
  1578. nil.")
  1579. (defvar org-export-filter-latex-fragment-functions nil
  1580. "List of functions applied to a transcoded latex-fragment.
  1581. Each filter is called with three arguments: the transcoded
  1582. latex-fragment, as a string, the back-end, as a symbol, and the
  1583. communication channel, as a plist. It must return a string or
  1584. nil.")
  1585. (defvar org-export-filter-line-break-functions nil
  1586. "List of functions applied to a transcoded line-break.
  1587. Each filter is called with three arguments: the transcoded
  1588. line-break, as a string, the back-end, as a symbol, and the
  1589. communication channel, as a plist. It must return a string or
  1590. nil.")
  1591. (defvar org-export-filter-link-functions nil
  1592. "List of functions applied to a transcoded link.
  1593. Each filter is called with three arguments: the transcoded link,
  1594. as a string, the back-end, as a symbol, and the communication
  1595. channel, as a plist. It must return a string or nil.")
  1596. (defvar org-export-filter-macro-functions nil
  1597. "List of functions applied to a transcoded macro.
  1598. Each filter is called with three arguments: the transcoded macro,
  1599. as a string, the back-end, as a symbol, and the communication
  1600. channel, as a plist. It must return a string or nil.")
  1601. (defvar org-export-filter-radio-target-functions nil
  1602. "List of functions applied to a transcoded radio-target.
  1603. Each filter is called with three arguments: the transcoded
  1604. radio-target, as a string, the back-end, as a symbol, and the
  1605. communication channel, as a plist. It must return a string or
  1606. nil.")
  1607. (defvar org-export-filter-statistics-cookie-functions nil
  1608. "List of functions applied to a transcoded statistics-cookie.
  1609. Each filter is called with three arguments: the transcoded
  1610. statistics-cookie, as a string, the back-end, as a symbol, and
  1611. the communication channel, as a plist. It must return a string
  1612. or nil.")
  1613. (defvar org-export-filter-subscript-functions nil
  1614. "List of functions applied to a transcoded subscript.
  1615. Each filter is called with three arguments: the transcoded
  1616. subscript, as a string, the back-end, as a symbol, and the
  1617. communication channel, as a plist. It must return a string or
  1618. nil.")
  1619. (defvar org-export-filter-superscript-functions nil
  1620. "List of functions applied to a transcoded superscript.
  1621. Each filter is called with three arguments: the transcoded
  1622. superscript, as a string, the back-end, as a symbol, and the
  1623. communication channel, as a plist. It must return a string or
  1624. nil.")
  1625. (defvar org-export-filter-target-functions nil
  1626. "List of functions applied to a transcoded target.
  1627. Each filter is called with three arguments: the transcoded
  1628. target, as a string, the back-end, as a symbol, and the
  1629. communication channel, as a plist. It must return a string or
  1630. nil.")
  1631. (defvar org-export-filter-time-stamp-functions nil
  1632. "List of functions applied to a transcoded time-stamp.
  1633. Each filter is called with three arguments: the transcoded
  1634. time-stamp, as a string, the back-end, as a symbol, and the
  1635. communication channel, as a plist. It must return a string or
  1636. nil.")
  1637. (defvar org-export-filter-verbatim-functions nil
  1638. "List of functions applied to a transcoded verbatim.
  1639. Each filter is called with three arguments: the transcoded
  1640. verbatim, as a string, the back-end, as a symbol, and the
  1641. communication channel, as a plist. It must return a string or
  1642. nil.")
  1643. (defun org-export-filter-apply-functions (filters value backend info)
  1644. "Call every function in FILTERS with arguments VALUE, BACKEND and INFO.
  1645. Functions are called in a LIFO fashion, to be sure that developer
  1646. specified filters, if any, are called first."
  1647. (loop for filter in filters
  1648. if (not value) return nil else
  1649. do (setq value (funcall filter value backend info)))
  1650. value)
  1651. (defun org-export-install-filters (backend info)
  1652. "Install filters properties in communication channel.
  1653. BACKEND is a symbol specifying which back-end specific filters to
  1654. install, if any. INFO is a plist containing the current
  1655. communication channel.
  1656. Return the updated communication channel."
  1657. (let (plist)
  1658. ;; Install user defined filters with `org-export-filters-alist'.
  1659. (mapc (lambda (p)
  1660. (setq plist (plist-put plist (car p) (eval (cdr p)))))
  1661. org-export-filters-alist)
  1662. ;; Prepend back-end specific filters to that list.
  1663. (let ((back-end-filters (intern (format "org-%s-filters-alist" backend))))
  1664. (when (boundp back-end-filters)
  1665. (mapc (lambda (p)
  1666. ;; Single values get consed, lists are prepended.
  1667. (let ((key (car p)) (value (cdr p)))
  1668. (when value
  1669. (setq plist
  1670. (plist-put
  1671. plist key
  1672. (if (atom value) (cons value (plist-get plist key))
  1673. (append value (plist-get plist key))))))))
  1674. (eval back-end-filters))))
  1675. ;; Return new communication channel.
  1676. (org-combine-plists info plist)))
  1677. ;;; Core functions
  1678. ;; This is the room for the main function, `org-export-as', along with
  1679. ;; its derivatives, `org-export-to-buffer' and `org-export-to-file'.
  1680. ;; They differ only by the way they output the resulting code.
  1681. ;; `org-export-output-file-name' is an auxiliary function meant to be
  1682. ;; used with `org-export-to-file'. With a given extension, it tries
  1683. ;; to provide a canonical file name to write export output to.
  1684. ;; Note that `org-export-as' doesn't really parse the current buffer,
  1685. ;; but a copy of it (with the same buffer-local variables and
  1686. ;; visibility), where include keywords are expanded and Babel blocks
  1687. ;; are executed, if appropriate.
  1688. ;; `org-export-with-current-buffer-copy' macro prepares that copy.
  1689. ;; File inclusion is taken care of by
  1690. ;; `org-export-expand-include-keyword' and
  1691. ;; `org-export-prepare-file-contents'. Structure wise, including
  1692. ;; a whole Org file in a buffer often makes little sense. For
  1693. ;; example, if the file contains an headline and the include keyword
  1694. ;; was within an item, the item should contain the headline. That's
  1695. ;; why file inclusion should be done before any structure can be
  1696. ;; associated to the file, that is before parsing.
  1697. (defun org-export-as (backend
  1698. &optional subtreep visible-only body-only ext-plist)
  1699. "Transcode current Org buffer into BACKEND code.
  1700. If narrowing is active in the current buffer, only transcode its
  1701. narrowed part.
  1702. If a region is active, transcode that region.
  1703. When optional argument SUBTREEP is non-nil, transcode the
  1704. sub-tree at point, extracting information from the headline
  1705. properties first.
  1706. When optional argument VISIBLE-ONLY is non-nil, don't export
  1707. contents of hidden elements.
  1708. When optional argument BODY-ONLY is non-nil, only return body
  1709. code, without preamble nor postamble.
  1710. EXT-PLIST, when provided, is a property list with external
  1711. parameters overriding Org default settings, but still inferior to
  1712. file-local settings.
  1713. Return code as a string."
  1714. (save-excursion
  1715. (save-restriction
  1716. ;; Narrow buffer to an appropriate region for parsing.
  1717. (when (org-region-active-p)
  1718. (narrow-to-region (region-beginning) (region-end)))
  1719. (when (and subtreep (not (org-at-heading-p)))
  1720. ;; Ensure point is at sub-tree's beginning.
  1721. (org-narrow-to-subtree))
  1722. ;; Retrieve export options (INFO) and parsed tree (RAW-DATA),
  1723. ;; Then options can be completed with tree properties. Note:
  1724. ;; Buffer isn't parsed directly. Instead, a temporary copy is
  1725. ;; created, where include keywords are expanded and code blocks
  1726. ;; are evaluated. RAW-DATA is the parsed tree of the buffer
  1727. ;; resulting from that process. Eventually call
  1728. ;; `org-export-filter-parse-tree-functions'.
  1729. (goto-char (point-min))
  1730. (let ((info (org-export-get-environment backend subtreep ext-plist)))
  1731. ;; Remove subtree's headline from contents if subtree mode is
  1732. ;; activated.
  1733. (when subtreep (forward-line) (narrow-to-region (point) (point-max)))
  1734. ;; Install filters in communication channel.
  1735. (setq info (org-export-install-filters backend info))
  1736. (let ((raw-data (org-export-filter-apply-functions
  1737. (plist-get info :filter-parse-tree)
  1738. (org-export-with-current-buffer-copy
  1739. (org-export-expand-include-keyword nil)
  1740. (let ((org-current-export-file (current-buffer)))
  1741. (org-export-blocks-preprocess))
  1742. (org-element-parse-buffer nil visible-only))
  1743. backend info)))
  1744. ;; Complete communication channel with tree properties.
  1745. (setq info
  1746. (org-combine-plists
  1747. info
  1748. (org-export-collect-tree-properties raw-data info backend)))
  1749. ;; Transcode RAW-DATA. Also call
  1750. ;; `org-export-filter-final-output-functions'.
  1751. (let* ((body (org-element-normalize-string
  1752. (org-export-data raw-data backend info)))
  1753. (template (intern (format "org-%s-template" backend)))
  1754. (output (org-export-filter-apply-functions
  1755. (plist-get info :filter-final-output)
  1756. (if (or (not (fboundp template)) body-only) body
  1757. (funcall template body info))
  1758. backend info)))
  1759. ;; Maybe add final OUTPUT to kill ring before returning it.
  1760. (when org-export-copy-to-kill-ring (org-kill-new output))
  1761. output))))))
  1762. (defun org-export-to-buffer (backend buffer &optional subtreep visible-only
  1763. body-only ext-plist)
  1764. "Call `org-export-as' with output to a specified buffer.
  1765. BACKEND is the back-end used for transcoding, as a symbol.
  1766. BUFFER is the output buffer. If it already exists, it will be
  1767. erased first, otherwise, it will be created.
  1768. Arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and EXT-PLIST are
  1769. similar to those used in `org-export-as', which see.
  1770. Return buffer."
  1771. (let ((out (org-export-as backend subtreep visible-only body-only ext-plist))
  1772. (buffer (get-buffer-create buffer)))
  1773. (with-current-buffer buffer
  1774. (erase-buffer)
  1775. (insert out)
  1776. (goto-char (point-min)))
  1777. buffer))
  1778. (defun org-export-to-file
  1779. (backend file &optional subtreep visible-only body-only ext-plist)
  1780. "Call `org-export-as' with output to a specified file.
  1781. BACKEND is the back-end used for transcoding, as a symbol. FILE
  1782. is the name of the output file, as a string.
  1783. Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
  1784. EXT-PLIST are similar to those used in `org-export-as', which
  1785. see.
  1786. Return output file's name."
  1787. ;; Checks for FILE permissions. `write-file' would do the same, but
  1788. ;; we'd rather avoid needless transcoding of parse tree.
  1789. (unless (file-writable-p file) (error "Output file not writable"))
  1790. ;; Insert contents to a temporary buffer and write it to FILE.
  1791. (let ((out (org-export-as
  1792. backend subtreep visible-only body-only ext-plist)))
  1793. (with-temp-buffer
  1794. (insert out)
  1795. (let ((coding-system-for-write org-export-coding-system))
  1796. (write-file file))))
  1797. ;; Return full path.
  1798. file)
  1799. (defun org-export-output-file-name (extension &optional subtreep pub-dir)
  1800. "Return output file's name according to buffer specifications.
  1801. EXTENSION is a string representing the output file extension,
  1802. with the leading dot.
  1803. With a non-nil optional argument SUBTREEP, try to determine
  1804. output file's name by looking for \"EXPORT_FILE_NAME\" property
  1805. of subtree at point.
  1806. When optional argument PUB-DIR is set, use it as the publishing
  1807. directory.
  1808. Return file name as a string, or nil if it couldn't be
  1809. determined."
  1810. (let ((base-name
  1811. ;; File name may come from EXPORT_FILE_NAME subtree property,
  1812. ;; assuming point is at beginning of said sub-tree.
  1813. (file-name-sans-extension
  1814. (or (and subtreep
  1815. (org-entry-get
  1816. (save-excursion
  1817. (ignore-errors
  1818. (org-back-to-heading (not visible-only)) (point)))
  1819. "EXPORT_FILE_NAME" t))
  1820. ;; File name may be extracted from buffer's associated
  1821. ;; file, if any.
  1822. (buffer-file-name (buffer-base-buffer))
  1823. ;; Can't determine file name on our own: Ask user.
  1824. (let ((read-file-name-function
  1825. (and org-completion-use-ido 'ido-read-file-name)))
  1826. (read-file-name
  1827. "Output file: " pub-dir nil nil nil
  1828. (lambda (name)
  1829. (string= (file-name-extension name t) extension))))))))
  1830. ;; Build file name. Enforce EXTENSION over whatever user may have
  1831. ;; come up with. PUB-DIR, if defined, always has precedence over
  1832. ;; any provided path.
  1833. (cond
  1834. (pub-dir
  1835. (concat (file-name-as-directory pub-dir)
  1836. (file-name-nondirectory base-name)
  1837. extension))
  1838. ((string= (file-name-nondirectory base-name) base-name)
  1839. (concat (file-name-as-directory ".") base-name extension))
  1840. (t (concat base-name extension)))))
  1841. (defmacro org-export-with-current-buffer-copy (&rest body)
  1842. "Apply BODY in a copy of the current buffer.
  1843. The copy preserves local variables and visibility of the original
  1844. buffer.
  1845. Point is at buffer's beginning when BODY is applied."
  1846. (org-with-gensyms (original-buffer offset buffer-string overlays)
  1847. `(let ((,original-buffer ,(current-buffer))
  1848. (,offset ,(1- (point-min)))
  1849. (,buffer-string ,(buffer-string))
  1850. (,overlays (mapcar
  1851. 'copy-overlay (overlays-in (point-min) (point-max)))))
  1852. (with-temp-buffer
  1853. (let ((buffer-invisibility-spec nil))
  1854. (org-clone-local-variables
  1855. ,original-buffer
  1856. "^\\(org-\\|orgtbl-\\|major-mode$\\|outline-\\(regexp\\|level\\)$\\)")
  1857. (insert ,buffer-string)
  1858. (mapc (lambda (ov)
  1859. (move-overlay
  1860. ov
  1861. (- (overlay-start ov) ,offset)
  1862. (- (overlay-end ov) ,offset)
  1863. (current-buffer)))
  1864. ,overlays)
  1865. (goto-char (point-min))
  1866. (progn ,@body))))))
  1867. (def-edebug-spec org-export-with-current-buffer-copy (body))
  1868. (defun org-export-expand-include-keyword (included)
  1869. "Expand every include keyword in buffer.
  1870. INCLUDED is a list of included file names along with their line
  1871. restriction, when appropriate. It is used to avoid infinite
  1872. recursion."
  1873. (let ((case-fold-search nil))
  1874. (goto-char (point-min))
  1875. (while (re-search-forward "^[ \t]*#\\+include: \\(.*\\)" nil t)
  1876. (when (eq (car (save-match-data (org-element-at-point))) 'keyword)
  1877. (beginning-of-line)
  1878. ;; Extract arguments from keyword's value.
  1879. (let* ((value (match-string 1))
  1880. (ind (org-get-indentation))
  1881. (file (and (string-match "^\"\\(\\S-+\\)\"" value)
  1882. (prog1 (expand-file-name (match-string 1 value))
  1883. (setq value (replace-match "" nil nil value)))))
  1884. (lines
  1885. (and (string-match
  1886. ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value)
  1887. (prog1 (match-string 1 value)
  1888. (setq value (replace-match "" nil nil value)))))
  1889. (env (cond ((string-match "\\<example\\>" value) 'example)
  1890. ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
  1891. (match-string 1 value))))
  1892. ;; Minimal level of included file defaults to the child
  1893. ;; level of the current headline, if any, or one. It
  1894. ;; only applies is the file is meant to be included as
  1895. ;; an Org one.
  1896. (minlevel
  1897. (and (not env)
  1898. (if (string-match ":minlevel +\\([0-9]+\\)" value)
  1899. (prog1 (string-to-number (match-string 1 value))
  1900. (setq value (replace-match "" nil nil value)))
  1901. (let ((cur (org-current-level)))
  1902. (if cur (1+ (org-reduced-level cur)) 1))))))
  1903. ;; Remove keyword.
  1904. (delete-region (point) (progn (forward-line) (point)))
  1905. (cond
  1906. ((not (file-readable-p file)) (error "Cannot include file %s" file))
  1907. ;; Check if files has already been parsed. Look after
  1908. ;; inclusion lines too, as different parts of the same file
  1909. ;; can be included too.
  1910. ((member (list file lines) included)
  1911. (error "Recursive file inclusion: %s" file))
  1912. (t
  1913. (cond
  1914. ((eq env 'example)
  1915. (insert
  1916. (let ((ind-str (make-string ind ? ))
  1917. (contents
  1918. ;; Protect sensitive contents with commas.
  1919. (replace-regexp-in-string
  1920. "\\(^\\)\\([*]\\|[ \t]*#\\+\\)" ","
  1921. (org-export-prepare-file-contents file lines)
  1922. nil nil 1)))
  1923. (format "%s#+begin_example\n%s%s#+end_example\n"
  1924. ind-str contents ind-str))))
  1925. ((stringp env)
  1926. (insert
  1927. (let ((ind-str (make-string ind ? ))
  1928. (contents
  1929. ;; Protect sensitive contents with commas.
  1930. (replace-regexp-in-string
  1931. (if (string= env "org") "\\(^\\)\\(.\\)"
  1932. "\\(^\\)\\([*]\\|[ \t]*#\\+\\)") ","
  1933. (org-export-prepare-file-contents file lines)
  1934. nil nil 1)))
  1935. (format "%s#+begin_src %s\n%s%s#+end_src\n"
  1936. ind-str env contents ind-str))))
  1937. (t
  1938. (insert
  1939. (with-temp-buffer
  1940. (org-mode)
  1941. (insert
  1942. (org-export-prepare-file-contents file lines ind minlevel))
  1943. (org-export-expand-include-keyword
  1944. (cons (list file lines) included))
  1945. (buffer-string))))))))))))
  1946. (defun org-export-prepare-file-contents (file &optional lines ind minlevel)
  1947. "Prepare the contents of FILE for inclusion and return them as a string.
  1948. When optional argument LINES is a string specifying a range of
  1949. lines, include only those lines.
  1950. Optional argument IND, when non-nil, is an integer specifying the
  1951. global indentation of returned contents. Since its purpose is to
  1952. allow an included file to stay in the same environment it was
  1953. created \(i.e. a list item), it doesn't apply past the first
  1954. headline encountered.
  1955. Optional argument MINLEVEL, when non-nil, is an integer
  1956. specifying the level that any top-level headline in the included
  1957. file should have."
  1958. (with-temp-buffer
  1959. (insert-file-contents file)
  1960. (when lines
  1961. (let* ((lines (split-string lines "-"))
  1962. (lbeg (string-to-number (car lines)))
  1963. (lend (string-to-number (cadr lines)))
  1964. (beg (if (zerop lbeg) (point-min)
  1965. (goto-char (point-min))
  1966. (forward-line (1- lbeg))
  1967. (point)))
  1968. (end (if (zerop lend) (point-max)
  1969. (goto-char (point-min))
  1970. (forward-line (1- lend))
  1971. (point))))
  1972. (narrow-to-region beg end)))
  1973. ;; Remove blank lines at beginning and end of contents. The logic
  1974. ;; behind that removal is that blank lines around include keyword
  1975. ;; override blank lines in included file.
  1976. (goto-char (point-min))
  1977. (org-skip-whitespace)
  1978. (beginning-of-line)
  1979. (delete-region (point-min) (point))
  1980. (goto-char (point-max))
  1981. (skip-chars-backward " \r\t\n")
  1982. (forward-line)
  1983. (delete-region (point) (point-max))
  1984. ;; If IND is set, preserve indentation of include keyword until
  1985. ;; the first headline encountered.
  1986. (when ind
  1987. (unless (eq major-mode 'org-mode) (org-mode))
  1988. (goto-char (point-min))
  1989. (let ((ind-str (make-string ind ? )))
  1990. (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
  1991. ;; Do not move footnote definitions out of column 0.
  1992. (unless (and (looking-at org-footnote-definition-re)
  1993. (eq (car (org-element-at-point)) 'footnote-definition))
  1994. (insert ind-str))
  1995. (forward-line))))
  1996. ;; When MINLEVEL is specified, compute minimal level for headlines
  1997. ;; in the file (CUR-MIN), and remove stars to each headline so
  1998. ;; that headlines with minimal level have a level of MINLEVEL.
  1999. (when minlevel
  2000. (unless (eq major-mode 'org-mode) (org-mode))
  2001. (let ((levels (org-map-entries
  2002. (lambda () (org-reduced-level (org-current-level))))))
  2003. (when levels
  2004. (let ((offset (- minlevel (apply 'min levels))))
  2005. (unless (zerop offset)
  2006. (when org-odd-levels-only (setq offset (* offset 2)))
  2007. ;; Only change stars, don't bother moving whole
  2008. ;; sections.
  2009. (org-map-entries
  2010. (lambda () (if (< offset 0) (delete-char (abs offset))
  2011. (insert (make-string offset ?*))))))))))
  2012. (buffer-string)))
  2013. ;;; Tools For Back-Ends
  2014. ;; A whole set of tools is available to help build new exporters. Any
  2015. ;; function general enough to have its use across many back-ends
  2016. ;; should be added here.
  2017. ;; As of now, functions operating on footnotes, headlines, links,
  2018. ;; macros, references, src-blocks, tables and tables of contents are
  2019. ;; implemented.
  2020. ;;;; For Footnotes
  2021. ;; `org-export-collect-footnote-definitions' is a tool to list
  2022. ;; actually used footnotes definitions in the whole parse tree, or in
  2023. ;; an headline, in order to add footnote listings throughout the
  2024. ;; transcoded data.
  2025. ;; `org-export-footnote-first-reference-p' is a predicate used by some
  2026. ;; back-ends, when they need to attach the footnote definition only to
  2027. ;; the first occurrence of the corresponding label.
  2028. ;; `org-export-get-footnote-definition' and
  2029. ;; `org-export-get-footnote-number' provide easier access to
  2030. ;; additional information relative to a footnote reference.
  2031. (defun org-export-collect-footnote-definitions (data info)
  2032. "Return an alist between footnote numbers, labels and definitions.
  2033. DATA is the parse tree from which definitions are collected.
  2034. INFO is the plist used as a communication channel.
  2035. Definitions are sorted by order of references. They either
  2036. appear as Org data \(transcoded with `org-export-data'\) or as
  2037. a secondary string for inlined footnotes \(transcoded with
  2038. `org-export-secondary-string'\). Unreferenced definitions are
  2039. ignored."
  2040. (let (refs)
  2041. ;; Collect seen references in REFS.
  2042. (org-element-map
  2043. data 'footnote-reference
  2044. (lambda (footnote local)
  2045. (when (org-export-footnote-first-reference-p footnote local)
  2046. (list (org-export-get-footnote-number footnote local)
  2047. (org-element-get-property :label footnote)
  2048. (org-export-get-footnote-definition footnote local))))
  2049. info)))
  2050. (defun org-export-footnote-first-reference-p (footnote-reference info)
  2051. "Non-nil when a footnote reference is the first one for its label.
  2052. FOOTNOTE-REFERENCE is the footnote reference being considered.
  2053. INFO is the plist used as a communication channel."
  2054. (let ((label (org-element-get-property :label footnote-reference)))
  2055. (or (not label)
  2056. (equal
  2057. footnote-reference
  2058. (org-element-map
  2059. (plist-get info :parse-tree) 'footnote-reference
  2060. (lambda (footnote local)
  2061. (when (string= (org-element-get-property :label footnote) label)
  2062. footnote))
  2063. info 'first-match)))))
  2064. (defun org-export-get-footnote-definition (footnote-reference info)
  2065. "Return definition of FOOTNOTE-REFERENCE as parsed data.
  2066. INFO is the plist used as a communication channel."
  2067. (let ((label (org-element-get-property :label footnote-reference)))
  2068. (or (org-element-get-property :inline-definition footnote-reference)
  2069. (cdr (assoc label (plist-get info :footnote-definition-alist))))))
  2070. (defun org-export-get-footnote-number (footnote info)
  2071. "Return number associated to a footnote.
  2072. FOOTNOTE is either a footnote reference or a footnote definition.
  2073. INFO is the plist used as a communication channel."
  2074. (let ((label (org-element-get-property :label footnote)) seen-refs)
  2075. (org-element-map
  2076. (plist-get info :parse-tree) 'footnote-reference
  2077. (lambda (fn local)
  2078. (let ((fn-lbl (org-element-get-property :label fn)))
  2079. (cond
  2080. ((and (not fn-lbl) (equal fn footnote)) (1+ (length seen-refs)))
  2081. ((and label (string= label fn-lbl)) (1+ (length seen-refs)))
  2082. ;; Anonymous footnote: it's always a new one. Also, be sure
  2083. ;; to return nil from the `cond' so `first-match' doesn't
  2084. ;; get us out of the loop.
  2085. ((not fn-lbl) (push 'inline seen-refs) nil)
  2086. ;; Label not seen so far: add it so SEEN-REFS. Again,
  2087. ;; return nil to stay in the loop.
  2088. ((not (member fn-lbl seen-refs)) (push fn-lbl seen-refs) nil))))
  2089. info 'first-match)))
  2090. ;;;; For Headlines
  2091. ;; `org-export-get-relative-level' is a shortcut to get headline
  2092. ;; level, relatively to the lower headline level in the parsed tree.
  2093. ;; `org-export-get-headline-number' returns the section number of an
  2094. ;; headline, while `org-export-number-to-roman' allows to convert it
  2095. ;; to roman numbers.
  2096. ;; `org-export-low-level-p', `org-export-first-sibling-p' and
  2097. ;; `org-export-last-sibling-p' are three useful predicates when it
  2098. ;; comes to fulfill the `:headline-levels' property.
  2099. (defun org-export-get-relative-level (headline info)
  2100. "Return HEADLINE relative level within current parsed tree.
  2101. INFO is a plist holding contextual information."
  2102. (+ (org-element-get-property :level headline)
  2103. (or (plist-get info :headline-offset) 0)))
  2104. (defun org-export-low-level-p (headline info)
  2105. "Non-nil when HEADLINE is considered as low level.
  2106. INFO is a plist used as a communication channel.
  2107. A low level headlines has a relative level greater than
  2108. `:headline-levels' property value.
  2109. Return value is the difference between HEADLINE relative level
  2110. and the last level being considered as high enough, or nil."
  2111. (let ((limit (plist-get info :headline-levels)))
  2112. (when (wholenump limit)
  2113. (let ((level (org-export-get-relative-level headline info)))
  2114. (and (> level limit) (- level limit))))))
  2115. (defun org-export-get-headline-number (headline info)
  2116. "Return HEADLINE numbering as a list of numbers.
  2117. INFO is a plist holding contextual information."
  2118. (cdr (assoc headline (plist-get info :headline-numbering))))
  2119. (defun org-export-number-to-roman (n)
  2120. "Convert integer N into a roman numeral."
  2121. (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
  2122. ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
  2123. ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
  2124. ( 1 . "I")))
  2125. (res ""))
  2126. (if (<= n 0)
  2127. (number-to-string n)
  2128. (while roman
  2129. (if (>= n (caar roman))
  2130. (setq n (- n (caar roman))
  2131. res (concat res (cdar roman)))
  2132. (pop roman)))
  2133. res)))
  2134. (defun org-export-first-sibling-p (headline info)
  2135. "Non-nil when HEADLINE is the first sibling in its sub-tree.
  2136. INFO is the plist used as a communication channel."
  2137. (not (eq (car (org-export-get-previous-element headline info)) 'headline)))
  2138. (defun org-export-last-sibling-p (headline info)
  2139. "Non-nil when HEADLINE is the last sibling in its sub-tree.
  2140. INFO is the plist used as a communication channel."
  2141. (equal
  2142. (car (last (org-element-get-contents (car (plist-get info :genealogy)))))
  2143. headline))
  2144. ;;;; For Links
  2145. ;; `org-export-solidify-link-text' turns a string into a safer version
  2146. ;; for links, replacing most non-standard characters with hyphens.
  2147. ;; `org-export-get-coderef-format' returns an appropriate format
  2148. ;; string for coderefs.
  2149. ;; `org-export-inline-image-p' returns a non-nil value when the link
  2150. ;; provided should be considered as an inline image.
  2151. ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
  2152. ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
  2153. ;; returns an appropriate unique identifier when found, or nil.
  2154. ;; `org-export-resolve-id-link' returns the first headline with
  2155. ;; specified id or custom-id in parse tree, or nil when none was
  2156. ;; found.
  2157. ;; `org-export-resolve-coderef' associates a reference to a line
  2158. ;; number in the element it belongs, or returns the reference itself
  2159. ;; when the element isn't numbered.
  2160. (defun org-export-solidify-link-text (s)
  2161. "Take link text S and make a safe target out of it."
  2162. (save-match-data
  2163. (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-]+") "-")))
  2164. (defun org-export-get-coderef-format (path desc)
  2165. "Return format string for code reference link.
  2166. PATH is the link path. DESC is its description."
  2167. (save-match-data
  2168. (cond ((string-match (regexp-quote (concat "(" path ")")) desc)
  2169. (replace-match "%s" t t desc))
  2170. ((string= desc "") "%s")
  2171. (t desc))))
  2172. (defun org-export-inline-image-p (link &optional rules)
  2173. "Non-nil if LINK object points to an inline image.
  2174. Optional argument is a set of RULES defining inline images. It
  2175. is an alist where associations have the following shape:
  2176. \(TYPE . REGEXP)
  2177. Applying a rule means apply REGEXP against LINK's path when its
  2178. type is TYPE. The function will return a non-nil value if any of
  2179. the provided rules is non-nil. The default rule is
  2180. `org-export-default-inline-image-rule'.
  2181. This only applies to links without a description."
  2182. (and (not (org-element-get-contents link))
  2183. (let ((case-fold-search t)
  2184. (rules (or rules org-export-default-inline-image-rule)))
  2185. (some
  2186. (lambda (rule)
  2187. (and (string= (org-element-get-property :type link) (car rule))
  2188. (string-match (cdr rule)
  2189. (org-element-get-property :path link))))
  2190. rules))))
  2191. (defun org-export-resolve-fuzzy-link (link info)
  2192. "Return LINK destination.
  2193. INFO is a plist holding contextual information.
  2194. Return value can be an object, an element, or nil:
  2195. - If LINK path exactly matches any target, return the target
  2196. object.
  2197. - If LINK path exactly matches any headline name, return that
  2198. element. If more than one headline share that name, priority
  2199. will be given to the one with the closest common ancestor, if
  2200. any, or the first one in the parse tree otherwise.
  2201. - Otherwise, return nil.
  2202. Assume LINK type is \"fuzzy\"."
  2203. (let ((path (org-element-get-property :path link)))
  2204. ;; Link points to a target: return it.
  2205. (or (loop for target in (plist-get info :target-list)
  2206. when (string= (org-element-get-property :raw-value target) path)
  2207. return target)
  2208. ;; Link either points to an headline or nothing. Try to find
  2209. ;; the source, with priority given to headlines with the closest
  2210. ;; common ancestor. If such candidate is found, return its
  2211. ;; beginning position as an unique identifier, otherwise return
  2212. ;; nil.
  2213. (let ((find-headline
  2214. (function
  2215. ;; Return first headline whose `:raw-value' property
  2216. ;; is NAME in parse tree DATA, or nil.
  2217. (lambda (name data)
  2218. (org-element-map
  2219. data 'headline
  2220. (lambda (headline local)
  2221. (when (string=
  2222. (org-element-get-property :raw-value headline)
  2223. name)
  2224. headline))
  2225. info 'first-match)))))
  2226. ;; Search among headlines sharing an ancestor with link,
  2227. ;; from closest to farthest.
  2228. (or (catch 'exit
  2229. (mapc
  2230. (lambda (parent)
  2231. (when (eq (car parent) 'headline)
  2232. (let ((foundp (funcall find-headline path parent)))
  2233. (when foundp (throw 'exit foundp)))))
  2234. (plist-get info :genealogy)) nil)
  2235. ;; No match with a common ancestor: try the full parse-tree.
  2236. (funcall find-headline path (plist-get info :parse-tree)))))))
  2237. (defun org-export-resolve-id-link (link info)
  2238. "Return headline referenced as LINK destination.
  2239. INFO is a plist used as a communication channel.
  2240. Return value can be an headline element or nil. Assume LINK type
  2241. is either \"id\" or \"custom-id\"."
  2242. (let ((id (org-element-get-property :path link)))
  2243. (org-element-map
  2244. (plist-get info :parse-tree) 'headline
  2245. (lambda (headline local)
  2246. (when (or (string= (org-element-get-property :id headline) id)
  2247. (string= (org-element-get-property :custom-id headline) id))
  2248. headline))
  2249. info 'first-match)))
  2250. (defun org-export-resolve-coderef (ref info)
  2251. "Resolve a code reference REF.
  2252. INFO is a plist used as a communication channel.
  2253. Return associated line number in source code, or REF itself,
  2254. depending on src-block or example element's switches."
  2255. (org-element-map
  2256. (plist-get info :parse-tree) '(src-block example)
  2257. (lambda (el local)
  2258. (let ((switches (or (org-element-get-property :switches el) "")))
  2259. (with-temp-buffer
  2260. (insert (org-trim (org-element-get-property :value el)))
  2261. ;; Build reference regexp.
  2262. (let* ((label
  2263. (or (and (string-match "-l +\"\\([^\"\n]+\\)\"" switches)
  2264. (match-string 1 switches))
  2265. org-coderef-label-format))
  2266. (ref-re
  2267. (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
  2268. (replace-regexp-in-string "%s" ref label nil t))))
  2269. ;; Element containing REF is found. Only associate REF to
  2270. ;; a line number if element has "+n" or "-n" and "-k" or
  2271. ;; "-r" as switches. When it has "+n", count accumulated
  2272. ;; locs before, too.
  2273. (when (re-search-backward ref-re nil t)
  2274. (cond
  2275. ((not (string-match "-[kr]\\>" switches)) ref)
  2276. ((string-match "-n\\>" switches) (line-number-at-pos))
  2277. ((string-match "\\+n\\>" switches)
  2278. (+ (org-export-get-loc el local) (line-number-at-pos)))
  2279. (t ref)))))))
  2280. info 'first-match))
  2281. ;;;; For Macros
  2282. ;; `org-export-expand-macro' simply takes care of expanding macros.
  2283. (defun org-export-expand-macro (macro info)
  2284. "Expand MACRO and return it as a string.
  2285. INFO is a plist holding export options."
  2286. (let* ((key (org-element-get-property :key macro))
  2287. (args (org-element-get-property :args macro))
  2288. ;; User's macros are stored in the communication channel with
  2289. ;; a ":macro-" prefix.
  2290. (value (plist-get info (intern (format ":macro-%s" key)))))
  2291. ;; Replace arguments in VALUE. A nil VALUE removes the macro call
  2292. ;; from export.
  2293. (when (stringp value)
  2294. (let ((s 0) n)
  2295. (while (string-match "\\$\\([0-9]+\\)" value s)
  2296. (setq s (1+ (match-beginning 0))
  2297. n (string-to-number (match-string 1 value)))
  2298. (and (>= (length args) n)
  2299. (setq value (replace-match (nth (1- n) args) t t value)))))
  2300. ;; VALUE starts with "(eval": it is a s-exp, `eval' it.
  2301. (when (string-match "\\`(eval\\>" value)
  2302. (setq value (eval (read value))))
  2303. ;; Return string.
  2304. (format "%s" (or value "")))))
  2305. ;;;; For References
  2306. ;; `org-export-get-ordinal' associates a sequence number to any object
  2307. ;; or element.
  2308. (defun org-export-get-ordinal
  2309. (element info &optional types within-section predicate)
  2310. "Return ordinal number of an element or object.
  2311. ELEMENT is the element or object considered. INFO is the plist
  2312. used as a communication channel.
  2313. Optional argument TYPES, when non-nil, is a list of element or
  2314. object types, as symbols, that should also be counted in.
  2315. Otherwise, only provided element's type is considered.
  2316. When optional argument WITHIN-SECTION is non-nil, narrow counting
  2317. to the section containing ELEMENT.
  2318. Optional argument PREDICATE is a function returning a non-nil
  2319. value if the current element or object should be counted in. It
  2320. accepts one argument: the element or object being considered.
  2321. This argument allows to count only a certain type of objects,
  2322. like inline images, which are a subset of links \(in that case,
  2323. `org-export-inline-image-p' might be an useful predicate\)."
  2324. (let ((counter 0)
  2325. ;; Determine if search should apply to current section, in
  2326. ;; which case it should be retrieved first, or to full parse
  2327. ;; tree. As a special case, an element or object without
  2328. ;; a parent headline will also trigger a full search,
  2329. ;; notwithstanding WITHIN-SECTION value.
  2330. (data
  2331. (if (not within-section) (plist-get info :parse-tree)
  2332. (or (org-export-get-parent-headline element info)
  2333. (plist-get info :parse-tree)))))
  2334. ;; Increment counter until ELEMENT is found again.
  2335. (org-element-map
  2336. data (or types (car element))
  2337. (lambda (el local)
  2338. (cond
  2339. ((equal element el) (1+ counter))
  2340. ((not predicate) (incf counter) nil)
  2341. ((funcall predicate el) (incf counter) nil)))
  2342. info 'first-match)))
  2343. ;;;; For Src-Blocks
  2344. ;; `org-export-get-loc' counts number of code lines accumulated in
  2345. ;; src-block or example-block elements with a "+n" switch until
  2346. ;; a given element, excluded. Note: "-n" switches reset that count.
  2347. ;; `org-export-handle-code' takes care of line numbering and reference
  2348. ;; cleaning in source code, when appropriate.
  2349. (defun org-export-get-loc (element info)
  2350. "Return accumulated lines of code up to ELEMENT.
  2351. INFO is the plist used as a communication channel.
  2352. ELEMENT is excluded from count."
  2353. (let ((loc 0))
  2354. (org-element-map
  2355. (plist-get info :parse-tree) `(src-block example-block ,(car element))
  2356. (lambda (el local)
  2357. (cond
  2358. ;; ELEMENT is reached: Quit the loop.
  2359. ((equal el element) t)
  2360. ;; Only count lines from src-block and example-block elements
  2361. ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
  2362. ((not (memq (car el) '(src-block example-block))) nil)
  2363. ((let ((switches (org-element-get-property :switches el)))
  2364. (when (and switches (string-match "\\([-+]\\)n\\>" switches))
  2365. ;; Accumulate locs or reset them.
  2366. (let ((accumulatep (string= (match-string 1 switches) "-"))
  2367. (lines (org-count-lines
  2368. (org-trim (org-element-get-property :value el)))))
  2369. (setq loc (if accumulatep lines (+ loc lines))))))
  2370. ;; Return nil to stay in the loop.
  2371. nil)))
  2372. info 'first-match)
  2373. ;; Return value.
  2374. loc))
  2375. (defun org-export-handle-code (element info &optional num-fmt ref-fmt delayed)
  2376. "Handle line numbers and code references in ELEMENT.
  2377. ELEMENT has either a `src-block' an `example-block' type. INFO
  2378. is a plist used as a communication channel.
  2379. If optional argument NUM-FMT is a string, it will be used as
  2380. a format string for numbers at beginning of each line.
  2381. If optional argument REF-FMT is a string, it will be used as
  2382. a format string for each line of code containing a reference.
  2383. When optional argument DELAYED is non-nil, `org-loc' and
  2384. `org-coderef' properties, set to an adequate value, are applied
  2385. to, respectively, numbered lines and lines with a reference. No
  2386. line numbering is done and all references are stripped from the
  2387. resulting string. Both NUM-FMT and REF-FMT arguments are ignored
  2388. in that situation.
  2389. Return new code as a string."
  2390. (let* ((switches (or (org-element-get-property :switches element) ""))
  2391. (code (org-element-get-property :value element))
  2392. (numberp (string-match "[-+]n\\>" switches))
  2393. (accumulatep (string-match "\\+n\\>" switches))
  2394. ;; Initialize loc counter when any kind of numbering is
  2395. ;; active.
  2396. (total-LOC (cond
  2397. (accumulatep (org-export-get-loc element info))
  2398. (numberp 0)))
  2399. ;; Get code and clean it. Remove blank lines at its
  2400. ;; beginning and end. Also remove protective commas.
  2401. (preserve-indent-p (or org-src-preserve-indentation
  2402. (string-match "-i\\>" switches)))
  2403. (replace-labels (when (string-match "-r\\>" switches)
  2404. (if (string-match "-k\\>" switches) 'keep t)))
  2405. (code (let ((c (replace-regexp-in-string
  2406. "\\`\\([ \t]*\n\\)+" ""
  2407. (replace-regexp-in-string
  2408. "\\(:?[ \t]*\n\\)*[ \t]*\\'" "\n" code))))
  2409. ;; If appropriate, remove global indentation.
  2410. (unless preserve-indent-p (setq c (org-remove-indentation c)))
  2411. ;; Free up the protected lines. Note: Org blocks
  2412. ;; have commas at the beginning or every line.
  2413. (if (string=
  2414. (or (org-element-get-property :language element) "")
  2415. "org")
  2416. (replace-regexp-in-string "^," "" c)
  2417. (replace-regexp-in-string
  2418. "^\\(,\\)\\(:?\\*\\|[ \t]*#\\+\\)" "" c nil nil 1))))
  2419. ;; Split code to process it line by line.
  2420. (code-lines (org-split-string code "\n"))
  2421. ;; If numbering is active, ensure line numbers will be
  2422. ;; correctly padded before applying the format string.
  2423. (num-fmt
  2424. (when (and (not delayed) numberp)
  2425. (format (if (stringp num-fmt) num-fmt "%s: ")
  2426. (format "%%%ds"
  2427. (length (number-to-string
  2428. (+ (length code-lines) total-LOC)))))))
  2429. ;; Get format used for references.
  2430. (label-fmt (or (and (string-match "-l +\"\\([^\"\n]+\\)\"" switches)
  2431. (match-string 1 switches))
  2432. org-coderef-label-format))
  2433. ;; Build a regexp matching a loc with a reference.
  2434. (with-ref-re (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
  2435. (replace-regexp-in-string
  2436. "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
  2437. (org-element-normalize-string
  2438. (mapconcat
  2439. (lambda (loc)
  2440. ;; Maybe add line number to current line of code (LOC).
  2441. (when numberp
  2442. (incf total-LOC)
  2443. (setq loc (if delayed (org-add-props loc nil 'org-loc total-LOC)
  2444. (concat (format num-fmt total-LOC) loc))))
  2445. ;; Take action if at a ref line.
  2446. (when (string-match with-ref-re loc)
  2447. (let ((ref (match-string 3 loc)))
  2448. (setq loc
  2449. ;; Option "-r" without "-k" removes labels.
  2450. ;; A non-nil DELAYED removes labels unconditionally.
  2451. (if (or delayed
  2452. (and replace-labels (not (eq replace-labels 'keep))))
  2453. (replace-match "" nil nil loc 1)
  2454. (replace-match (format "(%s)" ref) nil nil loc 2)))
  2455. ;; Store REF in `org-coderef' property if DELAYED asks to.
  2456. (cond (delayed (setq loc (org-add-props loc nil 'org-coderef ref)))
  2457. ;; If REF-FMT is defined, apply it to current LOC.
  2458. ((stringp ref-fmt) (setq loc (format ref-fmt loc))))))
  2459. ;; Return updated LOC for concatenation.
  2460. loc)
  2461. code-lines "\n"))))
  2462. ;;;; For Tables
  2463. ;; `org-export-table-format-info' extracts formatting information
  2464. ;; (alignment, column groups and presence of a special column) from
  2465. ;; a raw table and returns it as a property list.
  2466. ;;
  2467. ;; `org-export-clean-table' cleans the raw table from any Org
  2468. ;; table-specific syntax.
  2469. (defun org-export-table-format-info (table)
  2470. "Extract info from TABLE.
  2471. Return a plist whose properties and values are:
  2472. `:alignment' vector of strings among \"r\", \"l\" and \"c\",
  2473. `:column-groups' vector of symbols among `start', `end', `start-end',
  2474. `:row-groups' list of integers representing row groups.
  2475. `:special-column-p' non-nil if table has a special column.
  2476. `:width' vector of integers representing desired width of
  2477. current column, or nil."
  2478. (with-temp-buffer
  2479. (insert table)
  2480. (goto-char 1)
  2481. (org-table-align)
  2482. (let ((align (vconcat (mapcar (lambda (c) (if c "r" "l"))
  2483. org-table-last-alignment)))
  2484. (width (make-vector (length org-table-last-alignment) nil))
  2485. (colgroups (make-vector (length org-table-last-alignment) nil))
  2486. (row-group 0)
  2487. (rowgroups)
  2488. (special-column-p 'empty))
  2489. (mapc (lambda (row)
  2490. (if (string-match "^[ \t]*|[-+]+|[ \t]*$" row)
  2491. (incf row-group)
  2492. ;; Determine if a special column is present by looking
  2493. ;; for special markers in the first column. More
  2494. ;; accurately, the first column is considered special
  2495. ;; if it only contains special markers and, maybe,
  2496. ;; empty cells.
  2497. (setq special-column-p
  2498. (cond
  2499. ((not special-column-p) nil)
  2500. ((string-match "^[ \t]*| *\\\\?\\([/#!$*_^]\\) *|" row)
  2501. 'special)
  2502. ((string-match "^[ \t]*| +|" row) special-column-p))))
  2503. (cond
  2504. ;; Read forced alignment and width information, if any,
  2505. ;; and determine final alignment for the table.
  2506. ((org-table-cookie-line-p row)
  2507. (let ((col 0))
  2508. (mapc (lambda (field)
  2509. (when (string-match
  2510. "<\\([lrc]\\)?\\([0-9]+\\)?>" field)
  2511. (let ((align-data (match-string 1 field)))
  2512. (when align-data (aset align col align-data)))
  2513. (let ((w-data (match-string 2 field)))
  2514. (when w-data
  2515. (aset width col (string-to-number w-data)))))
  2516. (incf col))
  2517. (org-split-string row "[ \t]*|[ \t]*"))))
  2518. ;; Read column groups information.
  2519. ((org-table-colgroup-line-p row)
  2520. (let ((col 0))
  2521. (mapc (lambda (field)
  2522. (aset colgroups col
  2523. (cond ((string= "<" field) 'start)
  2524. ((string= ">" field) 'end)
  2525. ((string= "<>" field) 'start-end)))
  2526. (incf col))
  2527. (org-split-string row "[ \t]*|[ \t]*"))))
  2528. ;; Contents line.
  2529. (t (push row-group rowgroups))))
  2530. (org-split-string table "\n"))
  2531. ;; Return plist.
  2532. (list :alignment align
  2533. :column-groups colgroups
  2534. :row-groups (reverse rowgroups)
  2535. :special-column-p (eq special-column-p 'special)
  2536. :width width))))
  2537. (defun org-export-clean-table (table specialp)
  2538. "Clean string TABLE from its formatting elements.
  2539. Remove any row containing column groups or formatting cookies and
  2540. rows starting with a special marker. If SPECIALP is non-nil,
  2541. assume the table contains a special formatting column and remove
  2542. it also."
  2543. (let ((rows (org-split-string table "\n")))
  2544. (mapconcat 'identity
  2545. (delq nil
  2546. (mapcar
  2547. (lambda (row)
  2548. (cond
  2549. ((org-table-colgroup-line-p row) nil)
  2550. ((org-table-cookie-line-p row) nil)
  2551. ;; Ignore rows starting with a special marker.
  2552. ((string-match "^[ \t]*| *[!_^/] *|" row) nil)
  2553. ;; Remove special column.
  2554. ((and specialp
  2555. (or (string-match "^\\([ \t]*\\)|-+\\+" row)
  2556. (string-match "^\\([ \t]*\\)|[^|]*|" row)))
  2557. (replace-match "\\1|" t nil row))
  2558. (t row)))
  2559. rows))
  2560. "\n")))
  2561. ;;;; For Tables Of Contents
  2562. ;; `org-export-collect-headlines' builds a list of all exportable
  2563. ;; headline elements, maybe limited to a certain depth. One can then
  2564. ;; easily parse it and transcode it.
  2565. ;; Building lists of tables, figures or listings is quite similar.
  2566. ;; Once the generic function `org-export-collect-elements' is defined,
  2567. ;; `org-export-collect-tables', `org-export-collect-figures' and
  2568. ;; `org-export-collect-listings' can be derived from it.
  2569. (defun org-export-collect-headlines (info &optional n)
  2570. "Collect headlines in order to build a table of contents.
  2571. INFO is a plist used as a communication channel.
  2572. When non-nil, optional argument N must be an integer. It
  2573. specifies the depth of the table of contents.
  2574. Return a list of all exportable headlines as parsed elements."
  2575. (org-element-map
  2576. (plist-get info :parse-tree)
  2577. 'headline
  2578. (lambda (headline local)
  2579. ;; Strip contents from HEADLINE.
  2580. (let ((relative-level (org-export-get-relative-level headline local)))
  2581. (unless (and n (> relative-level n)) headline)))
  2582. info))
  2583. (defun org-export-collect-elements (type info &optional predicate)
  2584. "Collect referenceable elements of a determined type.
  2585. TYPE can be a symbol or a list of symbols specifying element
  2586. types to search. Only elements with a caption or a name are
  2587. collected.
  2588. INFO is a plist used as a communication channel.
  2589. When non-nil, optional argument PREDICATE is a function accepting
  2590. one argument, an element of type TYPE. It returns a non-nil
  2591. value when that element should be collected.
  2592. Return a list of all elements found, in order of appearance."
  2593. (org-element-map
  2594. (plist-get info :parse-tree) type
  2595. (lambda (element local)
  2596. (and (or (org-element-get-property :caption element)
  2597. (org-element-get-property :name element))
  2598. (or (not predicate) (funcall predicate element))
  2599. element)) info))
  2600. (defun org-export-collect-tables (info)
  2601. "Build a list of tables.
  2602. INFO is a plist used as a communication channel.
  2603. Return a list of table elements with a caption or a name
  2604. affiliated keyword."
  2605. (org-export-collect-elements 'table info))
  2606. (defun org-export-collect-figures (info predicate)
  2607. "Build a list of figures.
  2608. INFO is a plist used as a communication channel. PREDICATE is
  2609. a function which accepts one argument: a paragraph element and
  2610. whose return value is non-nil when that element should be
  2611. collected.
  2612. A figure is a paragraph type element, with a caption or a name,
  2613. verifying PREDICATE. The latter has to be provided since
  2614. a \"figure\" is a vague concept that may depend on back-end.
  2615. Return a list of elements recognized as figures."
  2616. (org-export-collect-elements 'paragraph info predicate))
  2617. (defun org-export-collect-listings (info)
  2618. "Build a list of src blocks.
  2619. INFO is a plist used as a communication channel.
  2620. Return a list of src-block elements with a caption or a name
  2621. affiliated keyword."
  2622. (org-export-collect-elements 'src-block info))
  2623. ;;;; Topology
  2624. ;; Here are various functions to retrieve information about the
  2625. ;; neighbourhood of a given element or object. Neighbours of interest
  2626. ;; are parent headline (`org-export-get-parent-headline'), parent
  2627. ;; paragraph (`org-export-get-parent-paragraph'), previous element or
  2628. ;; object (`org-export-get-previous-element') and next element or
  2629. ;; object (`org-export-get-next-element').
  2630. ;; All of these functions are just a specific use of the more generic
  2631. ;; `org-export-get-genealogy', which returns the genealogy relative to
  2632. ;; the element or object.
  2633. (defun org-export-get-genealogy (blob info)
  2634. "Return genealogy relative to a given element or object.
  2635. BLOB is the element or object being considered. INFO is a plist
  2636. used as a communication channel."
  2637. ;; LOCALP tells if current `:genealogy' is sufficient to find parent
  2638. ;; headline, or if it should be computed.
  2639. (let ((localp (member blob (org-element-get-contents
  2640. (car (plist-get info :genealogy))))))
  2641. (if localp (plist-get info :genealogy)
  2642. (catch 'exit
  2643. (org-element-map
  2644. (plist-get info :parse-tree) (car blob)
  2645. (lambda (el local)
  2646. (when (equal el blob)
  2647. (throw 'exit (plist-get local :genealogy))))
  2648. info)))))
  2649. (defun org-export-get-parent-headline (blob info)
  2650. "Return closest parent headline or nil.
  2651. BLOB is the element or object being considered. INFO is a plist
  2652. used as a communication channel."
  2653. (catch 'exit
  2654. (mapc
  2655. (lambda (el) (when (eq (car el) 'headline) (throw 'exit el)))
  2656. (org-export-get-genealogy blob info))
  2657. nil))
  2658. (defun org-export-get-parent-paragraph (object info)
  2659. "Return parent paragraph or nil.
  2660. INFO is a plist used as a communication channel.
  2661. Optional argument OBJECT, when provided, is the object to consider.
  2662. Otherwise, return the paragraph containing current object.
  2663. This is useful for objects, which share attributes with the
  2664. paragraph containing them."
  2665. (catch 'exit
  2666. (mapc
  2667. (lambda (el) (when (eq (car el) 'paragraph) (throw 'exit el)))
  2668. (org-export-get-genealogy object info))
  2669. nil))
  2670. (defun org-export-get-previous-element (blob info)
  2671. "Return previous element or object.
  2672. BLOB is an element or object. INFO is a plist used as
  2673. a communication channel.
  2674. Return previous element or object, a string, or nil."
  2675. (let ((parent (car (org-export-get-genealogy blob info))))
  2676. (cadr (member blob (reverse (org-element-get-contents parent))))))
  2677. (defun org-export-get-next-element (blob info)
  2678. "Return next element or object.
  2679. BLOB is an element or object. INFO is a plist used as
  2680. a communication channel.
  2681. Return next element or object, a string, or nil."
  2682. (let ((parent (car (org-export-get-genealogy blob info))))
  2683. (cadr (member blob (org-element-get-contents parent)))))
  2684. ;;; The Dispatcher
  2685. ;; `org-export-dispatch' is the standard interactive way to start an
  2686. ;; export process. It uses `org-export-dispatch-ui' as a subroutine
  2687. ;; for its interface. Most commons back-ends should have an entry in
  2688. ;; it.
  2689. (defun org-export-dispatch ()
  2690. "Export dispatcher for Org mode.
  2691. It provides an access to common export related tasks in a buffer.
  2692. Its interface comes in two flavours: standard and expert. While
  2693. both share the same set of bindings, only the former displays the
  2694. valid keys associations. Set `org-export-dispatch-use-expert-ui'
  2695. to switch to one or the other.
  2696. Return an error if key pressed has no associated command."
  2697. (interactive)
  2698. (let* ((input (org-export-dispatch-ui
  2699. (if (listp org-export-initial-scope) org-export-initial-scope
  2700. (list org-export-initial-scope))
  2701. org-export-dispatch-use-expert-ui))
  2702. (raw-key (car input))
  2703. (optns (cdr input)))
  2704. ;; Translate "C-a", "C-b"... into "a", "b"... Then take action
  2705. ;; depending on user's key pressed.
  2706. (case (if (< raw-key 27) (+ raw-key 96) raw-key)
  2707. ;; Export with `e-ascii' back-end.
  2708. ((?A ?N ?U)
  2709. (let ((outbuf
  2710. (org-export-to-buffer
  2711. 'e-ascii "*Org E-ASCII Export*"
  2712. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)
  2713. `(:ascii-charset
  2714. ,(case raw-key (?A 'ascii) (?N 'latin1) (t 'utf-8))))))
  2715. (with-current-buffer outbuf (text-mode))
  2716. (when org-export-show-temporary-export-buffer
  2717. (switch-to-buffer-other-window outbuf))))
  2718. ((?a ?n ?u)
  2719. (org-e-ascii-export-to-ascii
  2720. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)
  2721. `(:ascii-charset ,(case raw-key (?a 'ascii) (?n 'latin1) (t 'utf-8)))))
  2722. ;; Export with `e-latex' back-end.
  2723. (?L
  2724. (let ((outbuf
  2725. (org-export-to-buffer
  2726. 'e-latex "*Org E-LaTeX Export*"
  2727. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns))))
  2728. (with-current-buffer outbuf (latex-mode))
  2729. (when org-export-show-temporary-export-buffer
  2730. (switch-to-buffer-other-window outbuf))))
  2731. (?l (org-e-latex-export-to-latex
  2732. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  2733. (?p (org-e-latex-export-to-pdf
  2734. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  2735. (?d (org-open-file
  2736. (org-e-latex-export-to-pdf
  2737. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns))))
  2738. ;; Publishing facilities
  2739. (?F (org-e-publish-current-file (memq 'force optns)))
  2740. (?P (org-e-publish-current-project (memq 'force optns)))
  2741. (?X (let ((project
  2742. (assoc (org-icompleting-read
  2743. "Publish project: " org-e-publish-project-alist nil t)
  2744. org-e-publish-project-alist)))
  2745. (org-e-publish project (memq 'force optns))))
  2746. (?E (org-e-publish-all (memq 'force optns)))
  2747. ;; Undefined command.
  2748. (t (error "No command associated with key %s"
  2749. (char-to-string raw-key))))))
  2750. (defun org-export-dispatch-ui (options expertp)
  2751. "Handle interface for `org-export-dispatch'.
  2752. OPTIONS is a list containing current interactive options set for
  2753. export. It can contain any of the following symbols:
  2754. `body' toggles a body-only export
  2755. `subtree' restricts export to current subtree
  2756. `visible' restricts export to visible part of buffer.
  2757. `force' force publishing files.
  2758. EXPERTP, when non-nil, triggers expert UI. In that case, no help
  2759. buffer is provided, but indications about currently active
  2760. options are given in the prompt. Moreover, \[?] allows to switch
  2761. back to standard interface.
  2762. Return value is a list with key pressed as CAR and a list of
  2763. final interactive export options as CDR."
  2764. (let ((help
  2765. (format "-------------------- General Options --------------------
  2766. \[1] Body only: %s [2] Export scope: %s
  2767. \[3] Visible only: %s [4] Force publishing: %s
  2768. -------------- ASCII/Latin-1/UTF-8 Export ---------------
  2769. \[a/n/u] to TXT file [A/N/U] to temporary buffer
  2770. --------------------- LaTeX Export ----------------------
  2771. \[l] to TEX file [L] to temporary buffer
  2772. \[p] to PDF file [d] ... and open it
  2773. ------------------------- Publish -------------------------
  2774. \[F] current file [P] current project
  2775. \[X] a project [E] every project"
  2776. (if (memq 'body options) "On" "Off")
  2777. (if (memq 'subtree options) "Subtree" "Buffer")
  2778. (if (memq 'visible options) "On" "Off")
  2779. (if (memq 'force options) "On" "Off")))
  2780. (standard-prompt "Export command: ")
  2781. (expert-prompt (format "Export command (%s%s%s%s): "
  2782. (if (memq 'body options) "b" "-")
  2783. (if (memq 'subtree options) "s" "-")
  2784. (if (memq 'visible options) "v" "-")
  2785. (if (memq 'force options) "f" "-")))
  2786. (handle-keypress
  2787. (function
  2788. ;; Read a character from command input, toggling interactive
  2789. ;; options when applicable. PROMPT is the displayed prompt,
  2790. ;; as a string.
  2791. (lambda (prompt)
  2792. (let ((key (read-char-exclusive prompt)))
  2793. (cond
  2794. ;; Ignore non-standard characters (i.e. "M-a").
  2795. ((not (characterp key)) (org-export-dispatch-ui options expertp))
  2796. ;; Help key: Switch back to standard interface if
  2797. ;; expert UI was active.
  2798. ((eq key ??) (org-export-dispatch-ui options nil))
  2799. ;; Toggle export options.
  2800. ((memq key '(?1 ?2 ?3 ?4))
  2801. (org-export-dispatch-ui
  2802. (let ((option (case key (?1 'body) (?2 'subtree) (?3 'visible)
  2803. (?4 'force))))
  2804. (if (memq option options) (remq option options)
  2805. (cons option options)))
  2806. expertp))
  2807. ;; Action selected: Send key and options back to
  2808. ;; `org-export-dispatch'.
  2809. (t (cons key options))))))))
  2810. ;; With expert UI, just read key with a fancy prompt. In standard
  2811. ;; UI, display an intrusive help buffer.
  2812. (if expertp (funcall handle-keypress expert-prompt)
  2813. (save-window-excursion
  2814. (delete-other-windows)
  2815. (with-output-to-temp-buffer "*Org Export/Publishing Help*" (princ help))
  2816. (org-fit-window-to-buffer
  2817. (get-buffer-window "*Org Export/Publishing Help*"))
  2818. (funcall handle-keypress standard-prompt)))))
  2819. (provide 'org-export)
  2820. ;;; org-export.el ends here