org-export.el 163 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309
  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. ;;
  17. ;; This library implements a generic export engine for Org, built on
  18. ;; its syntactical parser: Org Elements.
  19. ;;
  20. ;; Besides that parser, the generic exporter is made of three distinct
  21. ;; parts:
  22. ;;
  23. ;; - The communication channel consists in a property list, which is
  24. ;; created and updated during the process. Its use is to offer
  25. ;; every piece of information, would it be about initial environment
  26. ;; or contextual data, all in a single place. The exhaustive list
  27. ;; of properties is given in "The Communication Channel" section of
  28. ;; this file.
  29. ;;
  30. ;; - The transcoder walks the parse tree, ignores or treat as plain
  31. ;; text elements and objects according to export options, and
  32. ;; eventually calls back-end specific functions to do the real
  33. ;; transcoding, concatenating their return value along the way.
  34. ;;
  35. ;; - The filter system is activated at the very beginning and the very
  36. ;; end of the export process, and each time an element or an object
  37. ;; has been converted. It is the entry point to fine-tune standard
  38. ;; output from back-end transcoders. See "The Filter System"
  39. ;; section for more information.
  40. ;;
  41. ;; The core function is `org-export-as'. It returns the transcoded
  42. ;; buffer as a string.
  43. ;;
  44. ;; A back-end is defined through one mandatory variable: his
  45. ;; translation table. Its name is always
  46. ;; `org-BACKEND-translate-alist' where BACKEND stands for the name
  47. ;; chosen for the back-end. Its value is an alist whose keys are
  48. ;; elements and objects types and values translator functions.
  49. ;;
  50. ;; These functions should return a string without any trailing space,
  51. ;; or nil. They must accept three arguments: the object or element
  52. ;; itself, its contents or nil when it isn't recursive and the
  53. ;; property list used as a communication channel.
  54. ;;
  55. ;; Contents, when not nil, are stripped from any global indentation
  56. ;; (although the relative one is preserved). They also always end
  57. ;; with a single newline character.
  58. ;;
  59. ;; If, for a given type, no function is found, that element or object
  60. ;; type will simply be ignored, along with any blank line or white
  61. ;; space at its end. The same will happen if the function returns the
  62. ;; nil value. If that function returns the empty string, the type
  63. ;; will be ignored, but the blank lines or white spaces will be kept.
  64. ;;
  65. ;; In addition to element and object types, one function can be
  66. ;; associated to the `template' symbol and another one to the
  67. ;; `plain-text' symbol.
  68. ;;
  69. ;; The former returns the final transcoded string, and can be used to
  70. ;; add a preamble and a postamble to document's body. It must accept
  71. ;; two arguments: the transcoded string and the property list
  72. ;; containing export options.
  73. ;;
  74. ;; The latter, when defined, is to be called on every text not
  75. ;; recognized as an element or an object. It must accept two
  76. ;; arguments: the text string and the information channel. It is an
  77. ;; appropriate place to protect special chars relative to the
  78. ;; back-end.
  79. ;;
  80. ;; Optionally, a back-end can support specific buffer keywords and
  81. ;; OPTION keyword's items by setting `org-BACKEND-filters-alist'
  82. ;; variable. Refer to `org-export-options-alist' documentation for
  83. ;; more information about its value.
  84. ;;
  85. ;; If the new back-end shares most properties with another one,
  86. ;; `org-export-define-derived-backend' can be used to simplify the
  87. ;; process.
  88. ;;
  89. ;; Any back-end can define its own variables. Among them, those
  90. ;; customizables should belong to the `org-export-BACKEND' group.
  91. ;;
  92. ;; Tools for common tasks across back-ends are implemented in the
  93. ;; penultimate part of this file. A dispatcher for standard back-ends
  94. ;; is provided in the last one.
  95. ;;; Code:
  96. (eval-when-compile (require 'cl))
  97. (require 'org-element)
  98. (declare-function org-e-ascii-export-as-ascii "org-e-ascii"
  99. (&optional subtreep visible-only body-only ext-plist))
  100. (declare-function org-e-ascii-export-to-ascii "org-e-ascii"
  101. (&optional subtreep visible-only body-only ext-plist pub-dir))
  102. (declare-function org-e-html-export-as-html "org-e-html"
  103. (&optional subtreep visible-only body-only ext-plist pub-dir))
  104. (declare-function org-e-html-export-to-html "org-e-html"
  105. (&optional subtreep visible-only body-only ext-plist pub-dir))
  106. (declare-function org-e-latex-export-as-latex "org-e-latex"
  107. (&optional subtreep visible-only body-only ext-plist))
  108. (declare-function org-e-latex-export-to-latex "org-e-latex"
  109. (&optional subtreep visible-only body-only ext-plist pub-dir))
  110. (declare-function org-e-latex-export-to-pdf "org-e-latex"
  111. (&optional subtreep visible-only body-only ext-plist pub-dir))
  112. (declare-function org-e-odt-export-to-odt "org-e-odt"
  113. (&optional subtreep visible-only body-only ext-plist pub-dir))
  114. (declare-function org-e-publish "org-e-publish" (project &optional force))
  115. (declare-function org-e-publish-all "org-e-publish" (&optional force))
  116. (declare-function org-e-publish-current-file "org-e-publish" (&optional force))
  117. (declare-function org-e-publish-current-project "org-e-publish"
  118. (&optional force))
  119. (declare-function org-export-blocks-preprocess "org-exp-blocks")
  120. (defvar org-e-publish-project-alist)
  121. (defvar org-table-number-fraction)
  122. (defvar org-table-number-regexp)
  123. ;;; Internal Variables
  124. ;;
  125. ;; Among internal variables, the most important is
  126. ;; `org-export-options-alist'. This variable define the global export
  127. ;; options, shared between every exporter, and how they are acquired.
  128. (defconst org-export-max-depth 19
  129. "Maximum nesting depth for headlines, counting from 0.")
  130. (defconst org-export-options-alist
  131. '((:author "AUTHOR" nil user-full-name t)
  132. (:creator "CREATOR" nil org-export-creator-string)
  133. (:date "DATE" nil nil t)
  134. (:description "DESCRIPTION" nil nil newline)
  135. (:email "EMAIL" nil user-mail-address t)
  136. (:exclude-tags "EXCLUDE_TAGS" nil org-export-exclude-tags split)
  137. (:headline-levels nil "H" org-export-headline-levels)
  138. (:keywords "KEYWORDS" nil nil space)
  139. (:language "LANGUAGE" nil org-export-default-language t)
  140. (:preserve-breaks nil "\\n" org-export-preserve-breaks)
  141. (:section-numbers nil "num" org-export-with-section-numbers)
  142. (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
  143. (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
  144. (:title "TITLE" nil nil space)
  145. (:with-archived-trees nil "arch" org-export-with-archived-trees)
  146. (:with-author nil "author" org-export-with-author)
  147. (:with-clocks nil "c" org-export-with-clocks)
  148. (:with-creator nil "creator" org-export-with-creator)
  149. (:with-drawers nil "d" org-export-with-drawers)
  150. (:with-email nil "email" org-export-with-email)
  151. (:with-emphasize nil "*" org-export-with-emphasize)
  152. (:with-entities nil "e" org-export-with-entities)
  153. (:with-fixed-width nil ":" org-export-with-fixed-width)
  154. (:with-footnotes nil "f" org-export-with-footnotes)
  155. (:with-plannings nil "p" org-export-with-planning)
  156. (:with-priority nil "pri" org-export-with-priority)
  157. (:with-special-strings nil "-" org-export-with-special-strings)
  158. (:with-sub-superscript nil "^" org-export-with-sub-superscripts)
  159. (:with-toc nil "toc" org-export-with-toc)
  160. (:with-tables nil "|" org-export-with-tables)
  161. (:with-tags nil "tags" org-export-with-tags)
  162. (:with-tasks nil "tasks" org-export-with-tasks)
  163. (:with-timestamps nil "<" org-export-with-timestamps)
  164. (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
  165. "Alist between export properties and ways to set them.
  166. The CAR of the alist is the property name, and the CDR is a list
  167. like (KEYWORD OPTION DEFAULT BEHAVIOUR) where:
  168. KEYWORD is a string representing a buffer keyword, or nil. Each
  169. property defined this way can also be set, during subtree
  170. export, through an headline property named after the keyword
  171. with the \"EXPORT_\" prefix (i.e. DATE keyword and EXPORT_DATE
  172. property).
  173. OPTION is a string that could be found in an #+OPTIONS: line.
  174. DEFAULT is the default value for the property.
  175. BEHAVIOUR determine how Org should handle multiple keywords for
  176. the same property. It is a symbol among:
  177. nil Keep old value and discard the new one.
  178. t Replace old value with the new one.
  179. `space' Concatenate the values, separating them with a space.
  180. `newline' Concatenate the values, separating them with
  181. a newline.
  182. `split' Split values at white spaces, and cons them to the
  183. previous list.
  184. KEYWORD and OPTION have precedence over DEFAULT.
  185. All these properties should be back-end agnostic. For back-end
  186. specific properties, define a similar variable named
  187. `org-BACKEND-options-alist', replacing BACKEND with the name of
  188. the appropriate back-end. You can also redefine properties
  189. there, as they have precedence over these.")
  190. (defconst org-export-special-keywords
  191. '("SETUP_FILE" "OPTIONS" "MACRO")
  192. "List of in-buffer keywords that require special treatment.
  193. These keywords are not directly associated to a property. The
  194. way they are handled must be hard-coded into
  195. `org-export-get-inbuffer-options' function.")
  196. (defconst org-export-filters-alist
  197. '((:filter-bold . org-export-filter-bold-functions)
  198. (:filter-babel-call . org-export-filter-babel-call-functions)
  199. (:filter-center-block . org-export-filter-center-block-functions)
  200. (:filter-clock . org-export-filter-clock-functions)
  201. (:filter-code . org-export-filter-code-functions)
  202. (:filter-comment . org-export-filter-comment-functions)
  203. (:filter-comment-block . org-export-filter-comment-block-functions)
  204. (:filter-drawer . org-export-filter-drawer-functions)
  205. (:filter-dynamic-block . org-export-filter-dynamic-block-functions)
  206. (:filter-entity . org-export-filter-entity-functions)
  207. (:filter-example-block . org-export-filter-example-block-functions)
  208. (:filter-export-block . org-export-filter-export-block-functions)
  209. (:filter-export-snippet . org-export-filter-export-snippet-functions)
  210. (:filter-final-output . org-export-filter-final-output-functions)
  211. (:filter-fixed-width . org-export-filter-fixed-width-functions)
  212. (:filter-footnote-definition . org-export-filter-footnote-definition-functions)
  213. (:filter-footnote-reference . org-export-filter-footnote-reference-functions)
  214. (:filter-headline . org-export-filter-headline-functions)
  215. (:filter-horizontal-rule . org-export-filter-horizontal-rule-functions)
  216. (:filter-inline-babel-call . org-export-filter-inline-babel-call-functions)
  217. (:filter-inline-src-block . org-export-filter-inline-src-block-functions)
  218. (:filter-inlinetask . org-export-filter-inlinetask-functions)
  219. (:filter-italic . org-export-filter-italic-functions)
  220. (:filter-item . org-export-filter-item-functions)
  221. (:filter-keyword . org-export-filter-keyword-functions)
  222. (:filter-latex-environment . org-export-filter-latex-environment-functions)
  223. (:filter-latex-fragment . org-export-filter-latex-fragment-functions)
  224. (:filter-line-break . org-export-filter-line-break-functions)
  225. (:filter-link . org-export-filter-link-functions)
  226. (:filter-macro . org-export-filter-macro-functions)
  227. (:filter-paragraph . org-export-filter-paragraph-functions)
  228. (:filter-parse-tree . org-export-filter-parse-tree-functions)
  229. (:filter-plain-list . org-export-filter-plain-list-functions)
  230. (:filter-plain-text . org-export-filter-plain-text-functions)
  231. (:filter-planning . org-export-filter-planning-functions)
  232. (:filter-property-drawer . org-export-filter-property-drawer-functions)
  233. (:filter-quote-block . org-export-filter-quote-block-functions)
  234. (:filter-quote-section . org-export-filter-quote-section-functions)
  235. (:filter-radio-target . org-export-filter-radio-target-functions)
  236. (:filter-section . org-export-filter-section-functions)
  237. (:filter-special-block . org-export-filter-special-block-functions)
  238. (:filter-src-block . org-export-filter-src-block-functions)
  239. (:filter-statistics-cookie . org-export-filter-statistics-cookie-functions)
  240. (:filter-strike-through . org-export-filter-strike-through-functions)
  241. (:filter-subscript . org-export-filter-subscript-functions)
  242. (:filter-superscript . org-export-filter-superscript-functions)
  243. (:filter-table . org-export-filter-table-functions)
  244. (:filter-table-cell . org-export-filter-table-cell-functions)
  245. (:filter-table-row . org-export-filter-table-row-functions)
  246. (:filter-target . org-export-filter-target-functions)
  247. (:filter-timestamp . org-export-filter-timestamp-functions)
  248. (:filter-underline . org-export-filter-underline-functions)
  249. (:filter-verbatim . org-export-filter-verbatim-functions)
  250. (:filter-verse-block . org-export-filter-verse-block-functions))
  251. "Alist between filters properties and initial values.
  252. The key of each association is a property name accessible through
  253. the communication channel. Its value is a configurable global
  254. variable defining initial filters.
  255. This list is meant to install user specified filters. Back-end
  256. developers may install their own filters using
  257. `org-BACKEND-filters-alist', where BACKEND is the name of the
  258. considered back-end. Filters defined there will always be
  259. prepended to the current list, so they always get applied
  260. first.")
  261. (defconst org-export-default-inline-image-rule
  262. `(("file" .
  263. ,(format "\\.%s\\'"
  264. (regexp-opt
  265. '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
  266. "xpm" "pbm" "pgm" "ppm") t))))
  267. "Default rule for link matching an inline image.
  268. This rule applies to links with no description. By default, it
  269. will be considered as an inline image if it targets a local file
  270. whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
  271. \"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
  272. See `org-export-inline-image-p' for more information about
  273. rules.")
  274. ;;; User-configurable Variables
  275. ;;
  276. ;; Configuration for the masses.
  277. ;;
  278. ;; They should never be accessed directly, as their value is to be
  279. ;; stored in a property list (cf. `org-export-options-alist').
  280. ;; Back-ends will read their value from there instead.
  281. (defgroup org-export nil
  282. "Options for exporting Org mode files."
  283. :tag "Org Export"
  284. :group 'org)
  285. (defgroup org-export-general nil
  286. "General options for export engine."
  287. :tag "Org Export General"
  288. :group 'org-export)
  289. (defcustom org-export-with-archived-trees 'headline
  290. "Whether sub-trees with the ARCHIVE tag should be exported.
  291. This can have three different values:
  292. nil Do not export, pretend this tree is not present.
  293. t Do export the entire tree.
  294. `headline' Only export the headline, but skip the tree below it.
  295. This option can also be set with the #+OPTIONS line,
  296. e.g. \"arch:nil\"."
  297. :group 'org-export-general
  298. :type '(choice
  299. (const :tag "Not at all" nil)
  300. (const :tag "Headline only" 'headline)
  301. (const :tag "Entirely" t)))
  302. (defcustom org-export-with-author t
  303. "Non-nil means insert author name into the exported file.
  304. This option can also be set with the #+OPTIONS line,
  305. e.g. \"author:nil\"."
  306. :group 'org-export-general
  307. :type 'boolean)
  308. (defcustom org-export-with-clocks nil
  309. "Non-nil means export CLOCK keywords.
  310. This option can also be set with the #+OPTIONS line,
  311. e.g. \"c:t\"."
  312. :group 'org-export-general
  313. :type 'boolean)
  314. (defcustom org-export-with-creator 'comment
  315. "Non-nil means the postamble should contain a creator sentence.
  316. The sentence can be set in `org-export-creator-string' and
  317. defaults to \"Generated by Org mode XX in Emacs XXX.\".
  318. If the value is `comment' insert it as a comment."
  319. :group 'org-export-general
  320. :type '(choice
  321. (const :tag "No creator sentence" nil)
  322. (const :tag "Sentence as a comment" 'comment)
  323. (const :tag "Insert the sentence" t)))
  324. (defcustom org-export-creator-string
  325. (format "Generated by Org mode %s in Emacs %s."
  326. (if (fboundp 'org-version) (org-version) "(Unknown)")
  327. emacs-version)
  328. "String to insert at the end of the generated document."
  329. :group 'org-export-general
  330. :type '(string :tag "Creator string"))
  331. (defcustom org-export-with-drawers t
  332. "Non-nil means export contents of standard drawers.
  333. When t, all drawers are exported. This may also be a list of
  334. drawer names to export. This variable doesn't apply to
  335. properties drawers.
  336. This option can also be set with the #+OPTIONS line,
  337. e.g. \"d:nil\"."
  338. :group 'org-export-general
  339. :type '(choice
  340. (const :tag "All drawers" t)
  341. (const :tag "None" nil)
  342. (repeat :tag "Selected drawers"
  343. (string :tag "Drawer name"))))
  344. (defcustom org-export-with-email nil
  345. "Non-nil means insert author email into the exported file.
  346. This option can also be set with the #+OPTIONS line,
  347. e.g. \"email:t\"."
  348. :group 'org-export-general
  349. :type 'boolean)
  350. (defcustom org-export-with-emphasize t
  351. "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
  352. If the export target supports emphasizing text, the word will be
  353. typeset in bold, italic, or underlined, respectively. Not all
  354. export backends support this.
  355. This option can also be set with the #+OPTIONS line, e.g. \"*:nil\"."
  356. :group 'org-export-general
  357. :type 'boolean)
  358. (defcustom org-export-exclude-tags '("noexport")
  359. "Tags that exclude a tree from export.
  360. All trees carrying any of these tags will be excluded from
  361. export. This is without condition, so even subtrees inside that
  362. carry one of the `org-export-select-tags' will be removed.
  363. This option can also be set with the #+EXCLUDE_TAGS: keyword."
  364. :group 'org-export-general
  365. :type '(repeat (string :tag "Tag")))
  366. (defcustom org-export-with-fixed-width t
  367. "Non-nil means lines starting with \":\" will be in fixed width font.
  368. This can be used to have pre-formatted text, fragments of code
  369. etc. For example:
  370. : ;; Some Lisp examples
  371. : (while (defc cnt)
  372. : (ding))
  373. will be looking just like this in also HTML. See also the QUOTE
  374. keyword. Not all export backends support this.
  375. This option can also be set with the #+OPTIONS line, e.g. \"::nil\"."
  376. :group 'org-export-translation
  377. :type 'boolean)
  378. (defcustom org-export-with-footnotes t
  379. "Non-nil means Org footnotes should be exported.
  380. This option can also be set with the #+OPTIONS line,
  381. e.g. \"f:nil\"."
  382. :group 'org-export-general
  383. :type 'boolean)
  384. (defcustom org-export-headline-levels 3
  385. "The last level which is still exported as a headline.
  386. Inferior levels will produce itemize lists when exported. Note
  387. that a numeric prefix argument to an exporter function overrides
  388. this setting.
  389. This option can also be set with the #+OPTIONS line, e.g. \"H:2\"."
  390. :group 'org-export-general
  391. :type 'integer)
  392. (defcustom org-export-default-language "en"
  393. "The default language for export and clocktable translations, as a string.
  394. This may have an association in
  395. `org-clock-clocktable-language-setup'."
  396. :group 'org-export-general
  397. :type '(string :tag "Language"))
  398. (defcustom org-export-preserve-breaks nil
  399. "Non-nil means preserve all line breaks when exporting.
  400. Normally, in HTML output paragraphs will be reformatted.
  401. This option can also be set with the #+OPTIONS line,
  402. e.g. \"\\n:t\"."
  403. :group 'org-export-general
  404. :type 'boolean)
  405. (defcustom org-export-with-entities t
  406. "Non-nil means interpret entities when exporting.
  407. For example, HTML export converts \\alpha to &alpha; and \\AA to
  408. &Aring;.
  409. For a list of supported names, see the constant `org-entities'
  410. and the user option `org-entities-user'.
  411. This option can also be set with the #+OPTIONS line,
  412. e.g. \"e:nil\"."
  413. :group 'org-export-general
  414. :type 'boolean)
  415. (defcustom org-export-with-planning nil
  416. "Non-nil means include planning info in export.
  417. This option can also be set with the #+OPTIONS: line,
  418. e.g. \"p:t\"."
  419. :group 'org-export-general
  420. :type 'boolean)
  421. (defcustom org-export-with-priority nil
  422. "Non-nil means include priority cookies in export.
  423. When nil, remove priority cookies for export.
  424. This option can also be set with the #+OPTIONS line,
  425. e.g. \"pri:t\"."
  426. :group 'org-export-general
  427. :type 'boolean)
  428. (defcustom org-export-with-section-numbers t
  429. "Non-nil means add section numbers to headlines when exporting.
  430. When set to an integer n, numbering will only happen for
  431. headlines whose relative level is higher or equal to n.
  432. This option can also be set with the #+OPTIONS line,
  433. e.g. \"num:t\"."
  434. :group 'org-export-general
  435. :type 'boolean)
  436. (defcustom org-export-select-tags '("export")
  437. "Tags that select a tree for export.
  438. If any such tag is found in a buffer, all trees that do not carry
  439. one of these tags will be ignored during export. Inside trees
  440. that are selected like this, you can still deselect a subtree by
  441. tagging it with one of the `org-export-exclude-tags'.
  442. This option can also be set with the #+SELECT_TAGS: keyword."
  443. :group 'org-export-general
  444. :type '(repeat (string :tag "Tag")))
  445. (defcustom org-export-with-special-strings t
  446. "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
  447. When this option is turned on, these strings will be exported as:
  448. Org HTML LaTeX
  449. -----+----------+--------
  450. \\- &shy; \\-
  451. -- &ndash; --
  452. --- &mdash; ---
  453. ... &hellip; \ldots
  454. This option can also be set with the #+OPTIONS line,
  455. e.g. \"-:nil\"."
  456. :group 'org-export-general
  457. :type 'boolean)
  458. (defcustom org-export-with-sub-superscripts t
  459. "Non-nil means interpret \"_\" and \"^\" for export.
  460. When this option is turned on, you can use TeX-like syntax for
  461. sub- and superscripts. Several characters after \"_\" or \"^\"
  462. will be considered as a single item - so grouping with {} is
  463. normally not needed. For example, the following things will be
  464. parsed as single sub- or superscripts.
  465. 10^24 or 10^tau several digits will be considered 1 item.
  466. 10^-12 or 10^-tau a leading sign with digits or a word
  467. x^2-y^3 will be read as x^2 - y^3, because items are
  468. terminated by almost any nonword/nondigit char.
  469. x_{i^2} or x^(2-i) braces or parenthesis do grouping.
  470. Still, ambiguity is possible - so when in doubt use {} to enclose
  471. the sub/superscript. If you set this variable to the symbol
  472. `{}', the braces are *required* in order to trigger
  473. interpretations as sub/superscript. This can be helpful in
  474. documents that need \"_\" frequently in plain text.
  475. This option can also be set with the #+OPTIONS line,
  476. e.g. \"^:nil\"."
  477. :group 'org-export-general
  478. :type '(choice
  479. (const :tag "Interpret them" t)
  480. (const :tag "Curly brackets only" {})
  481. (const :tag "Do not interpret them" nil)))
  482. (defcustom org-export-with-toc t
  483. "Non-nil means create a table of contents in exported files.
  484. The TOC contains headlines with levels up
  485. to`org-export-headline-levels'. When an integer, include levels
  486. up to N in the toc, this may then be different from
  487. `org-export-headline-levels', but it will not be allowed to be
  488. larger than the number of headline levels. When nil, no table of
  489. contents is made.
  490. This option can also be set with the #+OPTIONS line,
  491. e.g. \"toc:nil\" or \"toc:3\"."
  492. :group 'org-export-general
  493. :type '(choice
  494. (const :tag "No Table of Contents" nil)
  495. (const :tag "Full Table of Contents" t)
  496. (integer :tag "TOC to level")))
  497. (defcustom org-export-with-tables t
  498. "If non-nil, lines starting with \"|\" define a table.
  499. For example:
  500. | Name | Address | Birthday |
  501. |-------------+----------+-----------|
  502. | Arthur Dent | England | 29.2.2100 |
  503. This option can also be set with the #+OPTIONS line, e.g. \"|:nil\"."
  504. :group 'org-export-general
  505. :type 'boolean)
  506. (defcustom org-export-with-tags t
  507. "If nil, do not export tags, just remove them from headlines.
  508. If this is the symbol `not-in-toc', tags will be removed from
  509. table of contents entries, but still be shown in the headlines of
  510. the document.
  511. This option can also be set with the #+OPTIONS line,
  512. e.g. \"tags:nil\"."
  513. :group 'org-export-general
  514. :type '(choice
  515. (const :tag "Off" nil)
  516. (const :tag "Not in TOC" not-in-toc)
  517. (const :tag "On" t)))
  518. (defcustom org-export-with-tasks t
  519. "Non-nil means include TODO items for export.
  520. This may have the following values:
  521. t include tasks independent of state.
  522. todo include only tasks that are not yet done.
  523. done include only tasks that are already done.
  524. nil remove all tasks before export
  525. list of keywords keep only tasks with these keywords"
  526. :group 'org-export-general
  527. :type '(choice
  528. (const :tag "All tasks" t)
  529. (const :tag "No tasks" nil)
  530. (const :tag "Not-done tasks" todo)
  531. (const :tag "Only done tasks" done)
  532. (repeat :tag "Specific TODO keywords"
  533. (string :tag "Keyword"))))
  534. (defcustom org-export-time-stamp-file t
  535. "Non-nil means insert a time stamp into the exported file.
  536. The time stamp shows when the file was created.
  537. This option can also be set with the #+OPTIONS line,
  538. e.g. \"timestamp:nil\"."
  539. :group 'org-export-general
  540. :type 'boolean)
  541. (defcustom org-export-with-timestamps t
  542. "Non nil means allow timestamps in export.
  543. It can be set to `active', `inactive', t or nil, in order to
  544. export, respectively, only active timestamps, only inactive ones,
  545. all of them or none.
  546. This option can also be set with the #+OPTIONS line, e.g.
  547. \"<:nil\"."
  548. :group 'org-export-general
  549. :type '(choice
  550. (const :tag "All timestamps" t)
  551. (const :tag "Only active timestamps" active)
  552. (const :tag "Only inactive timestamps" inactive)
  553. (const :tag "No timestamp" nil)))
  554. (defcustom org-export-with-todo-keywords t
  555. "Non-nil means include TODO keywords in export.
  556. When nil, remove all these keywords from the export."
  557. :group 'org-export-general
  558. :type 'boolean)
  559. (defcustom org-export-allow-BIND 'confirm
  560. "Non-nil means allow #+BIND to define local variable values for export.
  561. This is a potential security risk, which is why the user must
  562. confirm the use of these lines."
  563. :group 'org-export-general
  564. :type '(choice
  565. (const :tag "Never" nil)
  566. (const :tag "Always" t)
  567. (const :tag "Ask a confirmation for each file" confirm)))
  568. (defcustom org-export-snippet-translation-alist nil
  569. "Alist between export snippets back-ends and exporter back-ends.
  570. This variable allows to provide shortcuts for export snippets.
  571. For example, with a value of '\(\(\"h\" . \"e-html\"\)\), the
  572. HTML back-end will recognize the contents of \"@@h:<b>@@\" as
  573. HTML code while every other back-end will ignore it."
  574. :group 'org-export-general
  575. :type '(repeat
  576. (cons
  577. (string :tag "Shortcut")
  578. (string :tag "Back-end"))))
  579. (defcustom org-export-coding-system nil
  580. "Coding system for the exported file."
  581. :group 'org-export-general
  582. :type 'coding-system)
  583. (defcustom org-export-copy-to-kill-ring t
  584. "Non-nil means exported stuff will also be pushed onto the kill ring."
  585. :group 'org-export-general
  586. :type 'boolean)
  587. (defcustom org-export-initial-scope 'buffer
  588. "The initial scope when exporting with `org-export-dispatch'.
  589. This variable can be either set to `buffer' or `subtree'."
  590. :group 'org-export-general
  591. :type '(choice
  592. (const :tag "Export current buffer" 'buffer)
  593. (const :tag "Export current subtree" 'subtree)))
  594. (defcustom org-export-show-temporary-export-buffer t
  595. "Non-nil means show buffer after exporting to temp buffer.
  596. When Org exports to a file, the buffer visiting that file is ever
  597. shown, but remains buried. However, when exporting to
  598. a temporary buffer, that buffer is popped up in a second window.
  599. When this variable is nil, the buffer remains buried also in
  600. these cases."
  601. :group 'org-export-general
  602. :type 'boolean)
  603. (defcustom org-export-dispatch-use-expert-ui nil
  604. "Non-nil means using a non-intrusive `org-export-dispatch'.
  605. In that case, no help buffer is displayed. Though, an indicator
  606. for current export scope is added to the prompt \(i.e. \"b\" when
  607. output is restricted to body only, \"s\" when it is restricted to
  608. the current subtree and \"v\" when only visible elements are
  609. considered for export\). Also, \[?] allows to switch back to
  610. standard mode."
  611. :group 'org-export-general
  612. :type 'boolean)
  613. ;;; Defining New Back-ends
  614. (defmacro org-export-define-derived-backend (child parent &rest body)
  615. "Create a new back-end as a variant of an existing one.
  616. CHILD is the name of the derived back-end. PARENT is the name of
  617. the parent back-end.
  618. BODY can start with pre-defined keyword arguments. The following
  619. keywords are understood:
  620. `:filters-alist'
  621. Alist of filters that will overwrite or complete filters
  622. defined in PARENT back-end, if any.
  623. `:options-alist'
  624. Alist of buffer keywords or #+OPTIONS items that will
  625. overwrite or complete those defined in PARENT back-end, if
  626. any.
  627. `:translate-alist'
  628. Alist of element and object types and transcoders that will
  629. overwrite or complete transcode table from PARENT back-end.
  630. As an example, here is how one could define \"my-latex\" back-end
  631. as a variant of `e-latex' back-end with a custom template
  632. function:
  633. \(org-export-define-derived-backend my-latex e-latex
  634. :translate-alist ((template . my-latex-template-fun)))
  635. The back-end could then be called with, for example:
  636. \(org-export-to-buffer 'my-latex \"*Test my-latex\")"
  637. (declare (debug (&define name symbolp [&rest keywordp sexp] def-body))
  638. (indent 2))
  639. (let (filters options translate)
  640. (while (keywordp (car body))
  641. (case (pop body)
  642. (:filters-alist (setq filters (pop body)))
  643. (:options-alist (setq options (pop body)))
  644. (:translate-alist (setq translate (pop body)))
  645. (t (pop body))))
  646. `(progn
  647. ;; Define filters.
  648. ,(let ((parent-filters (intern (format "org-%s-filters-alist" parent))))
  649. (when (or (boundp parent-filters) filters)
  650. `(defconst ,(intern (format "org-%s-filters-alist" child))
  651. ',(append filters
  652. (and (boundp parent-filters)
  653. (copy-sequence (symbol-value parent-filters))))
  654. "Alist between filters keywords and back-end specific filters.
  655. See `org-export-filters-alist' for more information.")))
  656. ;; Define options.
  657. ,(let ((parent-options (intern (format "org-%s-options-alist" parent))))
  658. (when (or (boundp parent-options) options)
  659. `(defconst ,(intern (format "org-%s-options-alist" child))
  660. ',(append options
  661. (and (boundp parent-options)
  662. (copy-sequence (symbol-value parent-options))))
  663. "Alist between LaTeX export properties and ways to set them.
  664. See `org-export-options-alist' for more information on the
  665. structure of the values.")))
  666. ;; Define translators.
  667. (defvar ,(intern (format "org-%s-translate-alist" child))
  668. ',(append translate
  669. (copy-sequence
  670. (symbol-value
  671. (intern (format "org-%s-translate-alist" parent)))))
  672. "Alist between element or object types and translators.")
  673. ;; Splice in the body, if any.
  674. ,@body)))
  675. ;;; The Communication Channel
  676. ;;
  677. ;; During export process, every function has access to a number of
  678. ;; properties. They are of two types:
  679. ;;
  680. ;; 1. Environment options are collected once at the very beginning of
  681. ;; the process, out of the original buffer and configuration.
  682. ;; Collecting them is handled by `org-export-get-environment'
  683. ;; function.
  684. ;;
  685. ;; Most environment options are defined through the
  686. ;; `org-export-options-alist' variable.
  687. ;;
  688. ;; 2. Tree properties are extracted directly from the parsed tree,
  689. ;; just before export, by `org-export-collect-tree-properties'.
  690. ;;
  691. ;; Here is the full list of properties available during transcode
  692. ;; process, with their category (option, tree or local) and their
  693. ;; value type.
  694. ;;
  695. ;; + `:author' :: Author's name.
  696. ;; - category :: option
  697. ;; - type :: string
  698. ;;
  699. ;; + `:back-end' :: Current back-end used for transcoding.
  700. ;; - category :: tree
  701. ;; - type :: symbol
  702. ;;
  703. ;; + `:creator' :: String to write as creation information.
  704. ;; - category :: option
  705. ;; - type :: string
  706. ;;
  707. ;; + `:date' :: String to use as date.
  708. ;; - category :: option
  709. ;; - type :: string
  710. ;;
  711. ;; + `:description' :: Description text for the current data.
  712. ;; - category :: option
  713. ;; - type :: string
  714. ;;
  715. ;; + `:email' :: Author's email.
  716. ;; - category :: option
  717. ;; - type :: string
  718. ;;
  719. ;; + `:exclude-tags' :: Tags for exclusion of subtrees from export
  720. ;; process.
  721. ;; - category :: option
  722. ;; - type :: list of strings
  723. ;;
  724. ;; + `:footnote-definition-alist' :: Alist between footnote labels and
  725. ;; their definition, as parsed data. Only non-inlined footnotes
  726. ;; are represented in this alist. Also, every definition isn't
  727. ;; guaranteed to be referenced in the parse tree. The purpose of
  728. ;; this property is to preserve definitions from oblivion
  729. ;; (i.e. when the parse tree comes from a part of the original
  730. ;; buffer), it isn't meant for direct use in a back-end. To
  731. ;; retrieve a definition relative to a reference, use
  732. ;; `org-export-get-footnote-definition' instead.
  733. ;; - category :: option
  734. ;; - type :: alist (STRING . LIST)
  735. ;;
  736. ;; + `:headline-levels' :: Maximum level being exported as an
  737. ;; headline. Comparison is done with the relative level of
  738. ;; headlines in the parse tree, not necessarily with their
  739. ;; actual level.
  740. ;; - category :: option
  741. ;; - type :: integer
  742. ;;
  743. ;; + `:headline-offset' :: Difference between relative and real level
  744. ;; of headlines in the parse tree. For example, a value of -1
  745. ;; means a level 2 headline should be considered as level
  746. ;; 1 (cf. `org-export-get-relative-level').
  747. ;; - category :: tree
  748. ;; - type :: integer
  749. ;;
  750. ;; + `:headline-numbering' :: Alist between headlines and their
  751. ;; numbering, as a list of numbers
  752. ;; (cf. `org-export-get-headline-number').
  753. ;; - category :: tree
  754. ;; - type :: alist (INTEGER . LIST)
  755. ;;
  756. ;; + `:id-alist' :: Alist between ID strings and destination file's
  757. ;; path, relative to current directory. It is used by
  758. ;; `org-export-resolve-id-link' to resolve ID links targeting an
  759. ;; external file.
  760. ;; - category :: option
  761. ;; - type :: alist (STRING . STRING)
  762. ;;
  763. ;; + `:ignore-list' :: List of elements and objects that should be
  764. ;; ignored during export.
  765. ;; - category :: tree
  766. ;; - type :: list of elements and objects
  767. ;;
  768. ;; + `:input-file' :: Full path to input file, if any.
  769. ;; - category :: option
  770. ;; - type :: string or nil
  771. ;;
  772. ;; + `:keywords' :: List of keywords attached to data.
  773. ;; - category :: option
  774. ;; - type :: string
  775. ;;
  776. ;; + `:language' :: Default language used for translations.
  777. ;; - category :: option
  778. ;; - type :: string
  779. ;;
  780. ;; + `:parse-tree' :: Whole parse tree, available at any time during
  781. ;; transcoding.
  782. ;; - category :: option
  783. ;; - type :: list (as returned by `org-element-parse-buffer')
  784. ;;
  785. ;; + `:preserve-breaks' :: Non-nil means transcoding should preserve
  786. ;; all line breaks.
  787. ;; - category :: option
  788. ;; - type :: symbol (nil, t)
  789. ;;
  790. ;; + `:section-numbers' :: Non-nil means transcoding should add
  791. ;; section numbers to headlines.
  792. ;; - category :: option
  793. ;; - type :: symbol (nil, t)
  794. ;;
  795. ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees
  796. ;; in transcoding. When such a tag is present, subtrees without
  797. ;; it are de facto excluded from the process. See
  798. ;; `use-select-tags'.
  799. ;; - category :: option
  800. ;; - type :: list of strings
  801. ;;
  802. ;; + `:target-list' :: List of targets encountered in the parse tree.
  803. ;; This is used to partly resolve "fuzzy" links
  804. ;; (cf. `org-export-resolve-fuzzy-link').
  805. ;; - category :: tree
  806. ;; - type :: list of strings
  807. ;;
  808. ;; + `:time-stamp-file' :: Non-nil means transcoding should insert
  809. ;; a time stamp in the output.
  810. ;; - category :: option
  811. ;; - type :: symbol (nil, t)
  812. ;;
  813. ;; + `:translate-alist' :: Alist between element and object types and
  814. ;; transcoding functions relative to the current back-end.
  815. ;; Special keys `template' and `plain-text' are also possible.
  816. ;; - category :: option
  817. ;; - type :: alist (SYMBOL . FUNCTION)
  818. ;;
  819. ;; + `:with-archived-trees' :: Non-nil when archived subtrees should
  820. ;; also be transcoded. If it is set to the `headline' symbol,
  821. ;; only the archived headline's name is retained.
  822. ;; - category :: option
  823. ;; - type :: symbol (nil, t, `headline')
  824. ;;
  825. ;; + `:with-author' :: Non-nil means author's name should be included
  826. ;; in the output.
  827. ;; - category :: option
  828. ;; - type :: symbol (nil, t)
  829. ;;
  830. ;; + `:with-clocks' :: Non-nild means clock keywords should be exported.
  831. ;; - category :: option
  832. ;; - type :: symbol (nil, t)
  833. ;;
  834. ;; + `:with-creator' :: Non-nild means a creation sentence should be
  835. ;; inserted at the end of the transcoded string. If the value
  836. ;; is `comment', it should be commented.
  837. ;; - category :: option
  838. ;; - type :: symbol (`comment', nil, t)
  839. ;;
  840. ;; + `:with-drawers' :: Non-nil means drawers should be exported. If
  841. ;; its value is a list of names, only drawers with such names
  842. ;; will be transcoded.
  843. ;; - category :: option
  844. ;; - type :: symbol (nil, t) or list of strings
  845. ;;
  846. ;; + `:with-email' :: Non-nil means output should contain author's
  847. ;; email.
  848. ;; - category :: option
  849. ;; - type :: symbol (nil, t)
  850. ;;
  851. ;; + `:with-emphasize' :: Non-nil means emphasized text should be
  852. ;; interpreted.
  853. ;; - category :: option
  854. ;; - type :: symbol (nil, t)
  855. ;;
  856. ;; + `:with-fixed-width' :: Non-nil if transcoder should interpret
  857. ;; strings starting with a colon as a fixed-with (verbatim) area.
  858. ;; - category :: option
  859. ;; - type :: symbol (nil, t)
  860. ;;
  861. ;; + `:with-footnotes' :: Non-nil if transcoder should interpret
  862. ;; footnotes.
  863. ;; - category :: option
  864. ;; - type :: symbol (nil, t)
  865. ;;
  866. ;; + `:with-plannings' :: Non-nil means transcoding should include
  867. ;; planning info.
  868. ;; - category :: option
  869. ;; - type :: symbol (nil, t)
  870. ;;
  871. ;; + `:with-priority' :: Non-nil means transcoding should include
  872. ;; priority cookies.
  873. ;; - category :: option
  874. ;; - type :: symbol (nil, t)
  875. ;;
  876. ;; + `:with-special-strings' :: Non-nil means transcoding should
  877. ;; interpret special strings in plain text.
  878. ;; - category :: option
  879. ;; - type :: symbol (nil, t)
  880. ;;
  881. ;; + `:with-sub-superscript' :: Non-nil means transcoding should
  882. ;; interpret subscript and superscript. With a value of "{}",
  883. ;; only interpret those using curly brackets.
  884. ;; - category :: option
  885. ;; - type :: symbol (nil, {}, t)
  886. ;;
  887. ;; + `:with-tables' :: Non-nil means transcoding should interpret
  888. ;; tables.
  889. ;; - category :: option
  890. ;; - type :: symbol (nil, t)
  891. ;;
  892. ;; + `:with-tags' :: Non-nil means transcoding should keep tags in
  893. ;; headlines. A `not-in-toc' value will remove them from the
  894. ;; table of contents, if any, nonetheless.
  895. ;; - category :: option
  896. ;; - type :: symbol (nil, t, `not-in-toc')
  897. ;;
  898. ;; + `:with-tasks' :: Non-nil means transcoding should include
  899. ;; headlines with a TODO keyword. A `todo' value will only
  900. ;; include headlines with a todo type keyword while a `done'
  901. ;; value will do the contrary. If a list of strings is provided,
  902. ;; only tasks with keywords belonging to that list will be kept.
  903. ;; - category :: option
  904. ;; - type :: symbol (t, todo, done, nil) or list of strings
  905. ;;
  906. ;; + `:with-timestamps' :: Non-nil means transcoding should include
  907. ;; time stamps. Special value `active' (resp. `inactive') ask to
  908. ;; export only active (resp. inactive) timestamps. Otherwise,
  909. ;; completely remove them.
  910. ;; - category :: option
  911. ;; - type :: symbol: (`active', `inactive', t, nil)
  912. ;;
  913. ;; + `:with-toc' :: Non-nil means that a table of contents has to be
  914. ;; added to the output. An integer value limits its depth.
  915. ;; - category :: option
  916. ;; - type :: symbol (nil, t or integer)
  917. ;;
  918. ;; + `:with-todo-keywords' :: Non-nil means transcoding should
  919. ;; include TODO keywords.
  920. ;; - category :: option
  921. ;; - type :: symbol (nil, t)
  922. ;;;; Environment Options
  923. ;;
  924. ;; Environment options encompass all parameters defined outside the
  925. ;; scope of the parsed data. They come from five sources, in
  926. ;; increasing precedence order:
  927. ;;
  928. ;; - Global variables,
  929. ;; - Buffer's attributes,
  930. ;; - Options keyword symbols,
  931. ;; - Buffer keywords,
  932. ;; - Subtree properties.
  933. ;;
  934. ;; The central internal function with regards to environment options
  935. ;; is `org-export-get-environment'. It updates global variables with
  936. ;; "#+BIND:" keywords, then retrieve and prioritize properties from
  937. ;; the different sources.
  938. ;;
  939. ;; The internal functions doing the retrieval are:
  940. ;; `org-export-get-global-options',
  941. ;; `org-export-get-buffer-attributes',
  942. ;; `org-export-parse-option-keyword',
  943. ;; `org-export-get-subtree-options' and
  944. ;; `org-export-get-inbuffer-options'
  945. ;;
  946. ;; Also, `org-export-confirm-letbind' and `org-export-install-letbind'
  947. ;; take care of the part relative to "#+BIND:" keywords.
  948. (defun org-export-get-environment (&optional backend subtreep ext-plist)
  949. "Collect export options from the current buffer.
  950. Optional argument BACKEND is a symbol specifying which back-end
  951. specific options to read, if any.
  952. When optional argument SUBTREEP is non-nil, assume the export is
  953. done against the current sub-tree.
  954. Third optional argument EXT-PLIST is a property list with
  955. external parameters overriding Org default settings, but still
  956. inferior to file-local settings."
  957. ;; First install #+BIND variables.
  958. (org-export-install-letbind-maybe)
  959. ;; Get and prioritize export options...
  960. (org-combine-plists
  961. ;; ... from global variables...
  962. (org-export-get-global-options backend)
  963. ;; ... from buffer's attributes...
  964. (org-export-get-buffer-attributes)
  965. ;; ... from an external property list...
  966. ext-plist
  967. ;; ... from in-buffer settings...
  968. (org-export-get-inbuffer-options
  969. backend
  970. (and buffer-file-name (org-remove-double-quotes buffer-file-name)))
  971. ;; ... and from subtree, when appropriate.
  972. (and subtreep (org-export-get-subtree-options backend))
  973. ;; Eventually install back-end symbol and its translation table.
  974. `(:back-end
  975. ,backend
  976. :translate-alist
  977. ,(let ((trans-alist (intern (format "org-%s-translate-alist" backend))))
  978. (when (boundp trans-alist) (symbol-value trans-alist))))))
  979. (defun org-export-parse-option-keyword (options &optional backend)
  980. "Parse an OPTIONS line and return values as a plist.
  981. Optional argument BACKEND is a symbol specifying which back-end
  982. specific items to read, if any."
  983. (let* ((all
  984. (append org-export-options-alist
  985. (and backend
  986. (let ((var (intern
  987. (format "org-%s-options-alist" backend))))
  988. (and (boundp var) (eval var))))))
  989. ;; Build an alist between #+OPTION: item and property-name.
  990. (alist (delq nil
  991. (mapcar (lambda (e)
  992. (when (nth 2 e) (cons (regexp-quote (nth 2 e))
  993. (car e))))
  994. all)))
  995. plist)
  996. (mapc (lambda (e)
  997. (when (string-match (concat "\\(\\`\\|[ \t]\\)"
  998. (car e)
  999. ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
  1000. options)
  1001. (setq plist (plist-put plist
  1002. (cdr e)
  1003. (car (read-from-string
  1004. (match-string 2 options)))))))
  1005. alist)
  1006. plist))
  1007. (defun org-export-get-subtree-options (&optional backend)
  1008. "Get export options in subtree at point.
  1009. Optional argument BACKEND is a symbol specifying back-end used
  1010. for export. Return options as a plist."
  1011. ;; For each buffer keyword, create an headline property setting the
  1012. ;; same property in communication channel. The name for the property
  1013. ;; is the keyword with "EXPORT_" appended to it.
  1014. (org-with-wide-buffer
  1015. (let (prop plist)
  1016. ;; Make sure point is at an heading.
  1017. (unless (org-at-heading-p) (org-back-to-heading t))
  1018. ;; Take care of EXPORT_TITLE. If it isn't defined, use headline's
  1019. ;; title as its fallback value.
  1020. (when (setq prop (progn (looking-at org-todo-line-regexp)
  1021. (or (save-match-data
  1022. (org-entry-get (point) "EXPORT_TITLE"))
  1023. (org-match-string-no-properties 3))))
  1024. (setq plist
  1025. (plist-put
  1026. plist :title
  1027. (org-element-parse-secondary-string
  1028. prop (org-element-restriction 'keyword)))))
  1029. ;; EXPORT_OPTIONS are parsed in a non-standard way.
  1030. (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
  1031. (setq plist
  1032. (nconc plist (org-export-parse-option-keyword prop backend))))
  1033. ;; Handle other keywords.
  1034. (let ((seen '("TITLE")))
  1035. (mapc
  1036. (lambda (option)
  1037. (let ((property (nth 1 option)))
  1038. (when (and property (not (member property seen)))
  1039. (let* ((subtree-prop (concat "EXPORT_" property))
  1040. (value (org-entry-get (point) subtree-prop)))
  1041. (push property seen)
  1042. (when value
  1043. (setq plist
  1044. (plist-put
  1045. plist
  1046. (car option)
  1047. ;; Parse VALUE if required.
  1048. (if (member property org-element-parsed-keywords)
  1049. (org-element-parse-secondary-string
  1050. value (org-element-restriction 'keyword))
  1051. value))))))))
  1052. ;; Also look for both general keywords and back-end specific
  1053. ;; options if BACKEND is provided.
  1054. (append (and backend
  1055. (let ((var (intern
  1056. (format "org-%s-options-alist" backend))))
  1057. (and (boundp var) (symbol-value var))))
  1058. org-export-options-alist)))
  1059. ;; Return value.
  1060. plist)))
  1061. (defun org-export-get-inbuffer-options (&optional backend files)
  1062. "Return current buffer export options, as a plist.
  1063. Optional argument BACKEND, when non-nil, is a symbol specifying
  1064. which back-end specific options should also be read in the
  1065. process.
  1066. Optional argument FILES is a list of setup files names read so
  1067. far, used to avoid circular dependencies.
  1068. Assume buffer is in Org mode. Narrowing, if any, is ignored."
  1069. (org-with-wide-buffer
  1070. (goto-char (point-min))
  1071. (let ((case-fold-search t) plist)
  1072. ;; 1. Special keywords, as in `org-export-special-keywords'.
  1073. (let ((special-re (org-make-options-regexp org-export-special-keywords)))
  1074. (while (re-search-forward special-re nil t)
  1075. (let ((element (org-element-at-point)))
  1076. (when (eq (org-element-type element) 'keyword)
  1077. (let* ((key (org-element-property :key element))
  1078. (val (org-element-property :value element))
  1079. (prop
  1080. (cond
  1081. ((string= key "SETUP_FILE")
  1082. (let ((file
  1083. (expand-file-name
  1084. (org-remove-double-quotes (org-trim val)))))
  1085. ;; Avoid circular dependencies.
  1086. (unless (member file files)
  1087. (with-temp-buffer
  1088. (insert (org-file-contents file 'noerror))
  1089. (org-mode)
  1090. (org-export-get-inbuffer-options
  1091. backend (cons file files))))))
  1092. ((string= key "OPTIONS")
  1093. (org-export-parse-option-keyword val backend))
  1094. ((string= key "MACRO")
  1095. (when (string-match
  1096. "^\\([-a-zA-Z0-9_]+\\)\\(?:[ \t]+\\(.*?\\)[ \t]*$\\)?"
  1097. val)
  1098. (let ((key
  1099. (intern
  1100. (concat ":macro-"
  1101. (downcase (match-string 1 val)))))
  1102. (value (org-match-string-no-properties 2 val)))
  1103. (cond
  1104. ((not value) nil)
  1105. ;; Value will be evaled: do not parse it.
  1106. ((string-match "\\`(eval\\>" value)
  1107. (list key (list value)))
  1108. ;; Value has to be parsed for nested
  1109. ;; macros.
  1110. (t
  1111. (list
  1112. key
  1113. (let ((restr (org-element-restriction 'macro)))
  1114. (org-element-parse-secondary-string
  1115. ;; If user explicitly asks for
  1116. ;; a newline, be sure to preserve it
  1117. ;; from further filling with
  1118. ;; `hard-newline'. Also replace
  1119. ;; "\\n" with "\n", "\\\n" with "\\n"
  1120. ;; and so on...
  1121. (replace-regexp-in-string
  1122. "\\(\\\\\\\\\\)n" "\\\\"
  1123. (replace-regexp-in-string
  1124. "\\(?:^\\|[^\\\\]\\)\\(\\\\n\\)"
  1125. hard-newline value nil nil 1)
  1126. nil nil 1)
  1127. restr)))))))))))
  1128. (setq plist (org-combine-plists plist prop)))))))
  1129. ;; 2. Standard options, as in `org-export-options-alist'.
  1130. (let* ((all (append org-export-options-alist
  1131. ;; Also look for back-end specific options
  1132. ;; if BACKEND is defined.
  1133. (and backend
  1134. (let ((var
  1135. (intern
  1136. (format "org-%s-options-alist" backend))))
  1137. (and (boundp var) (eval var))))))
  1138. ;; Build alist between keyword name and property name.
  1139. (alist
  1140. (delq nil (mapcar
  1141. (lambda (e) (when (nth 1 e) (cons (nth 1 e) (car e))))
  1142. all)))
  1143. ;; Build regexp matching all keywords associated to export
  1144. ;; options. Note: the search is case insensitive.
  1145. (opt-re (org-make-options-regexp
  1146. (delq nil (mapcar (lambda (e) (nth 1 e)) all)))))
  1147. (goto-char (point-min))
  1148. (while (re-search-forward opt-re nil t)
  1149. (let ((element (org-element-at-point)))
  1150. (when (eq (org-element-type element) 'keyword)
  1151. (let* ((key (org-element-property :key element))
  1152. (val (org-element-property :value element))
  1153. (prop (cdr (assoc key alist)))
  1154. (behaviour (nth 4 (assq prop all))))
  1155. (setq plist
  1156. (plist-put
  1157. plist prop
  1158. ;; Handle value depending on specified BEHAVIOUR.
  1159. (case behaviour
  1160. (space
  1161. (if (not (plist-get plist prop)) (org-trim val)
  1162. (concat (plist-get plist prop) " " (org-trim val))))
  1163. (newline
  1164. (org-trim
  1165. (concat (plist-get plist prop) "\n" (org-trim val))))
  1166. (split
  1167. `(,@(plist-get plist prop) ,@(org-split-string val)))
  1168. ('t val)
  1169. (otherwise (if (not (plist-member plist prop)) val
  1170. (plist-get plist prop))))))))))
  1171. ;; Parse keywords specified in `org-element-parsed-keywords'.
  1172. (mapc
  1173. (lambda (key)
  1174. (let* ((prop (cdr (assoc key alist)))
  1175. (value (and prop (plist-get plist prop))))
  1176. (when (stringp value)
  1177. (setq plist
  1178. (plist-put
  1179. plist prop
  1180. (org-element-parse-secondary-string
  1181. value (org-element-restriction 'keyword)))))))
  1182. org-element-parsed-keywords))
  1183. ;; 3. Return final value.
  1184. plist)))
  1185. (defun org-export-get-buffer-attributes ()
  1186. "Return properties related to buffer attributes, as a plist."
  1187. (let ((visited-file (buffer-file-name (buffer-base-buffer))))
  1188. (list
  1189. ;; Store full path of input file name, or nil. For internal use.
  1190. :input-file visited-file
  1191. :title (or (and visited-file
  1192. (file-name-sans-extension
  1193. (file-name-nondirectory visited-file)))
  1194. (buffer-name (buffer-base-buffer)))
  1195. :footnote-definition-alist
  1196. ;; Footnotes definitions must be collected in the original
  1197. ;; buffer, as there's no insurance that they will still be in the
  1198. ;; parse tree, due to possible narrowing.
  1199. (let (alist)
  1200. (org-with-wide-buffer
  1201. (goto-char (point-min))
  1202. (while (re-search-forward org-footnote-definition-re nil t)
  1203. (let ((def (org-footnote-at-definition-p)))
  1204. (when def
  1205. (org-skip-whitespace)
  1206. (push (cons (car def)
  1207. (save-restriction
  1208. (narrow-to-region (point) (nth 2 def))
  1209. ;; Like `org-element-parse-buffer', but
  1210. ;; makes sure the definition doesn't start
  1211. ;; with a section element.
  1212. (org-element--parse-elements
  1213. (point-min) (point-max) nil nil nil nil
  1214. (list 'org-data nil))))
  1215. alist))))
  1216. alist))
  1217. :id-alist
  1218. ;; Collect id references.
  1219. (let (alist)
  1220. (org-with-wide-buffer
  1221. (goto-char (point-min))
  1222. (while (re-search-forward
  1223. "\\[\\[id:\\(\\S-+?\\)\\]\\(?:\\[.*?\\]\\)?\\]" nil t)
  1224. (let* ((id (org-match-string-no-properties 1))
  1225. (file (org-id-find-id-file id)))
  1226. (when file (push (cons id (file-relative-name file)) alist)))))
  1227. alist)
  1228. :macro-modification-time
  1229. (and visited-file
  1230. (file-exists-p visited-file)
  1231. (concat "(eval (format-time-string \"$1\" '"
  1232. (prin1-to-string (nth 5 (file-attributes visited-file)))
  1233. "))"))
  1234. ;; Store input file name as a macro.
  1235. :macro-input-file (and visited-file (file-name-nondirectory visited-file))
  1236. ;; `:macro-date', `:macro-time' and `:macro-property' could as
  1237. ;; well be initialized as tree properties, since they don't
  1238. ;; depend on buffer properties. Though, it may be more logical
  1239. ;; to keep them close to other ":macro-" properties.
  1240. :macro-date "(eval (format-time-string \"$1\"))"
  1241. :macro-time "(eval (format-time-string \"$1\"))"
  1242. :macro-property "(eval (org-entry-get nil \"$1\" 'selective))")))
  1243. (defun org-export-get-global-options (&optional backend)
  1244. "Return global export options as a plist.
  1245. Optional argument BACKEND, if non-nil, is a symbol specifying
  1246. which back-end specific export options should also be read in the
  1247. process."
  1248. (let ((all (append org-export-options-alist
  1249. (and backend
  1250. (let ((var (intern
  1251. (format "org-%s-options-alist" backend))))
  1252. (and (boundp var) (symbol-value var))))))
  1253. ;; Output value.
  1254. plist)
  1255. (mapc
  1256. (lambda (cell)
  1257. (setq plist
  1258. (plist-put
  1259. plist
  1260. (car cell)
  1261. ;; Eval default value provided. If keyword is a member
  1262. ;; of `org-element-parsed-keywords', parse it as
  1263. ;; a secondary string before storing it.
  1264. (let ((value (eval (nth 3 cell))))
  1265. (if (not (stringp value)) value
  1266. (let ((keyword (nth 1 cell)))
  1267. (if (not (member keyword org-element-parsed-keywords)) value
  1268. (org-element-parse-secondary-string
  1269. value (org-element-restriction 'keyword)))))))))
  1270. all)
  1271. ;; Return value.
  1272. plist))
  1273. (defvar org-export-allow-BIND-local nil)
  1274. (defun org-export-confirm-letbind ()
  1275. "Can we use #+BIND values during export?
  1276. By default this will ask for confirmation by the user, to divert
  1277. possible security risks."
  1278. (cond
  1279. ((not org-export-allow-BIND) nil)
  1280. ((eq org-export-allow-BIND t) t)
  1281. ((local-variable-p 'org-export-allow-BIND-local) org-export-allow-BIND-local)
  1282. (t (org-set-local 'org-export-allow-BIND-local
  1283. (yes-or-no-p "Allow BIND values in this buffer? ")))))
  1284. (defun org-export-install-letbind-maybe ()
  1285. "Install the values from #+BIND lines as local variables.
  1286. Variables must be installed before in-buffer options are
  1287. retrieved."
  1288. (let (letbind pair)
  1289. (org-with-wide-buffer
  1290. (goto-char (point-min))
  1291. (while (re-search-forward (org-make-options-regexp '("BIND")) nil t)
  1292. (when (org-export-confirm-letbind)
  1293. (push (read (concat "(" (org-match-string-no-properties 2) ")"))
  1294. letbind))))
  1295. (while (setq pair (pop letbind))
  1296. (org-set-local (car pair) (nth 1 pair)))))
  1297. ;;;; Tree Properties
  1298. ;;
  1299. ;; Tree properties are infromation extracted from parse tree. They
  1300. ;; are initialized at the beginning of the transcoding process by
  1301. ;; `org-export-collect-tree-properties'.
  1302. ;;
  1303. ;; Dedicated functions focus on computing the value of specific tree
  1304. ;; properties during initialization. Thus,
  1305. ;; `org-export-populate-ignore-list' lists elements and objects that
  1306. ;; should be skipped during export, `org-export-get-min-level' gets
  1307. ;; the minimal exportable level, used as a basis to compute relative
  1308. ;; level for headlines. Eventually
  1309. ;; `org-export-collect-headline-numbering' builds an alist between
  1310. ;; headlines and their numbering.
  1311. (defun org-export-collect-tree-properties (data info)
  1312. "Extract tree properties from parse tree.
  1313. DATA is the parse tree from which information is retrieved. INFO
  1314. is a list holding export options.
  1315. Following tree properties are set or updated:
  1316. `:footnote-definition-alist' List of footnotes definitions in
  1317. original buffer and current parse tree.
  1318. `:headline-offset' Offset between true level of headlines and
  1319. local level. An offset of -1 means an headline
  1320. of level 2 should be considered as a level
  1321. 1 headline in the context.
  1322. `:headline-numbering' Alist of all headlines as key an the
  1323. associated numbering as value.
  1324. `:ignore-list' List of elements that should be ignored during
  1325. export.
  1326. `:target-list' List of all targets in the parse tree.
  1327. Return updated plist."
  1328. ;; Install the parse tree in the communication channel, in order to
  1329. ;; use `org-export-get-genealogy' and al.
  1330. (setq info (plist-put info :parse-tree data))
  1331. ;; Get the list of elements and objects to ignore, and put it into
  1332. ;; `:ignore-list'. Do not overwrite any user ignore that might have
  1333. ;; been done during parse tree filtering.
  1334. (setq info
  1335. (plist-put info
  1336. :ignore-list
  1337. (append (org-export-populate-ignore-list data info)
  1338. (plist-get info :ignore-list))))
  1339. ;; Compute `:headline-offset' in order to be able to use
  1340. ;; `org-export-get-relative-level'.
  1341. (setq info
  1342. (plist-put info
  1343. :headline-offset (- 1 (org-export-get-min-level data info))))
  1344. ;; Update footnotes definitions list with definitions in parse tree.
  1345. ;; This is required since buffer expansion might have modified
  1346. ;; boundaries of footnote definitions contained in the parse tree.
  1347. ;; This way, definitions in `footnote-definition-alist' are bound to
  1348. ;; match those in the parse tree.
  1349. (let ((defs (plist-get info :footnote-definition-alist)))
  1350. (org-element-map
  1351. data 'footnote-definition
  1352. (lambda (fn)
  1353. (push (cons (org-element-property :label fn)
  1354. `(org-data nil ,@(org-element-contents fn)))
  1355. defs)))
  1356. (setq info (plist-put info :footnote-definition-alist defs)))
  1357. ;; Properties order doesn't matter: get the rest of the tree
  1358. ;; properties.
  1359. (nconc
  1360. `(:target-list
  1361. ,(org-element-map
  1362. data '(keyword target)
  1363. (lambda (blob)
  1364. (when (or (eq (org-element-type blob) 'target)
  1365. (string= (org-element-property :key blob) "TARGET"))
  1366. blob)) info)
  1367. :headline-numbering ,(org-export-collect-headline-numbering data info))
  1368. info))
  1369. (defun org-export-get-min-level (data options)
  1370. "Return minimum exportable headline's level in DATA.
  1371. DATA is parsed tree as returned by `org-element-parse-buffer'.
  1372. OPTIONS is a plist holding export options."
  1373. (catch 'exit
  1374. (let ((min-level 10000))
  1375. (mapc
  1376. (lambda (blob)
  1377. (when (and (eq (org-element-type blob) 'headline)
  1378. (not (memq blob (plist-get options :ignore-list))))
  1379. (setq min-level
  1380. (min (org-element-property :level blob) min-level)))
  1381. (when (= min-level 1) (throw 'exit 1)))
  1382. (org-element-contents data))
  1383. ;; If no headline was found, for the sake of consistency, set
  1384. ;; minimum level to 1 nonetheless.
  1385. (if (= min-level 10000) 1 min-level))))
  1386. (defun org-export-collect-headline-numbering (data options)
  1387. "Return numbering of all exportable headlines in a parse tree.
  1388. DATA is the parse tree. OPTIONS is the plist holding export
  1389. options.
  1390. Return an alist whose key is an headline and value is its
  1391. associated numbering \(in the shape of a list of numbers\)."
  1392. (let ((numbering (make-vector org-export-max-depth 0)))
  1393. (org-element-map
  1394. data
  1395. 'headline
  1396. (lambda (headline)
  1397. (let ((relative-level
  1398. (1- (org-export-get-relative-level headline options))))
  1399. (cons
  1400. headline
  1401. (loop for n across numbering
  1402. for idx from 0 to org-export-max-depth
  1403. when (< idx relative-level) collect n
  1404. when (= idx relative-level) collect (aset numbering idx (1+ n))
  1405. when (> idx relative-level) do (aset numbering idx 0)))))
  1406. options)))
  1407. (defun org-export-populate-ignore-list (data options)
  1408. "Return list of elements and objects to ignore during export.
  1409. DATA is the parse tree to traverse. OPTIONS is the plist holding
  1410. export options."
  1411. (let* (ignore
  1412. walk-data ; for byte-compiler.
  1413. (walk-data
  1414. (function
  1415. (lambda (data options selected)
  1416. ;; Collect ignored elements or objects into IGNORE-LIST.
  1417. (mapc
  1418. (lambda (el)
  1419. (if (org-export--skip-p el options selected) (push el ignore)
  1420. (let ((type (org-element-type el)))
  1421. (if (and (eq (plist-get options :with-archived-trees)
  1422. 'headline)
  1423. (eq (org-element-type el) 'headline)
  1424. (org-element-property :archivedp el))
  1425. ;; If headline is archived but tree below has
  1426. ;; to be skipped, add it to ignore list.
  1427. (mapc (lambda (e) (push e ignore))
  1428. (org-element-contents el))
  1429. ;; Move into recursive objects/elements.
  1430. (when (org-element-contents el)
  1431. (funcall walk-data el options selected))))))
  1432. (org-element-contents data))))))
  1433. ;; Main call. First find trees containing a select tag, if any.
  1434. (funcall walk-data data options (org-export--selected-trees data options))
  1435. ;; Return value.
  1436. ignore))
  1437. (defun org-export--selected-trees (data info)
  1438. "Return list of headlines containing a select tag in their tree.
  1439. DATA is parsed data as returned by `org-element-parse-buffer'.
  1440. INFO is a plist holding export options."
  1441. (let* (selected-trees
  1442. walk-data ; for byte-compiler.
  1443. (walk-data
  1444. (function
  1445. (lambda (data genealogy)
  1446. (case (org-element-type data)
  1447. (org-data (mapc (lambda (el) (funcall walk-data el genealogy))
  1448. (org-element-contents data)))
  1449. (headline
  1450. (let ((tags (org-element-property :tags data)))
  1451. (if (loop for tag in (plist-get info :select-tags)
  1452. thereis (member tag tags))
  1453. ;; When a select tag is found, mark full
  1454. ;; genealogy and every headline within the tree
  1455. ;; as acceptable.
  1456. (setq selected-trees
  1457. (append
  1458. genealogy
  1459. (org-element-map data 'headline 'identity)
  1460. selected-trees))
  1461. ;; Else, continue searching in tree, recursively.
  1462. (mapc
  1463. (lambda (el) (funcall walk-data el (cons data genealogy)))
  1464. (org-element-contents data))))))))))
  1465. (funcall walk-data data nil) selected-trees))
  1466. (defun org-export--skip-p (blob options selected)
  1467. "Non-nil when element or object BLOB should be skipped during export.
  1468. OPTIONS is the plist holding export options. SELECTED, when
  1469. non-nil, is a list of headlines belonging to a tree with a select
  1470. tag."
  1471. (case (org-element-type blob)
  1472. ;; Check headline.
  1473. (headline
  1474. (let ((with-tasks (plist-get options :with-tasks))
  1475. (todo (org-element-property :todo-keyword blob))
  1476. (todo-type (org-element-property :todo-type blob))
  1477. (archived (plist-get options :with-archived-trees))
  1478. (tags (org-element-property :tags blob)))
  1479. (or
  1480. ;; Ignore subtrees with an exclude tag.
  1481. (loop for k in (plist-get options :exclude-tags)
  1482. thereis (member k tags))
  1483. ;; When a select tag is present in the buffer, ignore any tree
  1484. ;; without it.
  1485. (and selected (not (memq blob selected)))
  1486. ;; Ignore commented sub-trees.
  1487. (org-element-property :commentedp blob)
  1488. ;; Ignore archived subtrees if `:with-archived-trees' is nil.
  1489. (and (not archived) (org-element-property :archivedp blob))
  1490. ;; Ignore tasks, if specified by `:with-tasks' property.
  1491. (and todo
  1492. (or (not with-tasks)
  1493. (and (memq with-tasks '(todo done))
  1494. (not (eq todo-type with-tasks)))
  1495. (and (consp with-tasks) (not (member todo with-tasks))))))))
  1496. ;; Check timestamp.
  1497. (timestamp
  1498. (case (plist-get options :with-timestamps)
  1499. ;; No timestamp allowed.
  1500. ('nil t)
  1501. ;; Only active timestamps allowed and the current one isn't
  1502. ;; active.
  1503. (active
  1504. (not (memq (org-element-property :type blob)
  1505. '(active active-range))))
  1506. ;; Only inactive timestamps allowed and the current one isn't
  1507. ;; inactive.
  1508. (inactive
  1509. (not (memq (org-element-property :type blob)
  1510. '(inactive inactive-range))))))
  1511. ;; Check drawer.
  1512. (drawer
  1513. (or (not (plist-get options :with-drawers))
  1514. (and (consp (plist-get options :with-drawers))
  1515. (not (member (org-element-property :drawer-name blob)
  1516. (plist-get options :with-drawers))))))
  1517. ;; Check table-row.
  1518. (table-row (org-export-table-row-is-special-p blob options))
  1519. ;; Check table-cell.
  1520. (table-cell
  1521. (and (org-export-table-has-special-column-p
  1522. (org-export-get-parent-table blob))
  1523. (not (org-export-get-previous-element blob))))
  1524. ;; Check clock.
  1525. (clock (not (plist-get options :with-clocks)))
  1526. ;; Check planning.
  1527. (planning (not (plist-get options :with-plannings)))))
  1528. ;;; The Transcoder
  1529. ;;
  1530. ;; `org-export-data' reads a parse tree (obtained with, i.e.
  1531. ;; `org-element-parse-buffer') and transcodes it into a specified
  1532. ;; back-end output. It takes care of filtering out elements or
  1533. ;; objects according to export options and organizing the output blank
  1534. ;; lines and white space are preserved.
  1535. ;;
  1536. ;; Internally, three functions handle the filtering of objects and
  1537. ;; elements during the export. In particular,
  1538. ;; `org-export-ignore-element' marks an element or object so future
  1539. ;; parse tree traversals skip it, `org-export-interpret-p' tells which
  1540. ;; elements or objects should be seen as real Org syntax and
  1541. ;; `org-export-expand' transforms the others back into their original
  1542. ;; shape
  1543. ;;
  1544. ;; `org-export-transcoder' is an accessor returning appropriate
  1545. ;; translator function for a given element or object.
  1546. (defun org-export-transcoder (blob info)
  1547. "Return appropriate transcoder for BLOB.
  1548. INFO is a plist containing export directives."
  1549. (let ((type (org-element-type blob)))
  1550. ;; Return contents only for complete parse trees.
  1551. (if (eq type 'org-data) (lambda (blob contents info) contents)
  1552. (let ((transcoder (cdr (assq type (plist-get info :translate-alist)))))
  1553. (and (functionp transcoder) transcoder)))))
  1554. (defun org-export-data (data info)
  1555. "Convert DATA into current back-end format.
  1556. DATA is a parse tree, an element or an object or a secondary
  1557. string. INFO is a plist holding export options.
  1558. Return transcoded string."
  1559. (let* ((type (org-element-type data))
  1560. (results
  1561. (cond
  1562. ;; Ignored element/object.
  1563. ((memq data (plist-get info :ignore-list)) nil)
  1564. ;; Plain text.
  1565. ((eq type 'plain-text)
  1566. (org-export-filter-apply-functions
  1567. (plist-get info :filter-plain-text)
  1568. (let ((transcoder (org-export-transcoder data info)))
  1569. (if transcoder (funcall transcoder data info) data))
  1570. info))
  1571. ;; Uninterpreted element/object: change it back to Org
  1572. ;; syntax and export again resulting raw string.
  1573. ((not (org-export-interpret-p data info))
  1574. (org-export-data
  1575. (org-export-expand
  1576. data
  1577. (mapconcat (lambda (blob) (org-export-data blob info))
  1578. (org-element-contents data)
  1579. ""))
  1580. info))
  1581. ;; Secondary string.
  1582. ((not type)
  1583. (mapconcat (lambda (obj) (org-export-data obj info)) data ""))
  1584. ;; Element/Object without contents or, as a special case,
  1585. ;; headline with archive tag and archived trees restricted
  1586. ;; to title only.
  1587. ((or (not (org-element-contents data))
  1588. (and (eq type 'headline)
  1589. (eq (plist-get info :with-archived-trees) 'headline)
  1590. (org-element-property :archivedp data)))
  1591. (let ((transcoder (org-export-transcoder data info)))
  1592. (and (functionp transcoder) (funcall transcoder data nil info))))
  1593. ;; Element/Object with contents.
  1594. (t
  1595. (let ((transcoder (org-export-transcoder data info)))
  1596. (when transcoder
  1597. (let* ((greaterp (memq type org-element-greater-elements))
  1598. (objectp (and (not greaterp)
  1599. (memq type org-element-recursive-objects)))
  1600. (contents
  1601. (mapconcat
  1602. (lambda (element) (org-export-data element info))
  1603. (org-element-contents
  1604. (if (or greaterp objectp) data
  1605. ;; Elements directly containing objects
  1606. ;; must have their indentation normalized
  1607. ;; first.
  1608. (org-element-normalize-contents
  1609. data
  1610. ;; When normalizing contents of the first
  1611. ;; paragraph in an item or a footnote
  1612. ;; definition, ignore first line's
  1613. ;; indentation: there is none and it
  1614. ;; might be misleading.
  1615. (when (eq type 'paragraph)
  1616. (let ((parent (org-export-get-parent data)))
  1617. (and (eq (car (org-element-contents parent))
  1618. data)
  1619. (memq (org-element-type parent)
  1620. '(footnote-definition item))))))))
  1621. "")))
  1622. (funcall transcoder data
  1623. (if greaterp (org-element-normalize-string contents)
  1624. contents)
  1625. info))))))))
  1626. (cond
  1627. ((not results) nil)
  1628. ((memq type '(org-data plain-text nil)) results)
  1629. ;; Append the same white space between elements or objects as in
  1630. ;; the original buffer, and call appropriate filters.
  1631. (t
  1632. (let ((results
  1633. (org-export-filter-apply-functions
  1634. (plist-get info (intern (format ":filter-%s" type)))
  1635. (let ((post-blank (or (org-element-property :post-blank data) 0)))
  1636. (if (memq type org-element-all-elements)
  1637. (concat (org-element-normalize-string results)
  1638. (make-string post-blank ?\n))
  1639. (concat results (make-string post-blank ? ))))
  1640. info)))
  1641. ;; Eventually return string.
  1642. results)))))
  1643. (defun org-export-interpret-p (blob info)
  1644. "Non-nil if element or object BLOB should be interpreted as Org syntax.
  1645. Check is done according to export options INFO, stored as
  1646. a plist."
  1647. (case (org-element-type blob)
  1648. ;; ... entities...
  1649. (entity (plist-get info :with-entities))
  1650. ;; ... emphasis...
  1651. (emphasis (plist-get info :with-emphasize))
  1652. ;; ... fixed-width areas.
  1653. (fixed-width (plist-get info :with-fixed-width))
  1654. ;; ... footnotes...
  1655. ((footnote-definition footnote-reference)
  1656. (plist-get info :with-footnotes))
  1657. ;; ... sub/superscripts...
  1658. ((subscript superscript)
  1659. (let ((sub/super-p (plist-get info :with-sub-superscript)))
  1660. (if (eq sub/super-p '{})
  1661. (org-element-property :use-brackets-p blob)
  1662. sub/super-p)))
  1663. ;; ... tables...
  1664. (table (plist-get info :with-tables))
  1665. (otherwise t)))
  1666. (defun org-export-expand (blob contents)
  1667. "Expand a parsed element or object to its original state.
  1668. BLOB is either an element or an object. CONTENTS is its
  1669. contents, as a string or nil."
  1670. (funcall
  1671. (intern (format "org-element-%s-interpreter" (org-element-type blob)))
  1672. blob contents))
  1673. (defun org-export-ignore-element (element info)
  1674. "Add ELEMENT to `:ignore-list' in INFO.
  1675. Any element in `:ignore-list' will be skipped when using
  1676. `org-element-map'. INFO is modified by side effects."
  1677. (plist-put info :ignore-list (cons element (plist-get info :ignore-list))))
  1678. ;;; The Filter System
  1679. ;;
  1680. ;; Filters allow end-users to tweak easily the transcoded output.
  1681. ;; They are the functional counterpart of hooks, as every filter in
  1682. ;; a set is applied to the return value of the previous one.
  1683. ;;
  1684. ;; Every set is back-end agnostic. Although, a filter is always
  1685. ;; called, in addition to the string it applies to, with the back-end
  1686. ;; used as argument, so it's easy for the end-user to add back-end
  1687. ;; specific filters in the set. The communication channel, as
  1688. ;; a plist, is required as the third argument.
  1689. ;;
  1690. ;; From the developer side, filters sets can be installed in the
  1691. ;; process with the help of `org-BACKEND-filters-alist' variable.
  1692. ;; Each association has a key among the following symbols and
  1693. ;; a function or a list of functions as value.
  1694. ;;
  1695. ;; - `:filter-parse-tree' applies directly on the complete parsed
  1696. ;; tree. It's the only filters set that doesn't apply to a string.
  1697. ;; Users can set it through `org-export-filter-parse-tree-functions'
  1698. ;; variable.
  1699. ;;
  1700. ;; - `:filter-final-output' applies to the final transcoded string.
  1701. ;; Users can set it with `org-export-filter-final-output-functions'
  1702. ;; variable
  1703. ;;
  1704. ;; - `:filter-plain-text' applies to any string not recognized as Org
  1705. ;; syntax. `org-export-filter-plain-text-functions' allows users to
  1706. ;; configure it.
  1707. ;;
  1708. ;; - `:filter-TYPE' applies on the string returned after an element or
  1709. ;; object of type TYPE has been transcoded. An user can modify
  1710. ;; `org-export-filter-TYPE-functions'
  1711. ;;
  1712. ;; All filters sets are applied with
  1713. ;; `org-export-filter-apply-functions' function. Filters in a set are
  1714. ;; applied in a LIFO fashion. It allows developers to be sure that
  1715. ;; their filters will be applied first.
  1716. ;;
  1717. ;; Filters properties are installed in communication channel with
  1718. ;; `org-export-install-filters' function.
  1719. ;;
  1720. ;; Eventually, a hook (`org-export-before-parsing-hook') is run just
  1721. ;; before parsing to allow for heavy structure modifications.
  1722. ;;;; Before Parsing Hook
  1723. (defvar org-export-before-parsing-hook nil
  1724. "Hook run before parsing an export buffer.
  1725. This is run after include keywords have been expanded and Babel
  1726. code executed, on a copy of original buffer's area being
  1727. exported. Visibility is the same as in the original one. Point
  1728. is left at the beginning of the new one.")
  1729. ;;;; Special Filters
  1730. (defvar org-export-filter-parse-tree-functions nil
  1731. "List of functions applied to the parsed tree.
  1732. Each filter is called with three arguments: the parse tree, as
  1733. returned by `org-element-parse-buffer', the back-end, as
  1734. a symbol, and the communication channel, as a plist. It must
  1735. return the modified parse tree to transcode.")
  1736. (defvar org-export-filter-final-output-functions nil
  1737. "List of functions applied to the transcoded string.
  1738. Each filter is called with three arguments: the full transcoded
  1739. string, the back-end, as a symbol, and the communication channel,
  1740. as a plist. It must return a string that will be used as the
  1741. final export output.")
  1742. (defvar org-export-filter-plain-text-functions nil
  1743. "List of functions applied to plain text.
  1744. Each filter is called with three arguments: a string which
  1745. contains no Org syntax, the back-end, as a symbol, and the
  1746. communication channel, as a plist. It must return a string or
  1747. nil.")
  1748. ;;;; Elements Filters
  1749. (defvar org-export-filter-center-block-functions nil
  1750. "List of functions applied to a transcoded center block.
  1751. Each filter is called with three arguments: the transcoded data,
  1752. as a string, the back-end, as a symbol, and the communication
  1753. channel, as a plist. It must return a string or nil.")
  1754. (defvar org-export-filter-clock-functions nil
  1755. "List of functions applied to a transcoded clock.
  1756. Each filter is called with three arguments: the transcoded data,
  1757. as a string, the back-end, as a symbol, and the communication
  1758. channel, as a plist. It must return a string or nil.")
  1759. (defvar org-export-filter-drawer-functions nil
  1760. "List of functions applied to a transcoded drawer.
  1761. Each filter is called with three arguments: the transcoded data,
  1762. as a string, the back-end, as a symbol, and the communication
  1763. channel, as a plist. It must return a string or nil.")
  1764. (defvar org-export-filter-dynamic-block-functions nil
  1765. "List of functions applied to a transcoded dynamic-block.
  1766. Each filter is called with three arguments: the transcoded data,
  1767. as a string, the back-end, as a symbol, and the communication
  1768. channel, as a plist. It must return a string or nil.")
  1769. (defvar org-export-filter-headline-functions nil
  1770. "List of functions applied to a transcoded headline.
  1771. Each filter is called with three arguments: the transcoded data,
  1772. as a string, the back-end, as a symbol, and the communication
  1773. channel, as a plist. It must return a string or nil.")
  1774. (defvar org-export-filter-inlinetask-functions nil
  1775. "List of functions applied to a transcoded inlinetask.
  1776. Each filter is called with three arguments: the transcoded data,
  1777. as a string, the back-end, as a symbol, and the communication
  1778. channel, as a plist. It must return a string or nil.")
  1779. (defvar org-export-filter-plain-list-functions nil
  1780. "List of functions applied to a transcoded plain-list.
  1781. Each filter is called with three arguments: the transcoded data,
  1782. as a string, the back-end, as a symbol, and the communication
  1783. channel, as a plist. It must return a string or nil.")
  1784. (defvar org-export-filter-item-functions nil
  1785. "List of functions applied to a transcoded item.
  1786. Each filter is called with three arguments: the transcoded data,
  1787. as a string, the back-end, as a symbol, and the communication
  1788. channel, as a plist. It must return a string or nil.")
  1789. (defvar org-export-filter-comment-functions nil
  1790. "List of functions applied to a transcoded comment.
  1791. Each filter is called with three arguments: the transcoded data,
  1792. as a string, the back-end, as a symbol, and the communication
  1793. channel, as a plist. It must return a string or nil.")
  1794. (defvar org-export-filter-comment-block-functions nil
  1795. "List of functions applied to a transcoded comment-comment.
  1796. Each filter is called with three arguments: the transcoded data,
  1797. as a string, the back-end, as a symbol, and the communication
  1798. channel, as a plist. It must return a string or nil.")
  1799. (defvar org-export-filter-example-block-functions nil
  1800. "List of functions applied to a transcoded example-block.
  1801. Each filter is called with three arguments: the transcoded data,
  1802. as a string, the back-end, as a symbol, and the communication
  1803. channel, as a plist. It must return a string or nil.")
  1804. (defvar org-export-filter-export-block-functions nil
  1805. "List of functions applied to a transcoded export-block.
  1806. Each filter is called with three arguments: the transcoded data,
  1807. as a string, the back-end, as a symbol, and the communication
  1808. channel, as a plist. It must return a string or nil.")
  1809. (defvar org-export-filter-fixed-width-functions nil
  1810. "List of functions applied to a transcoded fixed-width.
  1811. Each filter is called with three arguments: the transcoded data,
  1812. as a string, the back-end, as a symbol, and the communication
  1813. channel, as a plist. It must return a string or nil.")
  1814. (defvar org-export-filter-footnote-definition-functions nil
  1815. "List of functions applied to a transcoded footnote-definition.
  1816. Each filter is called with three arguments: the transcoded data,
  1817. as a string, the back-end, as a symbol, and the communication
  1818. channel, as a plist. It must return a string or nil.")
  1819. (defvar org-export-filter-horizontal-rule-functions nil
  1820. "List of functions applied to a transcoded horizontal-rule.
  1821. Each filter is called with three arguments: the transcoded data,
  1822. as a string, the back-end, as a symbol, and the communication
  1823. channel, as a plist. It must return a string or nil.")
  1824. (defvar org-export-filter-keyword-functions nil
  1825. "List of functions applied to a transcoded keyword.
  1826. Each filter is called with three arguments: the transcoded data,
  1827. as a string, the back-end, as a symbol, and the communication
  1828. channel, as a plist. It must return a string or nil.")
  1829. (defvar org-export-filter-latex-environment-functions nil
  1830. "List of functions applied to a transcoded latex-environment.
  1831. Each filter is called with three arguments: the transcoded data,
  1832. as a string, the back-end, as a symbol, and the communication
  1833. channel, as a plist. It must return a string or nil.")
  1834. (defvar org-export-filter-babel-call-functions nil
  1835. "List of functions applied to a transcoded babel-call.
  1836. Each filter is called with three arguments: the transcoded data,
  1837. as a string, the back-end, as a symbol, and the communication
  1838. channel, as a plist. It must return a string or nil.")
  1839. (defvar org-export-filter-paragraph-functions nil
  1840. "List of functions applied to a transcoded paragraph.
  1841. Each filter is called with three arguments: the transcoded data,
  1842. as a string, the back-end, as a symbol, and the communication
  1843. channel, as a plist. It must return a string or nil.")
  1844. (defvar org-export-filter-planning-functions nil
  1845. "List of functions applied to a transcoded planning.
  1846. Each filter is called with three arguments: the transcoded data,
  1847. as a string, the back-end, as a symbol, and the communication
  1848. channel, as a plist. It must return a string or nil.")
  1849. (defvar org-export-filter-property-drawer-functions nil
  1850. "List of functions applied to a transcoded property-drawer.
  1851. Each filter is called with three arguments: the transcoded data,
  1852. as a string, the back-end, as a symbol, and the communication
  1853. channel, as a plist. It must return a string or nil.")
  1854. (defvar org-export-filter-quote-block-functions nil
  1855. "List of functions applied to a transcoded quote block.
  1856. Each filter is called with three arguments: the transcoded quote
  1857. data, as a string, the back-end, as a symbol, and the
  1858. communication channel, as a plist. It must return a string or
  1859. nil.")
  1860. (defvar org-export-filter-quote-section-functions nil
  1861. "List of functions applied to a transcoded quote-section.
  1862. Each filter is called with three arguments: the transcoded data,
  1863. as a string, the back-end, as a symbol, and the communication
  1864. channel, as a plist. It must return a string or nil.")
  1865. (defvar org-export-filter-section-functions nil
  1866. "List of functions applied to a transcoded section.
  1867. Each filter is called with three arguments: the transcoded data,
  1868. as a string, the back-end, as a symbol, and the communication
  1869. channel, as a plist. It must return a string or nil.")
  1870. (defvar org-export-filter-special-block-functions nil
  1871. "List of functions applied to a transcoded special block.
  1872. Each filter is called with three arguments: the transcoded data,
  1873. as a string, the back-end, as a symbol, and the communication
  1874. channel, as a plist. It must return a string or nil.")
  1875. (defvar org-export-filter-src-block-functions nil
  1876. "List of functions applied to a transcoded src-block.
  1877. Each filter is called with three arguments: the transcoded data,
  1878. as a string, the back-end, as a symbol, and the communication
  1879. channel, as a plist. It must return a string or nil.")
  1880. (defvar org-export-filter-table-functions nil
  1881. "List of functions applied to a transcoded table.
  1882. Each filter is called with three arguments: the transcoded data,
  1883. as a string, the back-end, as a symbol, and the communication
  1884. channel, as a plist. It must return a string or nil.")
  1885. (defvar org-export-filter-table-cell-functions nil
  1886. "List of functions applied to a transcoded table-cell.
  1887. Each filter is called with three arguments: the transcoded data,
  1888. as a string, the back-end, as a symbol, and the communication
  1889. channel, as a plist. It must return a string or nil.")
  1890. (defvar org-export-filter-table-row-functions nil
  1891. "List of functions applied to a transcoded table-row.
  1892. Each filter is called with three arguments: the transcoded data,
  1893. as a string, the back-end, as a symbol, and the communication
  1894. channel, as a plist. It must return a string or nil.")
  1895. (defvar org-export-filter-verse-block-functions nil
  1896. "List of functions applied to a transcoded verse block.
  1897. Each filter is called with three arguments: the transcoded data,
  1898. as a string, the back-end, as a symbol, and the communication
  1899. channel, as a plist. It must return a string or nil.")
  1900. ;;;; Objects Filters
  1901. (defvar org-export-filter-bold-functions nil
  1902. "List of functions applied to transcoded bold text.
  1903. Each filter is called with three arguments: the transcoded data,
  1904. as a string, the back-end, as a symbol, and the communication
  1905. channel, as a plist. It must return a string or nil.")
  1906. (defvar org-export-filter-code-functions nil
  1907. "List of functions applied to transcoded code text.
  1908. Each filter is called with three arguments: the transcoded data,
  1909. as a string, the back-end, as a symbol, and the communication
  1910. channel, as a plist. It must return a string or nil.")
  1911. (defvar org-export-filter-entity-functions nil
  1912. "List of functions applied to a transcoded entity.
  1913. Each filter is called with three arguments: the transcoded data,
  1914. as a string, the back-end, as a symbol, and the communication
  1915. channel, as a plist. It must return a string or nil.")
  1916. (defvar org-export-filter-export-snippet-functions nil
  1917. "List of functions applied to a transcoded export-snippet.
  1918. Each filter is called with three arguments: the transcoded data,
  1919. as a string, the back-end, as a symbol, and the communication
  1920. channel, as a plist. It must return a string or nil.")
  1921. (defvar org-export-filter-footnote-reference-functions nil
  1922. "List of functions applied to a transcoded footnote-reference.
  1923. Each filter is called with three arguments: the transcoded data,
  1924. as a string, the back-end, as a symbol, and the communication
  1925. channel, as a plist. It must return a string or nil.")
  1926. (defvar org-export-filter-inline-babel-call-functions nil
  1927. "List of functions applied to a transcoded inline-babel-call.
  1928. Each filter is called with three arguments: the transcoded data,
  1929. as a string, the back-end, as a symbol, and the communication
  1930. channel, as a plist. It must return a string or nil.")
  1931. (defvar org-export-filter-inline-src-block-functions nil
  1932. "List of functions applied to a transcoded inline-src-block.
  1933. Each filter is called with three arguments: the transcoded data,
  1934. as a string, the back-end, as a symbol, and the communication
  1935. channel, as a plist. It must return a string or nil.")
  1936. (defvar org-export-filter-italic-functions nil
  1937. "List of functions applied to transcoded italic text.
  1938. Each filter is called with three arguments: the transcoded data,
  1939. as a string, the back-end, as a symbol, and the communication
  1940. channel, as a plist. It must return a string or nil.")
  1941. (defvar org-export-filter-latex-fragment-functions nil
  1942. "List of functions applied to a transcoded latex-fragment.
  1943. Each filter is called with three arguments: the transcoded data,
  1944. as a string, the back-end, as a symbol, and the communication
  1945. channel, as a plist. It must return a string or nil.")
  1946. (defvar org-export-filter-line-break-functions nil
  1947. "List of functions applied to a transcoded line-break.
  1948. Each filter is called with three arguments: the transcoded data,
  1949. as a string, the back-end, as a symbol, and the communication
  1950. channel, as a plist. It must return a string or nil.")
  1951. (defvar org-export-filter-link-functions nil
  1952. "List of functions applied to a transcoded link.
  1953. Each filter is called with three arguments: the transcoded data,
  1954. as a string, the back-end, as a symbol, and the communication
  1955. channel, as a plist. It must return a string or nil.")
  1956. (defvar org-export-filter-macro-functions nil
  1957. "List of functions applied to a transcoded macro.
  1958. Each filter is called with three arguments: the transcoded data,
  1959. as a string, the back-end, as a symbol, and the communication
  1960. channel, as a plist. It must return a string or nil.")
  1961. (defvar org-export-filter-radio-target-functions nil
  1962. "List of functions applied to a transcoded radio-target.
  1963. Each filter is called with three arguments: the transcoded data,
  1964. as a string, the back-end, as a symbol, and the communication
  1965. channel, as a plist. It must return a string or nil.")
  1966. (defvar org-export-filter-statistics-cookie-functions nil
  1967. "List of functions applied to a transcoded statistics-cookie.
  1968. Each filter is called with three arguments: the transcoded data,
  1969. as a string, the back-end, as a symbol, and the communication
  1970. channel, as a plist. It must return a string or nil.")
  1971. (defvar org-export-filter-strike-through-functions nil
  1972. "List of functions applied to transcoded strike-through text.
  1973. Each filter is called with three arguments: the transcoded data,
  1974. as a string, the back-end, as a symbol, and the communication
  1975. channel, as a plist. It must return a string or nil.")
  1976. (defvar org-export-filter-subscript-functions nil
  1977. "List of functions applied to a transcoded subscript.
  1978. Each filter is called with three arguments: the transcoded data,
  1979. as a string, the back-end, as a symbol, and the communication
  1980. channel, as a plist. It must return a string or nil.")
  1981. (defvar org-export-filter-superscript-functions nil
  1982. "List of functions applied to a transcoded superscript.
  1983. Each filter is called with three arguments: the transcoded data,
  1984. as a string, the back-end, as a symbol, and the communication
  1985. channel, as a plist. It must return a string or nil.")
  1986. (defvar org-export-filter-target-functions nil
  1987. "List of functions applied to a transcoded target.
  1988. Each filter is called with three arguments: the transcoded data,
  1989. as a string, the back-end, as a symbol, and the communication
  1990. channel, as a plist. It must return a string or nil.")
  1991. (defvar org-export-filter-timestamp-functions nil
  1992. "List of functions applied to a transcoded timestamp.
  1993. Each filter is called with three arguments: the transcoded data,
  1994. as a string, the back-end, as a symbol, and the communication
  1995. channel, as a plist. It must return a string or nil.")
  1996. (defvar org-export-filter-underline-functions nil
  1997. "List of functions applied to transcoded underline text.
  1998. Each filter is called with three arguments: the transcoded data,
  1999. as a string, the back-end, as a symbol, and the communication
  2000. channel, as a plist. It must return a string or nil.")
  2001. (defvar org-export-filter-verbatim-functions nil
  2002. "List of functions applied to transcoded verbatim text.
  2003. Each filter is called with three arguments: the transcoded data,
  2004. as a string, the back-end, as a symbol, and the communication
  2005. channel, as a plist. It must return a string or nil.")
  2006. ;;;; Filters Tools
  2007. ;;
  2008. ;; Internal function `org-export-install-filters' installs filters
  2009. ;; hard-coded in back-ends (developer filters) and filters from global
  2010. ;; variables (user filters) in the communication channel.
  2011. ;;
  2012. ;; Internal function `org-export-filter-apply-functions' takes care
  2013. ;; about applying each filter in order to a given data. It stops
  2014. ;; whenever a filter returns a nil value.
  2015. (defun org-export-filter-apply-functions (filters value info)
  2016. "Call every function in FILTERS.
  2017. Functions are called with arguments VALUE, current export
  2018. back-end and INFO. Call is done in a LIFO fashion, to be sure
  2019. that developer specified filters, if any, are called first."
  2020. (loop for filter in filters
  2021. if (not value) return nil else
  2022. do (setq value (funcall filter value (plist-get info :back-end) info)))
  2023. value)
  2024. (defun org-export-install-filters (info)
  2025. "Install filters properties in communication channel.
  2026. INFO is a plist containing the current communication channel.
  2027. Return the updated communication channel."
  2028. (let (plist)
  2029. ;; Install user defined filters with `org-export-filters-alist'.
  2030. (mapc (lambda (p)
  2031. (setq plist (plist-put plist (car p) (eval (cdr p)))))
  2032. org-export-filters-alist)
  2033. ;; Prepend back-end specific filters to that list.
  2034. (let ((back-end-filters (intern (format "org-%s-filters-alist"
  2035. (plist-get info :back-end)))))
  2036. (when (boundp back-end-filters)
  2037. (mapc (lambda (p)
  2038. ;; Single values get consed, lists are prepended.
  2039. (let ((key (car p)) (value (cdr p)))
  2040. (when value
  2041. (setq plist
  2042. (plist-put
  2043. plist key
  2044. (if (atom value) (cons value (plist-get plist key))
  2045. (append value (plist-get plist key))))))))
  2046. (eval back-end-filters))))
  2047. ;; Return new communication channel.
  2048. (org-combine-plists info plist)))
  2049. ;;; Core functions
  2050. ;;
  2051. ;; This is the room for the main function, `org-export-as', along with
  2052. ;; its derivatives, `org-export-to-buffer' and `org-export-to-file'.
  2053. ;; They differ only by the way they output the resulting code.
  2054. ;;
  2055. ;; `org-export-output-file-name' is an auxiliary function meant to be
  2056. ;; used with `org-export-to-file'. With a given extension, it tries
  2057. ;; to provide a canonical file name to write export output to.
  2058. ;;
  2059. ;; Note that `org-export-as' doesn't really parse the current buffer,
  2060. ;; but a copy of it (with the same buffer-local variables and
  2061. ;; visibility), where include keywords are expanded and Babel blocks
  2062. ;; are executed, if appropriate.
  2063. ;; `org-export-with-current-buffer-copy' macro prepares that copy.
  2064. ;;
  2065. ;; File inclusion is taken care of by
  2066. ;; `org-export-expand-include-keyword' and
  2067. ;; `org-export-prepare-file-contents'. Structure wise, including
  2068. ;; a whole Org file in a buffer often makes little sense. For
  2069. ;; example, if the file contains an headline and the include keyword
  2070. ;; was within an item, the item should contain the headline. That's
  2071. ;; why file inclusion should be done before any structure can be
  2072. ;; associated to the file, that is before parsing.
  2073. (defvar org-current-export-file) ; Dynamically scoped
  2074. (defvar org-export-current-backend) ; Dynamically scoped
  2075. (defun org-export-as
  2076. (backend &optional subtreep visible-only body-only ext-plist noexpand)
  2077. "Transcode current Org buffer into BACKEND code.
  2078. If narrowing is active in the current buffer, only transcode its
  2079. narrowed part.
  2080. If a region is active, transcode that region.
  2081. When optional argument SUBTREEP is non-nil, transcode the
  2082. sub-tree at point, extracting information from the headline
  2083. properties first.
  2084. When optional argument VISIBLE-ONLY is non-nil, don't export
  2085. contents of hidden elements.
  2086. When optional argument BODY-ONLY is non-nil, only return body
  2087. code, without preamble nor postamble.
  2088. Optional argument EXT-PLIST, when provided, is a property list
  2089. with external parameters overriding Org default settings, but
  2090. still inferior to file-local settings.
  2091. Optional argument NOEXPAND, when non-nil, prevents included files
  2092. to be expanded and Babel code to be executed.
  2093. Return code as a string."
  2094. (save-excursion
  2095. (save-restriction
  2096. ;; Narrow buffer to an appropriate region or subtree for
  2097. ;; parsing. If parsing subtree, be sure to remove main headline
  2098. ;; too.
  2099. (cond ((org-region-active-p)
  2100. (narrow-to-region (region-beginning) (region-end)))
  2101. (subtreep
  2102. (org-narrow-to-subtree)
  2103. (goto-char (point-min))
  2104. (forward-line)
  2105. (narrow-to-region (point) (point-max))))
  2106. ;; 1. Get export environment from original buffer. Also install
  2107. ;; user's and developer's filters.
  2108. (let ((info (org-export-install-filters
  2109. (org-export-get-environment backend subtreep ext-plist)))
  2110. ;; 2. Get parse tree. Buffer isn't parsed directly.
  2111. ;; Instead, a temporary copy is created, where include
  2112. ;; keywords are expanded and code blocks are evaluated.
  2113. (tree (let ((buf (or (buffer-file-name (buffer-base-buffer))
  2114. (current-buffer))))
  2115. (org-export-with-current-buffer-copy
  2116. (unless noexpand
  2117. (org-export-expand-include-keyword)
  2118. ;; Setting `org-current-export-file' is
  2119. ;; required by Org Babel to properly resolve
  2120. ;; noweb references.
  2121. (let ((org-current-export-file buf))
  2122. (org-export-blocks-preprocess)))
  2123. (goto-char (point-min))
  2124. ;; Run hook with `org-export-current-backend' set
  2125. ;; to BACKEND.
  2126. (let ((org-export-current-backend backend))
  2127. (run-hooks 'org-export-before-parsing-hook))
  2128. ;; Eventually parse buffer.
  2129. (org-element-parse-buffer nil visible-only)))))
  2130. ;; 3. Call parse-tree filters to get the final tree.
  2131. (setq tree
  2132. (org-export-filter-apply-functions
  2133. (plist-get info :filter-parse-tree) tree info))
  2134. ;; 4. Now tree is complete, compute its properties and add
  2135. ;; them to communication channel.
  2136. (setq info
  2137. (org-combine-plists
  2138. info (org-export-collect-tree-properties tree info)))
  2139. ;; 5. Eventually transcode TREE. Wrap the resulting string
  2140. ;; into a template, if required. Eventually call
  2141. ;; final-output filter.
  2142. (let* ((body (org-element-normalize-string (org-export-data tree info)))
  2143. (template (cdr (assq 'template
  2144. (plist-get info :translate-alist))))
  2145. (output (org-export-filter-apply-functions
  2146. (plist-get info :filter-final-output)
  2147. (if (or (not (functionp template)) body-only) body
  2148. (funcall template body info))
  2149. info)))
  2150. ;; Maybe add final OUTPUT to kill ring, then return it.
  2151. (when org-export-copy-to-kill-ring (org-kill-new output))
  2152. output)))))
  2153. (defun org-export-to-buffer
  2154. (backend buffer &optional subtreep visible-only body-only ext-plist noexpand)
  2155. "Call `org-export-as' with output to a specified buffer.
  2156. BACKEND is the back-end used for transcoding, as a symbol.
  2157. BUFFER is the output buffer. If it already exists, it will be
  2158. erased first, otherwise, it will be created.
  2159. Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY, EXT-PLIST
  2160. and NOEXPAND are similar to those used in `org-export-as', which
  2161. see.
  2162. Return buffer."
  2163. (let ((out (org-export-as
  2164. backend subtreep visible-only body-only ext-plist noexpand))
  2165. (buffer (get-buffer-create buffer)))
  2166. (with-current-buffer buffer
  2167. (erase-buffer)
  2168. (insert out)
  2169. (goto-char (point-min)))
  2170. buffer))
  2171. (defun org-export-to-file
  2172. (backend file &optional subtreep visible-only body-only ext-plist noexpand)
  2173. "Call `org-export-as' with output to a specified file.
  2174. BACKEND is the back-end used for transcoding, as a symbol. FILE
  2175. is the name of the output file, as a string.
  2176. Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY, EXT-PLIST
  2177. and NOEXPAND are similar to those used in `org-export-as', which
  2178. see.
  2179. Return output file's name."
  2180. ;; Checks for FILE permissions. `write-file' would do the same, but
  2181. ;; we'd rather avoid needless transcoding of parse tree.
  2182. (unless (file-writable-p file) (error "Output file not writable"))
  2183. ;; Insert contents to a temporary buffer and write it to FILE.
  2184. (let ((out (org-export-as
  2185. backend subtreep visible-only body-only ext-plist noexpand)))
  2186. (with-temp-buffer
  2187. (insert out)
  2188. (let ((coding-system-for-write org-export-coding-system))
  2189. (write-file file))))
  2190. ;; Return full path.
  2191. file)
  2192. (defun org-export-output-file-name (extension &optional subtreep pub-dir)
  2193. "Return output file's name according to buffer specifications.
  2194. EXTENSION is a string representing the output file extension,
  2195. with the leading dot.
  2196. With a non-nil optional argument SUBTREEP, try to determine
  2197. output file's name by looking for \"EXPORT_FILE_NAME\" property
  2198. of subtree at point.
  2199. When optional argument PUB-DIR is set, use it as the publishing
  2200. directory.
  2201. When optional argument VISIBLE-ONLY is non-nil, don't export
  2202. contents of hidden elements.
  2203. Return file name as a string, or nil if it couldn't be
  2204. determined."
  2205. (let ((base-name
  2206. ;; File name may come from EXPORT_FILE_NAME subtree property,
  2207. ;; assuming point is at beginning of said sub-tree.
  2208. (file-name-sans-extension
  2209. (or (and subtreep
  2210. (org-entry-get
  2211. (save-excursion
  2212. (ignore-errors (org-back-to-heading) (point)))
  2213. "EXPORT_FILE_NAME" t))
  2214. ;; File name may be extracted from buffer's associated
  2215. ;; file, if any.
  2216. (buffer-file-name (buffer-base-buffer))
  2217. ;; Can't determine file name on our own: Ask user.
  2218. (let ((read-file-name-function
  2219. (and org-completion-use-ido 'ido-read-file-name)))
  2220. (read-file-name
  2221. "Output file: " pub-dir nil nil nil
  2222. (lambda (name)
  2223. (string= (file-name-extension name t) extension))))))))
  2224. ;; Build file name. Enforce EXTENSION over whatever user may have
  2225. ;; come up with. PUB-DIR, if defined, always has precedence over
  2226. ;; any provided path.
  2227. (cond
  2228. (pub-dir
  2229. (concat (file-name-as-directory pub-dir)
  2230. (file-name-nondirectory base-name)
  2231. extension))
  2232. ((string= (file-name-nondirectory base-name) base-name)
  2233. (concat (file-name-as-directory ".") base-name extension))
  2234. (t (concat base-name extension)))))
  2235. (defmacro org-export-with-current-buffer-copy (&rest body)
  2236. "Apply BODY in a copy of the current buffer.
  2237. The copy preserves local variables and visibility of the original
  2238. buffer.
  2239. Point is at buffer's beginning when BODY is applied."
  2240. (org-with-gensyms (original-buffer offset buffer-string overlays)
  2241. `(let ((,original-buffer (current-buffer))
  2242. (,offset (1- (point-min)))
  2243. (,buffer-string (buffer-string))
  2244. (,overlays (mapcar
  2245. 'copy-overlay (overlays-in (point-min) (point-max)))))
  2246. (with-temp-buffer
  2247. (let ((buffer-invisibility-spec nil))
  2248. (org-clone-local-variables
  2249. ,original-buffer
  2250. "^\\(org-\\|orgtbl-\\|major-mode$\\|outline-\\(regexp\\|level\\)$\\)")
  2251. (insert ,buffer-string)
  2252. (mapc (lambda (ov)
  2253. (move-overlay
  2254. ov
  2255. (- (overlay-start ov) ,offset)
  2256. (- (overlay-end ov) ,offset)
  2257. (current-buffer)))
  2258. ,overlays)
  2259. (goto-char (point-min))
  2260. (progn ,@body))))))
  2261. (def-edebug-spec org-export-with-current-buffer-copy (body))
  2262. (defun org-export-expand-include-keyword (&optional included dir)
  2263. "Expand every include keyword in buffer.
  2264. Optional argument INCLUDED is a list of included file names along
  2265. with their line restriction, when appropriate. It is used to
  2266. avoid infinite recursion. Optional argument DIR is the current
  2267. working directory. It is used to properly resolve relative
  2268. paths."
  2269. (let ((case-fold-search t))
  2270. (goto-char (point-min))
  2271. (while (re-search-forward "^[ \t]*#\\+INCLUDE: \\(.*\\)" nil t)
  2272. (when (eq (org-element-type (save-match-data (org-element-at-point)))
  2273. 'keyword)
  2274. (beginning-of-line)
  2275. ;; Extract arguments from keyword's value.
  2276. (let* ((value (match-string 1))
  2277. (ind (org-get-indentation))
  2278. (file (and (string-match "^\"\\(\\S-+\\)\"" value)
  2279. (prog1 (expand-file-name (match-string 1 value) dir)
  2280. (setq value (replace-match "" nil nil value)))))
  2281. (lines
  2282. (and (string-match
  2283. ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value)
  2284. (prog1 (match-string 1 value)
  2285. (setq value (replace-match "" nil nil value)))))
  2286. (env (cond ((string-match "\\<example\\>" value) 'example)
  2287. ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
  2288. (match-string 1 value))))
  2289. ;; Minimal level of included file defaults to the child
  2290. ;; level of the current headline, if any, or one. It
  2291. ;; only applies is the file is meant to be included as
  2292. ;; an Org one.
  2293. (minlevel
  2294. (and (not env)
  2295. (if (string-match ":minlevel +\\([0-9]+\\)" value)
  2296. (prog1 (string-to-number (match-string 1 value))
  2297. (setq value (replace-match "" nil nil value)))
  2298. (let ((cur (org-current-level)))
  2299. (if cur (1+ (org-reduced-level cur)) 1))))))
  2300. ;; Remove keyword.
  2301. (delete-region (point) (progn (forward-line) (point)))
  2302. (cond
  2303. ((not (file-readable-p file)) (error "Cannot include file %s" file))
  2304. ;; Check if files has already been parsed. Look after
  2305. ;; inclusion lines too, as different parts of the same file
  2306. ;; can be included too.
  2307. ((member (list file lines) included)
  2308. (error "Recursive file inclusion: %s" file))
  2309. (t
  2310. (cond
  2311. ((eq env 'example)
  2312. (insert
  2313. (let ((ind-str (make-string ind ? ))
  2314. (contents
  2315. ;; Protect sensitive contents with commas.
  2316. (replace-regexp-in-string
  2317. "\\(^\\)\\([*]\\|[ \t]*#\\+\\)" ","
  2318. (org-export-prepare-file-contents file lines)
  2319. nil nil 1)))
  2320. (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
  2321. ind-str contents ind-str))))
  2322. ((stringp env)
  2323. (insert
  2324. (let ((ind-str (make-string ind ? ))
  2325. (contents
  2326. ;; Protect sensitive contents with commas.
  2327. (replace-regexp-in-string
  2328. (if (string= env "org") "\\(^\\)\\(.\\)"
  2329. "\\(^\\)\\([*]\\|[ \t]*#\\+\\)") ","
  2330. (org-export-prepare-file-contents file lines)
  2331. nil nil 1)))
  2332. (format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
  2333. ind-str env contents ind-str))))
  2334. (t
  2335. (insert
  2336. (with-temp-buffer
  2337. (org-mode)
  2338. (insert
  2339. (org-export-prepare-file-contents file lines ind minlevel))
  2340. (org-export-expand-include-keyword
  2341. (cons (list file lines) included)
  2342. (file-name-directory file))
  2343. (buffer-string))))))))))))
  2344. (defun org-export-prepare-file-contents (file &optional lines ind minlevel)
  2345. "Prepare the contents of FILE for inclusion and return them as a string.
  2346. When optional argument LINES is a string specifying a range of
  2347. lines, include only those lines.
  2348. Optional argument IND, when non-nil, is an integer specifying the
  2349. global indentation of returned contents. Since its purpose is to
  2350. allow an included file to stay in the same environment it was
  2351. created \(i.e. a list item), it doesn't apply past the first
  2352. headline encountered.
  2353. Optional argument MINLEVEL, when non-nil, is an integer
  2354. specifying the level that any top-level headline in the included
  2355. file should have."
  2356. (with-temp-buffer
  2357. (insert-file-contents file)
  2358. (when lines
  2359. (let* ((lines (split-string lines "-"))
  2360. (lbeg (string-to-number (car lines)))
  2361. (lend (string-to-number (cadr lines)))
  2362. (beg (if (zerop lbeg) (point-min)
  2363. (goto-char (point-min))
  2364. (forward-line (1- lbeg))
  2365. (point)))
  2366. (end (if (zerop lend) (point-max)
  2367. (goto-char (point-min))
  2368. (forward-line (1- lend))
  2369. (point))))
  2370. (narrow-to-region beg end)))
  2371. ;; Remove blank lines at beginning and end of contents. The logic
  2372. ;; behind that removal is that blank lines around include keyword
  2373. ;; override blank lines in included file.
  2374. (goto-char (point-min))
  2375. (org-skip-whitespace)
  2376. (beginning-of-line)
  2377. (delete-region (point-min) (point))
  2378. (goto-char (point-max))
  2379. (skip-chars-backward " \r\t\n")
  2380. (forward-line)
  2381. (delete-region (point) (point-max))
  2382. ;; If IND is set, preserve indentation of include keyword until
  2383. ;; the first headline encountered.
  2384. (when ind
  2385. (unless (eq major-mode 'org-mode) (org-mode))
  2386. (goto-char (point-min))
  2387. (let ((ind-str (make-string ind ? )))
  2388. (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
  2389. ;; Do not move footnote definitions out of column 0.
  2390. (unless (and (looking-at org-footnote-definition-re)
  2391. (eq (org-element-type (org-element-at-point))
  2392. 'footnote-definition))
  2393. (insert ind-str))
  2394. (forward-line))))
  2395. ;; When MINLEVEL is specified, compute minimal level for headlines
  2396. ;; in the file (CUR-MIN), and remove stars to each headline so
  2397. ;; that headlines with minimal level have a level of MINLEVEL.
  2398. (when minlevel
  2399. (unless (eq major-mode 'org-mode) (org-mode))
  2400. (let ((levels (org-map-entries
  2401. (lambda () (org-reduced-level (org-current-level))))))
  2402. (when levels
  2403. (let ((offset (- minlevel (apply 'min levels))))
  2404. (unless (zerop offset)
  2405. (when org-odd-levels-only (setq offset (* offset 2)))
  2406. ;; Only change stars, don't bother moving whole
  2407. ;; sections.
  2408. (org-map-entries
  2409. (lambda () (if (< offset 0) (delete-char (abs offset))
  2410. (insert (make-string offset ?*))))))))))
  2411. (buffer-string)))
  2412. ;;; Tools For Back-Ends
  2413. ;;
  2414. ;; A whole set of tools is available to help build new exporters. Any
  2415. ;; function general enough to have its use across many back-ends
  2416. ;; should be added here.
  2417. ;;
  2418. ;; As of now, functions operating on footnotes, headlines, links,
  2419. ;; macros, references, src-blocks, tables and tables of contents are
  2420. ;; implemented.
  2421. ;;;; For Affiliated Keywords
  2422. ;;
  2423. ;; `org-export-read-attribute' reads a property from a given element
  2424. ;; as a plist. It can be used to normalize affiliated keywords'
  2425. ;; syntax.
  2426. (defun org-export-read-attribute (attribute element &optional property)
  2427. "Turn ATTRIBUTE property from ELEMENT into a plist.
  2428. When optional argument PROPERTY is non-nil, return the value of
  2429. that property within attributes.
  2430. This function assumes attributes are defined as \":keyword
  2431. value\" pairs. It is appropriate for `:attr_html' like
  2432. properties."
  2433. (let ((attributes
  2434. (let ((value (org-element-property attribute element)))
  2435. (and value
  2436. (read (format "(%s)" (mapconcat 'identity value " ")))))))
  2437. (if property (plist-get attributes property) attributes)))
  2438. ;;;; For Export Snippets
  2439. ;;
  2440. ;; Every export snippet is transmitted to the back-end. Though, the
  2441. ;; latter will only retain one type of export-snippet, ignoring
  2442. ;; others, based on the former's target back-end. The function
  2443. ;; `org-export-snippet-backend' returns that back-end for a given
  2444. ;; export-snippet.
  2445. (defun org-export-snippet-backend (export-snippet)
  2446. "Return EXPORT-SNIPPET targeted back-end as a symbol.
  2447. Translation, with `org-export-snippet-translation-alist', is
  2448. applied."
  2449. (let ((back-end (org-element-property :back-end export-snippet)))
  2450. (intern
  2451. (or (cdr (assoc back-end org-export-snippet-translation-alist))
  2452. back-end))))
  2453. ;;;; For Footnotes
  2454. ;;
  2455. ;; `org-export-collect-footnote-definitions' is a tool to list
  2456. ;; actually used footnotes definitions in the whole parse tree, or in
  2457. ;; an headline, in order to add footnote listings throughout the
  2458. ;; transcoded data.
  2459. ;;
  2460. ;; `org-export-footnote-first-reference-p' is a predicate used by some
  2461. ;; back-ends, when they need to attach the footnote definition only to
  2462. ;; the first occurrence of the corresponding label.
  2463. ;;
  2464. ;; `org-export-get-footnote-definition' and
  2465. ;; `org-export-get-footnote-number' provide easier access to
  2466. ;; additional information relative to a footnote reference.
  2467. (defun org-export-collect-footnote-definitions (data info)
  2468. "Return an alist between footnote numbers, labels and definitions.
  2469. DATA is the parse tree from which definitions are collected.
  2470. INFO is the plist used as a communication channel.
  2471. Definitions are sorted by order of references. They either
  2472. appear as Org data or as a secondary string for inlined
  2473. footnotes. Unreferenced definitions are ignored."
  2474. (let* (num-alist
  2475. collect-fn ; for byte-compiler.
  2476. (collect-fn
  2477. (function
  2478. (lambda (data)
  2479. ;; Collect footnote number, label and definition in DATA.
  2480. (org-element-map
  2481. data 'footnote-reference
  2482. (lambda (fn)
  2483. (when (org-export-footnote-first-reference-p fn info)
  2484. (let ((def (org-export-get-footnote-definition fn info)))
  2485. (push
  2486. (list (org-export-get-footnote-number fn info)
  2487. (org-element-property :label fn)
  2488. def)
  2489. num-alist)
  2490. ;; Also search in definition for nested footnotes.
  2491. (when (eq (org-element-property :type fn) 'standard)
  2492. (funcall collect-fn def)))))
  2493. ;; Don't enter footnote definitions since it will happen
  2494. ;; when their first reference is found.
  2495. info nil 'footnote-definition)))))
  2496. (funcall collect-fn (plist-get info :parse-tree))
  2497. (reverse num-alist)))
  2498. (defun org-export-footnote-first-reference-p (footnote-reference info)
  2499. "Non-nil when a footnote reference is the first one for its label.
  2500. FOOTNOTE-REFERENCE is the footnote reference being considered.
  2501. INFO is the plist used as a communication channel."
  2502. (let ((label (org-element-property :label footnote-reference)))
  2503. ;; Anonymous footnotes are always a first reference.
  2504. (if (not label) t
  2505. ;; Otherwise, return the first footnote with the same LABEL and
  2506. ;; test if it is equal to FOOTNOTE-REFERENCE.
  2507. (let* (search-refs ; for byte-compiler.
  2508. (search-refs
  2509. (function
  2510. (lambda (data)
  2511. (org-element-map
  2512. data 'footnote-reference
  2513. (lambda (fn)
  2514. (cond
  2515. ((string= (org-element-property :label fn) label)
  2516. (throw 'exit fn))
  2517. ;; If FN isn't inlined, be sure to traverse its
  2518. ;; definition before resuming search. See
  2519. ;; comments in `org-export-get-footnote-number'
  2520. ;; for more information.
  2521. ((eq (org-element-property :type fn) 'standard)
  2522. (funcall search-refs
  2523. (org-export-get-footnote-definition fn info)))))
  2524. ;; Don't enter footnote definitions since it will
  2525. ;; happen when their first reference is found.
  2526. info 'first-match 'footnote-definition)))))
  2527. (eq (catch 'exit (funcall search-refs (plist-get info :parse-tree)))
  2528. footnote-reference)))))
  2529. (defun org-export-get-footnote-definition (footnote-reference info)
  2530. "Return definition of FOOTNOTE-REFERENCE as parsed data.
  2531. INFO is the plist used as a communication channel."
  2532. (let ((label (org-element-property :label footnote-reference)))
  2533. (or (org-element-property :inline-definition footnote-reference)
  2534. (cdr (assoc label (plist-get info :footnote-definition-alist))))))
  2535. (defun org-export-get-footnote-number (footnote info)
  2536. "Return number associated to a footnote.
  2537. FOOTNOTE is either a footnote reference or a footnote definition.
  2538. INFO is the plist used as a communication channel."
  2539. (let* ((label (org-element-property :label footnote))
  2540. seen-refs
  2541. search-ref ; for byte-compiler.
  2542. (search-ref
  2543. (function
  2544. (lambda (data)
  2545. ;; Search footnote references through DATA, filling
  2546. ;; SEEN-REFS along the way.
  2547. (org-element-map
  2548. data 'footnote-reference
  2549. (lambda (fn)
  2550. (let ((fn-lbl (org-element-property :label fn)))
  2551. (cond
  2552. ;; Anonymous footnote match: return number.
  2553. ((and (not fn-lbl) (eq fn footnote))
  2554. (throw 'exit (1+ (length seen-refs))))
  2555. ;; Labels match: return number.
  2556. ((and label (string= label fn-lbl))
  2557. (throw 'exit (1+ (length seen-refs))))
  2558. ;; Anonymous footnote: it's always a new one. Also,
  2559. ;; be sure to return nil from the `cond' so
  2560. ;; `first-match' doesn't get us out of the loop.
  2561. ((not fn-lbl) (push 'inline seen-refs) nil)
  2562. ;; Label not seen so far: add it so SEEN-REFS.
  2563. ;;
  2564. ;; Also search for subsequent references in footnote
  2565. ;; definition so numbering following reading logic.
  2566. ;; Note that we don't have to care about inline
  2567. ;; definitions, since `org-element-map' already
  2568. ;; traverse them at the right time.
  2569. ;;
  2570. ;; Once again, return nil to stay in the loop.
  2571. ((not (member fn-lbl seen-refs))
  2572. (push fn-lbl seen-refs)
  2573. (funcall search-ref
  2574. (org-export-get-footnote-definition fn info))
  2575. nil))))
  2576. ;; Don't enter footnote definitions since it will happen
  2577. ;; when their first reference is found.
  2578. info 'first-match 'footnote-definition)))))
  2579. (catch 'exit (funcall search-ref (plist-get info :parse-tree)))))
  2580. ;;;; For Headlines
  2581. ;;
  2582. ;; `org-export-get-relative-level' is a shortcut to get headline
  2583. ;; level, relatively to the lower headline level in the parsed tree.
  2584. ;;
  2585. ;; `org-export-get-headline-number' returns the section number of an
  2586. ;; headline, while `org-export-number-to-roman' allows to convert it
  2587. ;; to roman numbers.
  2588. ;;
  2589. ;; `org-export-low-level-p', `org-export-first-sibling-p' and
  2590. ;; `org-export-last-sibling-p' are three useful predicates when it
  2591. ;; comes to fulfill the `:headline-levels' property.
  2592. (defun org-export-get-relative-level (headline info)
  2593. "Return HEADLINE relative level within current parsed tree.
  2594. INFO is a plist holding contextual information."
  2595. (+ (org-element-property :level headline)
  2596. (or (plist-get info :headline-offset) 0)))
  2597. (defun org-export-low-level-p (headline info)
  2598. "Non-nil when HEADLINE is considered as low level.
  2599. INFO is a plist used as a communication channel.
  2600. A low level headlines has a relative level greater than
  2601. `:headline-levels' property value.
  2602. Return value is the difference between HEADLINE relative level
  2603. and the last level being considered as high enough, or nil."
  2604. (let ((limit (plist-get info :headline-levels)))
  2605. (when (wholenump limit)
  2606. (let ((level (org-export-get-relative-level headline info)))
  2607. (and (> level limit) (- level limit))))))
  2608. (defun org-export-get-headline-number (headline info)
  2609. "Return HEADLINE numbering as a list of numbers.
  2610. INFO is a plist holding contextual information."
  2611. (cdr (assoc headline (plist-get info :headline-numbering))))
  2612. (defun org-export-numbered-headline-p (headline info)
  2613. "Return a non-nil value if HEADLINE element should be numbered.
  2614. INFO is a plist used as a communication channel."
  2615. (let ((sec-num (plist-get info :section-numbers))
  2616. (level (org-export-get-relative-level headline info)))
  2617. (if (wholenump sec-num) (<= level sec-num) sec-num)))
  2618. (defun org-export-number-to-roman (n)
  2619. "Convert integer N into a roman numeral."
  2620. (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
  2621. ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
  2622. ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
  2623. ( 1 . "I")))
  2624. (res ""))
  2625. (if (<= n 0)
  2626. (number-to-string n)
  2627. (while roman
  2628. (if (>= n (caar roman))
  2629. (setq n (- n (caar roman))
  2630. res (concat res (cdar roman)))
  2631. (pop roman)))
  2632. res)))
  2633. (defun org-export-get-tags (element info &optional tags)
  2634. "Return list of tags associated to ELEMENT.
  2635. ELEMENT has either an `headline' or an `inlinetask' type. INFO
  2636. is a plist used as a communication channel.
  2637. Select tags (see `org-export-select-tags') and exclude tags (see
  2638. `org-export-exclude-tags') are removed from the list.
  2639. When non-nil, optional argument TAGS should be a list of strings.
  2640. Any tag belonging to this list will also be removed."
  2641. (org-remove-if (lambda (tag) (or (member tag (plist-get info :select-tags))
  2642. (member tag (plist-get info :exclude-tags))
  2643. (member tag tags)))
  2644. (org-element-property :tags element)))
  2645. (defun org-export-first-sibling-p (headline)
  2646. "Non-nil when HEADLINE is the first sibling in its sub-tree."
  2647. (not (eq (org-element-type (org-export-get-previous-element headline))
  2648. 'headline)))
  2649. (defun org-export-last-sibling-p (headline)
  2650. "Non-nil when HEADLINE is the last sibling in its sub-tree."
  2651. (not (org-export-get-next-element headline)))
  2652. ;;;; For Links
  2653. ;;
  2654. ;; `org-export-solidify-link-text' turns a string into a safer version
  2655. ;; for links, replacing most non-standard characters with hyphens.
  2656. ;;
  2657. ;; `org-export-get-coderef-format' returns an appropriate format
  2658. ;; string for coderefs.
  2659. ;;
  2660. ;; `org-export-inline-image-p' returns a non-nil value when the link
  2661. ;; provided should be considered as an inline image.
  2662. ;;
  2663. ;; `org-export-resolve-fuzzy-link' searches destination of fuzzy links
  2664. ;; (i.e. links with "fuzzy" as type) within the parsed tree, and
  2665. ;; returns an appropriate unique identifier when found, or nil.
  2666. ;;
  2667. ;; `org-export-resolve-id-link' returns the first headline with
  2668. ;; specified id or custom-id in parse tree, the path to the external
  2669. ;; file with the id or nil when neither was found.
  2670. ;;
  2671. ;; `org-export-resolve-coderef' associates a reference to a line
  2672. ;; number in the element it belongs, or returns the reference itself
  2673. ;; when the element isn't numbered.
  2674. (defun org-export-solidify-link-text (s)
  2675. "Take link text S and make a safe target out of it."
  2676. (save-match-data
  2677. (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-]+") "-")))
  2678. (defun org-export-get-coderef-format (path desc)
  2679. "Return format string for code reference link.
  2680. PATH is the link path. DESC is its description."
  2681. (save-match-data
  2682. (cond ((not desc) "%s")
  2683. ((string-match (regexp-quote (concat "(" path ")")) desc)
  2684. (replace-match "%s" t t desc))
  2685. (t desc))))
  2686. (defun org-export-inline-image-p (link &optional rules)
  2687. "Non-nil if LINK object points to an inline image.
  2688. Optional argument is a set of RULES defining inline images. It
  2689. is an alist where associations have the following shape:
  2690. \(TYPE . REGEXP)
  2691. Applying a rule means apply REGEXP against LINK's path when its
  2692. type is TYPE. The function will return a non-nil value if any of
  2693. the provided rules is non-nil. The default rule is
  2694. `org-export-default-inline-image-rule'.
  2695. This only applies to links without a description."
  2696. (and (not (org-element-contents link))
  2697. (let ((case-fold-search t)
  2698. (rules (or rules org-export-default-inline-image-rule)))
  2699. (catch 'exit
  2700. (mapc
  2701. (lambda (rule)
  2702. (and (string= (org-element-property :type link) (car rule))
  2703. (string-match (cdr rule)
  2704. (org-element-property :path link))
  2705. (throw 'exit t)))
  2706. rules)
  2707. ;; Return nil if no rule matched.
  2708. nil))))
  2709. (defun org-export-resolve-coderef (ref info)
  2710. "Resolve a code reference REF.
  2711. INFO is a plist used as a communication channel.
  2712. Return associated line number in source code, or REF itself,
  2713. depending on src-block or example element's switches."
  2714. (org-element-map
  2715. (plist-get info :parse-tree) '(example-block src-block)
  2716. (lambda (el)
  2717. (with-temp-buffer
  2718. (insert (org-trim (org-element-property :value el)))
  2719. (let* ((label-fmt (regexp-quote
  2720. (or (org-element-property :label-fmt el)
  2721. org-coderef-label-format)))
  2722. (ref-re
  2723. (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)\\)[ \t]*$"
  2724. (replace-regexp-in-string "%s" ref label-fmt nil t))))
  2725. ;; Element containing REF is found. Resolve it to either
  2726. ;; a label or a line number, as needed.
  2727. (when (re-search-backward ref-re nil t)
  2728. (cond
  2729. ((org-element-property :use-labels el) ref)
  2730. ((eq (org-element-property :number-lines el) 'continued)
  2731. (+ (org-export-get-loc el info) (line-number-at-pos)))
  2732. (t (line-number-at-pos)))))))
  2733. info 'first-match))
  2734. (defun org-export-resolve-fuzzy-link (link info)
  2735. "Return LINK destination.
  2736. INFO is a plist holding contextual information.
  2737. Return value can be an object, an element, or nil:
  2738. - If LINK path matches a target object (i.e. <<path>>) or
  2739. element (i.e. \"#+TARGET: path\"), return it.
  2740. - If LINK path exactly matches the name affiliated keyword
  2741. \(i.e. #+NAME: path) of an element, return that element.
  2742. - If LINK path exactly matches any headline name, return that
  2743. element. If more than one headline share that name, priority
  2744. will be given to the one with the closest common ancestor, if
  2745. any, or the first one in the parse tree otherwise.
  2746. - Otherwise, return nil.
  2747. Assume LINK type is \"fuzzy\"."
  2748. (let* ((path (org-element-property :path link))
  2749. (match-title-p (eq (aref path 0) ?*)))
  2750. (cond
  2751. ;; First try to find a matching "<<path>>" unless user specified
  2752. ;; he was looking for an headline (path starts with a *
  2753. ;; character).
  2754. ((and (not match-title-p)
  2755. (loop for target in (plist-get info :target-list)
  2756. when (string= (org-element-property :value target) path)
  2757. return target)))
  2758. ;; Then try to find an element with a matching "#+NAME: path"
  2759. ;; affiliated keyword.
  2760. ((and (not match-title-p)
  2761. (org-element-map
  2762. (plist-get info :parse-tree) org-element-all-elements
  2763. (lambda (el)
  2764. (when (string= (org-element-property :name el) path) el))
  2765. info 'first-match)))
  2766. ;; Last case: link either points to an headline or to
  2767. ;; nothingness. Try to find the source, with priority given to
  2768. ;; headlines with the closest common ancestor. If such candidate
  2769. ;; is found, return it, otherwise return nil.
  2770. (t
  2771. (let ((find-headline
  2772. (function
  2773. ;; Return first headline whose `:raw-value' property
  2774. ;; is NAME in parse tree DATA, or nil.
  2775. (lambda (name data)
  2776. (org-element-map
  2777. data 'headline
  2778. (lambda (headline)
  2779. (when (string=
  2780. (org-element-property :raw-value headline)
  2781. name)
  2782. headline))
  2783. info 'first-match)))))
  2784. ;; Search among headlines sharing an ancestor with link,
  2785. ;; from closest to farthest.
  2786. (or (catch 'exit
  2787. (mapc
  2788. (lambda (parent)
  2789. (when (eq (org-element-type parent) 'headline)
  2790. (let ((foundp (funcall find-headline path parent)))
  2791. (when foundp (throw 'exit foundp)))))
  2792. (org-export-get-genealogy link)) nil)
  2793. ;; No match with a common ancestor: try the full parse-tree.
  2794. (funcall find-headline
  2795. (if match-title-p (substring path 1) path)
  2796. (plist-get info :parse-tree))))))))
  2797. (defun org-export-resolve-id-link (link info)
  2798. "Return headline referenced as LINK destination.
  2799. INFO is a plist used as a communication channel.
  2800. Return value can be the headline element matched in current parse
  2801. tree, a file name or nil. Assume LINK type is either \"id\" or
  2802. \"custom-id\"."
  2803. (let ((id (org-element-property :path link)))
  2804. ;; First check if id is within the current parse tree.
  2805. (or (org-element-map
  2806. (plist-get info :parse-tree) 'headline
  2807. (lambda (headline)
  2808. (when (or (string= (org-element-property :id headline) id)
  2809. (string= (org-element-property :custom-id headline) id))
  2810. headline))
  2811. info 'first-match)
  2812. ;; Otherwise, look for external files.
  2813. (cdr (assoc id (plist-get info :id-alist))))))
  2814. (defun org-export-resolve-radio-link (link info)
  2815. "Return radio-target object referenced as LINK destination.
  2816. INFO is a plist used as a communication channel.
  2817. Return value can be a radio-target object or nil. Assume LINK
  2818. has type \"radio\"."
  2819. (let ((path (org-element-property :path link)))
  2820. (org-element-map
  2821. (plist-get info :parse-tree) 'radio-target
  2822. (lambda (radio)
  2823. (when (equal (org-element-property :value radio) path) radio))
  2824. info 'first-match)))
  2825. ;;;; For Macros
  2826. ;;
  2827. ;; `org-export-expand-macro' simply takes care of expanding macros.
  2828. (defun org-export-expand-macro (macro info)
  2829. "Expand MACRO and return it as a string.
  2830. INFO is a plist holding export options."
  2831. (let* ((key (org-element-property :key macro))
  2832. (args (org-element-property :args macro))
  2833. ;; User's macros are stored in the communication channel with
  2834. ;; a ":macro-" prefix. Replace arguments in VALUE. Also
  2835. ;; expand recursively macros within.
  2836. (value (org-export-data
  2837. (mapcar
  2838. (lambda (obj)
  2839. (if (not (stringp obj)) (org-export-data obj info)
  2840. (replace-regexp-in-string
  2841. "\\$[0-9]+"
  2842. (lambda (arg)
  2843. (nth (1- (string-to-number (substring arg 1))) args))
  2844. obj)))
  2845. (plist-get info (intern (format ":macro-%s" key))))
  2846. info)))
  2847. ;; VALUE starts with "(eval": it is a s-exp, `eval' it.
  2848. (when (string-match "\\`(eval\\>" value) (setq value (eval (read value))))
  2849. ;; Return string.
  2850. (format "%s" (or value ""))))
  2851. ;;;; For References
  2852. ;;
  2853. ;; `org-export-get-ordinal' associates a sequence number to any object
  2854. ;; or element.
  2855. (defun org-export-get-ordinal (element info &optional types predicate)
  2856. "Return ordinal number of an element or object.
  2857. ELEMENT is the element or object considered. INFO is the plist
  2858. used as a communication channel.
  2859. Optional argument TYPES, when non-nil, is a list of element or
  2860. object types, as symbols, that should also be counted in.
  2861. Otherwise, only provided element's type is considered.
  2862. Optional argument PREDICATE is a function returning a non-nil
  2863. value if the current element or object should be counted in. It
  2864. accepts two arguments: the element or object being considered and
  2865. the plist used as a communication channel. This allows to count
  2866. only a certain type of objects (i.e. inline images).
  2867. Return value is a list of numbers if ELEMENT is an headline or an
  2868. item. It is nil for keywords. It represents the footnote number
  2869. for footnote definitions and footnote references. If ELEMENT is
  2870. a target, return the same value as if ELEMENT was the closest
  2871. table, item or headline containing the target. In any other
  2872. case, return the sequence number of ELEMENT among elements or
  2873. objects of the same type."
  2874. ;; A target keyword, representing an invisible target, never has
  2875. ;; a sequence number.
  2876. (unless (eq (org-element-type element) 'keyword)
  2877. ;; Ordinal of a target object refer to the ordinal of the closest
  2878. ;; table, item, or headline containing the object.
  2879. (when (eq (org-element-type element) 'target)
  2880. (setq element
  2881. (loop for parent in (org-export-get-genealogy element)
  2882. when
  2883. (memq
  2884. (org-element-type parent)
  2885. '(footnote-definition footnote-reference headline item
  2886. table))
  2887. return parent)))
  2888. (case (org-element-type element)
  2889. ;; Special case 1: An headline returns its number as a list.
  2890. (headline (org-export-get-headline-number element info))
  2891. ;; Special case 2: An item returns its number as a list.
  2892. (item (let ((struct (org-element-property :structure element)))
  2893. (org-list-get-item-number
  2894. (org-element-property :begin element)
  2895. struct
  2896. (org-list-prevs-alist struct)
  2897. (org-list-parents-alist struct))))
  2898. ((footnote-definition footnote-reference)
  2899. (org-export-get-footnote-number element info))
  2900. (otherwise
  2901. (let ((counter 0))
  2902. ;; Increment counter until ELEMENT is found again.
  2903. (org-element-map
  2904. (plist-get info :parse-tree) (or types (org-element-type element))
  2905. (lambda (el)
  2906. (cond
  2907. ((eq element el) (1+ counter))
  2908. ((not predicate) (incf counter) nil)
  2909. ((funcall predicate el info) (incf counter) nil)))
  2910. info 'first-match))))))
  2911. ;;;; For Src-Blocks
  2912. ;;
  2913. ;; `org-export-get-loc' counts number of code lines accumulated in
  2914. ;; src-block or example-block elements with a "+n" switch until
  2915. ;; a given element, excluded. Note: "-n" switches reset that count.
  2916. ;;
  2917. ;; `org-export-unravel-code' extracts source code (along with a code
  2918. ;; references alist) from an `element-block' or `src-block' type
  2919. ;; element.
  2920. ;;
  2921. ;; `org-export-format-code' applies a formatting function to each line
  2922. ;; of code, providing relative line number and code reference when
  2923. ;; appropriate. Since it doesn't access the original element from
  2924. ;; which the source code is coming, it expects from the code calling
  2925. ;; it to know if lines should be numbered and if code references
  2926. ;; should appear.
  2927. ;;
  2928. ;; Eventually, `org-export-format-code-default' is a higher-level
  2929. ;; function (it makes use of the two previous functions) which handles
  2930. ;; line numbering and code references inclusion, and returns source
  2931. ;; code in a format suitable for plain text or verbatim output.
  2932. (defun org-export-get-loc (element info)
  2933. "Return accumulated lines of code up to ELEMENT.
  2934. INFO is the plist used as a communication channel.
  2935. ELEMENT is excluded from count."
  2936. (let ((loc 0))
  2937. (org-element-map
  2938. (plist-get info :parse-tree)
  2939. `(src-block example-block ,(org-element-type element))
  2940. (lambda (el)
  2941. (cond
  2942. ;; ELEMENT is reached: Quit the loop.
  2943. ((eq el element))
  2944. ;; Only count lines from src-block and example-block elements
  2945. ;; with a "+n" or "-n" switch. A "-n" switch resets counter.
  2946. ((not (memq (org-element-type el) '(src-block example-block))) nil)
  2947. ((let ((linums (org-element-property :number-lines el)))
  2948. (when linums
  2949. ;; Accumulate locs or reset them.
  2950. (let ((lines (org-count-lines
  2951. (org-trim (org-element-property :value el)))))
  2952. (setq loc (if (eq linums 'new) lines (+ loc lines))))))
  2953. ;; Return nil to stay in the loop.
  2954. nil)))
  2955. info 'first-match)
  2956. ;; Return value.
  2957. loc))
  2958. (defun org-export-unravel-code (element)
  2959. "Clean source code and extract references out of it.
  2960. ELEMENT has either a `src-block' an `example-block' type.
  2961. Return a cons cell whose CAR is the source code, cleaned from any
  2962. reference and protective comma and CDR is an alist between
  2963. relative line number (integer) and name of code reference on that
  2964. line (string)."
  2965. (let* ((line 0) refs
  2966. ;; Get code and clean it. Remove blank lines at its
  2967. ;; beginning and end. Also remove protective commas.
  2968. (code (let ((c (replace-regexp-in-string
  2969. "\\`\\([ \t]*\n\\)+" ""
  2970. (replace-regexp-in-string
  2971. "\\(:?[ \t]*\n\\)*[ \t]*\\'" "\n"
  2972. (org-element-property :value element)))))
  2973. ;; If appropriate, remove global indentation.
  2974. (unless (or org-src-preserve-indentation
  2975. (org-element-property :preserve-indent element))
  2976. (setq c (org-remove-indentation c)))
  2977. ;; Free up the protected lines. Note: Org blocks
  2978. ;; have commas at the beginning or every line.
  2979. (if (string= (org-element-property :language element) "org")
  2980. (replace-regexp-in-string "^," "" c)
  2981. (replace-regexp-in-string
  2982. "^\\(,\\)\\(:?\\*\\|[ \t]*#\\+\\)" "" c nil nil 1))))
  2983. ;; Get format used for references.
  2984. (label-fmt (regexp-quote
  2985. (or (org-element-property :label-fmt element)
  2986. org-coderef-label-format)))
  2987. ;; Build a regexp matching a loc with a reference.
  2988. (with-ref-re
  2989. (format "^.*?\\S-.*?\\([ \t]*\\(%s\\)[ \t]*\\)$"
  2990. (replace-regexp-in-string
  2991. "%s" "\\([-a-zA-Z0-9_ ]+\\)" label-fmt nil t))))
  2992. ;; Return value.
  2993. (cons
  2994. ;; Code with references removed.
  2995. (org-element-normalize-string
  2996. (mapconcat
  2997. (lambda (loc)
  2998. (incf line)
  2999. (if (not (string-match with-ref-re loc)) loc
  3000. ;; Ref line: remove ref, and signal its position in REFS.
  3001. (push (cons line (match-string 3 loc)) refs)
  3002. (replace-match "" nil nil loc 1)))
  3003. (org-split-string code "\n") "\n"))
  3004. ;; Reference alist.
  3005. refs)))
  3006. (defun org-export-format-code (code fun &optional num-lines ref-alist)
  3007. "Format CODE by applying FUN line-wise and return it.
  3008. CODE is a string representing the code to format. FUN is
  3009. a function. It must accept three arguments: a line of
  3010. code (string), the current line number (integer) or nil and the
  3011. reference associated to the current line (string) or nil.
  3012. Optional argument NUM-LINES can be an integer representing the
  3013. number of code lines accumulated until the current code. Line
  3014. numbers passed to FUN will take it into account. If it is nil,
  3015. FUN's second argument will always be nil. This number can be
  3016. obtained with `org-export-get-loc' function.
  3017. Optional argument REF-ALIST can be an alist between relative line
  3018. number (i.e. ignoring NUM-LINES) and the name of the code
  3019. reference on it. If it is nil, FUN's third argument will always
  3020. be nil. It can be obtained through the use of
  3021. `org-export-unravel-code' function."
  3022. (let ((--locs (org-split-string code "\n"))
  3023. (--line 0))
  3024. (org-element-normalize-string
  3025. (mapconcat
  3026. (lambda (--loc)
  3027. (incf --line)
  3028. (let ((--ref (cdr (assq --line ref-alist))))
  3029. (funcall fun --loc (and num-lines (+ num-lines --line)) --ref)))
  3030. --locs "\n"))))
  3031. (defun org-export-format-code-default (element info)
  3032. "Return source code from ELEMENT, formatted in a standard way.
  3033. ELEMENT is either a `src-block' or `example-block' element. INFO
  3034. is a plist used as a communication channel.
  3035. This function takes care of line numbering and code references
  3036. inclusion. Line numbers, when applicable, appear at the
  3037. beginning of the line, separated from the code by two white
  3038. spaces. Code references, on the other hand, appear flushed to
  3039. the right, separated by six white spaces from the widest line of
  3040. code."
  3041. ;; Extract code and references.
  3042. (let* ((code-info (org-export-unravel-code element))
  3043. (code (car code-info))
  3044. (code-lines (org-split-string code "\n"))
  3045. (refs (and (org-element-property :retain-labels element)
  3046. (cdr code-info)))
  3047. ;; Handle line numbering.
  3048. (num-start (case (org-element-property :number-lines element)
  3049. (continued (org-export-get-loc element info))
  3050. (new 0)))
  3051. (num-fmt
  3052. (and num-start
  3053. (format "%%%ds "
  3054. (length (number-to-string
  3055. (+ (length code-lines) num-start))))))
  3056. ;; Prepare references display, if required. Any reference
  3057. ;; should start six columns after the widest line of code,
  3058. ;; wrapped with parenthesis.
  3059. (max-width
  3060. (+ (apply 'max (mapcar 'length code-lines))
  3061. (if (not num-start) 0 (length (format num-fmt num-start))))))
  3062. (org-export-format-code
  3063. code
  3064. (lambda (loc line-num ref)
  3065. (let ((number-str (and num-fmt (format num-fmt line-num))))
  3066. (concat
  3067. number-str
  3068. loc
  3069. (and ref
  3070. (concat (make-string
  3071. (- (+ 6 max-width)
  3072. (+ (length loc) (length number-str))) ? )
  3073. (format "(%s)" ref))))))
  3074. num-start refs)))
  3075. ;;;; For Tables
  3076. ;;
  3077. ;; `org-export-table-has-special-column-p' and and
  3078. ;; `org-export-table-row-is-special-p' are predicates used to look for
  3079. ;; meta-information about the table structure.
  3080. ;;
  3081. ;; `org-table-has-header-p' tells when the rows before the first rule
  3082. ;; should be considered as table's header.
  3083. ;;
  3084. ;; `org-export-table-cell-width', `org-export-table-cell-alignment'
  3085. ;; and `org-export-table-cell-borders' extract information from
  3086. ;; a table-cell element.
  3087. ;;
  3088. ;; `org-export-table-dimensions' gives the number on rows and columns
  3089. ;; in the table, ignoring horizontal rules and special columns.
  3090. ;; `org-export-table-cell-address', given a table-cell object, returns
  3091. ;; the absolute address of a cell. On the other hand,
  3092. ;; `org-export-get-table-cell-at' does the contrary.
  3093. ;;
  3094. ;; `org-export-table-cell-starts-colgroup-p',
  3095. ;; `org-export-table-cell-ends-colgroup-p',
  3096. ;; `org-export-table-row-starts-rowgroup-p',
  3097. ;; `org-export-table-row-ends-rowgroup-p',
  3098. ;; `org-export-table-row-starts-header-p' and
  3099. ;; `org-export-table-row-ends-header-p' indicate position of current
  3100. ;; row or cell within the table.
  3101. (defun org-export-table-has-special-column-p (table)
  3102. "Non-nil when TABLE has a special column.
  3103. All special columns will be ignored during export."
  3104. ;; The table has a special column when every first cell of every row
  3105. ;; has an empty value or contains a symbol among "/", "#", "!", "$",
  3106. ;; "*" "_" and "^". Though, do not consider a first row containing
  3107. ;; only empty cells as special.
  3108. (let ((special-column-p 'empty))
  3109. (catch 'exit
  3110. (mapc
  3111. (lambda (row)
  3112. (when (eq (org-element-property :type row) 'standard)
  3113. (let ((value (org-element-contents
  3114. (car (org-element-contents row)))))
  3115. (cond ((member value '(("/") ("#") ("!") ("$") ("*") ("_") ("^")))
  3116. (setq special-column-p 'special))
  3117. ((not value))
  3118. (t (throw 'exit nil))))))
  3119. (org-element-contents table))
  3120. (eq special-column-p 'special))))
  3121. (defun org-export-table-has-header-p (table info)
  3122. "Non-nil when TABLE has an header.
  3123. INFO is a plist used as a communication channel.
  3124. A table has an header when it contains at least two row groups."
  3125. (let ((rowgroup 1) row-flag)
  3126. (org-element-map
  3127. table 'table-row
  3128. (lambda (row)
  3129. (cond
  3130. ((> rowgroup 1) t)
  3131. ((and row-flag (eq (org-element-property :type row) 'rule))
  3132. (incf rowgroup) (setq row-flag nil))
  3133. ((and (not row-flag) (eq (org-element-property :type row) 'standard))
  3134. (setq row-flag t) nil)))
  3135. info)))
  3136. (defun org-export-table-row-is-special-p (table-row info)
  3137. "Non-nil if TABLE-ROW is considered special.
  3138. INFO is a plist used as the communication channel.
  3139. All special rows will be ignored during export."
  3140. (when (eq (org-element-property :type table-row) 'standard)
  3141. (let ((first-cell (org-element-contents
  3142. (car (org-element-contents table-row)))))
  3143. ;; A row is special either when...
  3144. (or
  3145. ;; ... it starts with a field only containing "/",
  3146. (equal first-cell '("/"))
  3147. ;; ... the table contains a special column and the row start
  3148. ;; with a marking character among, "^", "_", "$" or "!",
  3149. (and (org-export-table-has-special-column-p
  3150. (org-export-get-parent table-row))
  3151. (member first-cell '(("^") ("_") ("$") ("!"))))
  3152. ;; ... it contains only alignment cookies and empty cells.
  3153. (let ((special-row-p 'empty))
  3154. (catch 'exit
  3155. (mapc
  3156. (lambda (cell)
  3157. (let ((value (org-element-contents cell)))
  3158. ;; Since VALUE is a secondary string, the following
  3159. ;; checks avoid expanding it with `org-export-data'.
  3160. (cond ((not value))
  3161. ((and (not (cdr value))
  3162. (stringp (car value))
  3163. (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
  3164. (car value)))
  3165. (setq special-row-p 'cookie))
  3166. (t (throw 'exit nil)))))
  3167. (org-element-contents table-row))
  3168. (eq special-row-p 'cookie)))))))
  3169. (defun org-export-table-row-group (table-row info)
  3170. "Return TABLE-ROW's group.
  3171. INFO is a plist used as the communication channel.
  3172. Return value is the group number, as an integer, or nil special
  3173. rows and table rules. Group 1 is also table's header."
  3174. (unless (or (eq (org-element-property :type table-row) 'rule)
  3175. (org-export-table-row-is-special-p table-row info))
  3176. (let ((group 0) row-flag)
  3177. (catch 'found
  3178. (mapc
  3179. (lambda (row)
  3180. (cond
  3181. ((and (eq (org-element-property :type row) 'standard)
  3182. (not (org-export-table-row-is-special-p row info)))
  3183. (unless row-flag (incf group) (setq row-flag t)))
  3184. ((eq (org-element-property :type row) 'rule)
  3185. (setq row-flag nil)))
  3186. (when (eq table-row row) (throw 'found group)))
  3187. (org-element-contents (org-export-get-parent table-row)))))))
  3188. (defun org-export-table-cell-width (table-cell info)
  3189. "Return TABLE-CELL contents width.
  3190. INFO is a plist used as the communication channel.
  3191. Return value is the width given by the last width cookie in the
  3192. same column as TABLE-CELL, or nil."
  3193. (let* ((row (org-export-get-parent table-cell))
  3194. (column (let ((cells (org-element-contents row)))
  3195. (- (length cells) (length (memq table-cell cells)))))
  3196. (table (org-export-get-parent-table table-cell))
  3197. cookie-width)
  3198. (mapc
  3199. (lambda (row)
  3200. (cond
  3201. ;; In a special row, try to find a width cookie at COLUMN.
  3202. ((org-export-table-row-is-special-p row info)
  3203. (let ((value (org-element-contents
  3204. (elt (org-element-contents row) column))))
  3205. ;; The following checks avoid expanding unnecessarily the
  3206. ;; cell with `org-export-data'
  3207. (when (and value
  3208. (not (cdr value))
  3209. (stringp (car value))
  3210. (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" (car value))
  3211. (match-string 1 (car value)))
  3212. (setq cookie-width
  3213. (string-to-number (match-string 1 (car value)))))))
  3214. ;; Ignore table rules.
  3215. ((eq (org-element-property :type row) 'rule))))
  3216. (org-element-contents table))
  3217. ;; Return value.
  3218. cookie-width))
  3219. (defun org-export-table-cell-alignment (table-cell info)
  3220. "Return TABLE-CELL contents alignment.
  3221. INFO is a plist used as the communication channel.
  3222. Return alignment as specified by the last alignment cookie in the
  3223. same column as TABLE-CELL. If no such cookie is found, a default
  3224. alignment value will be deduced from fraction of numbers in the
  3225. column (see `org-table-number-fraction' for more information).
  3226. Possible values are `left', `right' and `center'."
  3227. (let* ((row (org-export-get-parent table-cell))
  3228. (column (let ((cells (org-element-contents row)))
  3229. (- (length cells) (length (memq table-cell cells)))))
  3230. (table (org-export-get-parent-table table-cell))
  3231. (number-cells 0)
  3232. (total-cells 0)
  3233. cookie-align)
  3234. (mapc
  3235. (lambda (row)
  3236. (cond
  3237. ;; In a special row, try to find an alignment cookie at
  3238. ;; COLUMN.
  3239. ((org-export-table-row-is-special-p row info)
  3240. (let ((value (org-element-contents
  3241. (elt (org-element-contents row) column))))
  3242. ;; Since VALUE is a secondary string, the following checks
  3243. ;; avoid useless expansion through `org-export-data'.
  3244. (when (and value
  3245. (not (cdr value))
  3246. (stringp (car value))
  3247. (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
  3248. (car value))
  3249. (match-string 1 (car value)))
  3250. (setq cookie-align (match-string 1 (car value))))))
  3251. ;; Ignore table rules.
  3252. ((eq (org-element-property :type row) 'rule))
  3253. ;; In a standard row, check if cell's contents are expressing
  3254. ;; some kind of number. Increase NUMBER-CELLS accordingly.
  3255. ;; Though, don't bother if an alignment cookie has already
  3256. ;; defined cell's alignment.
  3257. ((not cookie-align)
  3258. (let ((value (org-export-data
  3259. (org-element-contents
  3260. (elt (org-element-contents row) column))
  3261. info)))
  3262. (incf total-cells)
  3263. (when (string-match org-table-number-regexp value)
  3264. (incf number-cells))))))
  3265. (org-element-contents table))
  3266. ;; Return value. Alignment specified by cookies has precedence
  3267. ;; over alignment deduced from cells contents.
  3268. (cond ((equal cookie-align "l") 'left)
  3269. ((equal cookie-align "r") 'right)
  3270. ((equal cookie-align "c") 'center)
  3271. ((>= (/ (float number-cells) total-cells) org-table-number-fraction)
  3272. 'right)
  3273. (t 'left))))
  3274. (defun org-export-table-cell-borders (table-cell info)
  3275. "Return TABLE-CELL borders.
  3276. INFO is a plist used as a communication channel.
  3277. Return value is a list of symbols, or nil. Possible values are:
  3278. `top', `bottom', `above', `below', `left' and `right'. Note:
  3279. `top' (resp. `bottom') only happen for a cell in the first
  3280. row (resp. last row) of the table, ignoring table rules, if any.
  3281. Returned borders ignore special rows."
  3282. (let* ((row (org-export-get-parent table-cell))
  3283. (table (org-export-get-parent-table table-cell))
  3284. borders)
  3285. ;; Top/above border? TABLE-CELL has a border above when a rule
  3286. ;; used to demarcate row groups can be found above. Hence,
  3287. ;; finding a rule isn't sufficient to push `above' in BORDERS:
  3288. ;; another regular row has to be found above that rule.
  3289. (let (rule-flag)
  3290. (catch 'exit
  3291. (mapc (lambda (row)
  3292. (cond ((eq (org-element-property :type row) 'rule)
  3293. (setq rule-flag t))
  3294. ((not (org-export-table-row-is-special-p row info))
  3295. (if rule-flag (throw 'exit (push 'above borders))
  3296. (throw 'exit nil)))))
  3297. ;; Look at every row before the current one.
  3298. (cdr (memq row (reverse (org-element-contents table)))))
  3299. ;; No rule above, or rule found starts the table (ignoring any
  3300. ;; special row): TABLE-CELL is at the top of the table.
  3301. (when rule-flag (push 'above borders))
  3302. (push 'top borders)))
  3303. ;; Bottom/below border? TABLE-CELL has a border below when next
  3304. ;; non-regular row below is a rule.
  3305. (let (rule-flag)
  3306. (catch 'exit
  3307. (mapc (lambda (row)
  3308. (cond ((eq (org-element-property :type row) 'rule)
  3309. (setq rule-flag t))
  3310. ((not (org-export-table-row-is-special-p row info))
  3311. (if rule-flag (throw 'exit (push 'below borders))
  3312. (throw 'exit nil)))))
  3313. ;; Look at every row after the current one.
  3314. (cdr (memq row (org-element-contents table))))
  3315. ;; No rule below, or rule found ends the table (modulo some
  3316. ;; special row): TABLE-CELL is at the bottom of the table.
  3317. (when rule-flag (push 'below borders))
  3318. (push 'bottom borders)))
  3319. ;; Right/left borders? They can only be specified by column
  3320. ;; groups. Column groups are defined in a row starting with "/".
  3321. ;; Also a column groups row only contains "<", "<>", ">" or blank
  3322. ;; cells.
  3323. (catch 'exit
  3324. (let ((column (let ((cells (org-element-contents row)))
  3325. (- (length cells) (length (memq table-cell cells))))))
  3326. (mapc
  3327. (lambda (row)
  3328. (unless (eq (org-element-property :type row) 'rule)
  3329. (when (equal (org-element-contents
  3330. (car (org-element-contents row)))
  3331. '("/"))
  3332. (let ((column-groups
  3333. (mapcar
  3334. (lambda (cell)
  3335. (let ((value (org-element-contents cell)))
  3336. (when (member value '(("<") ("<>") (">") nil))
  3337. (car value))))
  3338. (org-element-contents row))))
  3339. ;; There's a left border when previous cell, if
  3340. ;; any, ends a group, or current one starts one.
  3341. (when (or (and (not (zerop column))
  3342. (member (elt column-groups (1- column))
  3343. '(">" "<>")))
  3344. (member (elt column-groups column) '("<" "<>")))
  3345. (push 'left borders))
  3346. ;; There's a right border when next cell, if any,
  3347. ;; starts a group, or current one ends one.
  3348. (when (or (and (/= (1+ column) (length column-groups))
  3349. (member (elt column-groups (1+ column))
  3350. '("<" "<>")))
  3351. (member (elt column-groups column) '(">" "<>")))
  3352. (push 'right borders))
  3353. (throw 'exit nil)))))
  3354. ;; Table rows are read in reverse order so last column groups
  3355. ;; row has precedence over any previous one.
  3356. (reverse (org-element-contents table)))))
  3357. ;; Return value.
  3358. borders))
  3359. (defun org-export-table-cell-starts-colgroup-p (table-cell info)
  3360. "Non-nil when TABLE-CELL is at the beginning of a row group.
  3361. INFO is a plist used as a communication channel."
  3362. ;; A cell starts a column group either when it is at the beginning
  3363. ;; of a row (or after the special column, if any) or when it has
  3364. ;; a left border.
  3365. (or (eq (org-element-map
  3366. (org-export-get-parent table-cell)
  3367. 'table-cell 'identity info 'first-match)
  3368. table-cell)
  3369. (memq 'left (org-export-table-cell-borders table-cell info))))
  3370. (defun org-export-table-cell-ends-colgroup-p (table-cell info)
  3371. "Non-nil when TABLE-CELL is at the end of a row group.
  3372. INFO is a plist used as a communication channel."
  3373. ;; A cell ends a column group either when it is at the end of a row
  3374. ;; or when it has a right border.
  3375. (or (eq (car (last (org-element-contents
  3376. (org-export-get-parent table-cell))))
  3377. table-cell)
  3378. (memq 'right (org-export-table-cell-borders table-cell info))))
  3379. (defun org-export-table-row-starts-rowgroup-p (table-row info)
  3380. "Non-nil when TABLE-ROW is at the beginning of a column group.
  3381. INFO is a plist used as a communication channel."
  3382. (unless (or (eq (org-element-property :type table-row) 'rule)
  3383. (org-export-table-row-is-special-p table-row info))
  3384. (let ((borders (org-export-table-cell-borders
  3385. (car (org-element-contents table-row)) info)))
  3386. (or (memq 'top borders) (memq 'above borders)))))
  3387. (defun org-export-table-row-ends-rowgroup-p (table-row info)
  3388. "Non-nil when TABLE-ROW is at the end of a column group.
  3389. INFO is a plist used as a communication channel."
  3390. (unless (or (eq (org-element-property :type table-row) 'rule)
  3391. (org-export-table-row-is-special-p table-row info))
  3392. (let ((borders (org-export-table-cell-borders
  3393. (car (org-element-contents table-row)) info)))
  3394. (or (memq 'bottom borders) (memq 'below borders)))))
  3395. (defun org-export-table-row-starts-header-p (table-row info)
  3396. "Non-nil when TABLE-ROW is the first table header's row.
  3397. INFO is a plist used as a communication channel."
  3398. (and (org-export-table-has-header-p
  3399. (org-export-get-parent-table table-row) info)
  3400. (org-export-table-row-starts-rowgroup-p table-row info)
  3401. (= (org-export-table-row-group table-row info) 1)))
  3402. (defun org-export-table-row-ends-header-p (table-row info)
  3403. "Non-nil when TABLE-ROW is the last table header's row.
  3404. INFO is a plist used as a communication channel."
  3405. (and (org-export-table-has-header-p
  3406. (org-export-get-parent-table table-row) info)
  3407. (org-export-table-row-ends-rowgroup-p table-row info)
  3408. (= (org-export-table-row-group table-row info) 1)))
  3409. (defun org-export-table-dimensions (table info)
  3410. "Return TABLE dimensions.
  3411. INFO is a plist used as a communication channel.
  3412. Return value is a CONS like (ROWS . COLUMNS) where
  3413. ROWS (resp. COLUMNS) is the number of exportable
  3414. rows (resp. columns)."
  3415. (let (first-row (columns 0) (rows 0))
  3416. ;; Set number of rows, and extract first one.
  3417. (org-element-map
  3418. table 'table-row
  3419. (lambda (row)
  3420. (when (eq (org-element-property :type row) 'standard)
  3421. (incf rows)
  3422. (unless first-row (setq first-row row)))) info)
  3423. ;; Set number of columns.
  3424. (org-element-map first-row 'table-cell (lambda (cell) (incf columns)) info)
  3425. ;; Return value.
  3426. (cons rows columns)))
  3427. (defun org-export-table-cell-address (table-cell info)
  3428. "Return address of a regular TABLE-CELL object.
  3429. TABLE-CELL is the cell considered. INFO is a plist used as
  3430. a communication channel.
  3431. Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
  3432. zero-based index. Only exportable cells are considered. The
  3433. function returns nil for other cells."
  3434. (let* ((table-row (org-export-get-parent table-cell))
  3435. (table (org-export-get-parent-table table-cell)))
  3436. ;; Ignore cells in special rows or in special column.
  3437. (unless (or (org-export-table-row-is-special-p table-row info)
  3438. (and (org-export-table-has-special-column-p table)
  3439. (eq (car (org-element-contents table-row)) table-cell)))
  3440. (cons
  3441. ;; Row number.
  3442. (let ((row-count 0))
  3443. (org-element-map
  3444. table 'table-row
  3445. (lambda (row)
  3446. (cond ((eq (org-element-property :type row) 'rule) nil)
  3447. ((eq row table-row) row-count)
  3448. (t (incf row-count) nil)))
  3449. info 'first-match))
  3450. ;; Column number.
  3451. (let ((col-count 0))
  3452. (org-element-map
  3453. table-row 'table-cell
  3454. (lambda (cell)
  3455. (if (eq cell table-cell) col-count (incf col-count) nil))
  3456. info 'first-match))))))
  3457. (defun org-export-get-table-cell-at (address table info)
  3458. "Return regular table-cell object at ADDRESS in TABLE.
  3459. Address is a CONS cell (ROW . COLUMN), where ROW and COLUMN are
  3460. zero-based index. TABLE is a table type element. INFO is
  3461. a plist used as a communication channel.
  3462. If no table-cell, among exportable cells, is found at ADDRESS,
  3463. return nil."
  3464. (let ((column-pos (cdr address)) (column-count 0))
  3465. (org-element-map
  3466. ;; Row at (car address) or nil.
  3467. (let ((row-pos (car address)) (row-count 0))
  3468. (org-element-map
  3469. table 'table-row
  3470. (lambda (row)
  3471. (cond ((eq (org-element-property :type row) 'rule) nil)
  3472. ((= row-count row-pos) row)
  3473. (t (incf row-count) nil)))
  3474. info 'first-match))
  3475. 'table-cell
  3476. (lambda (cell)
  3477. (if (= column-count column-pos) cell
  3478. (incf column-count) nil))
  3479. info 'first-match)))
  3480. ;;;; For Tables Of Contents
  3481. ;;
  3482. ;; `org-export-collect-headlines' builds a list of all exportable
  3483. ;; headline elements, maybe limited to a certain depth. One can then
  3484. ;; easily parse it and transcode it.
  3485. ;;
  3486. ;; Building lists of tables, figures or listings is quite similar.
  3487. ;; Once the generic function `org-export-collect-elements' is defined,
  3488. ;; `org-export-collect-tables', `org-export-collect-figures' and
  3489. ;; `org-export-collect-listings' can be derived from it.
  3490. (defun org-export-collect-headlines (info &optional n)
  3491. "Collect headlines in order to build a table of contents.
  3492. INFO is a plist used as a communication channel.
  3493. When non-nil, optional argument N must be an integer. It
  3494. specifies the depth of the table of contents.
  3495. Return a list of all exportable headlines as parsed elements."
  3496. (org-element-map
  3497. (plist-get info :parse-tree)
  3498. 'headline
  3499. (lambda (headline)
  3500. ;; Strip contents from HEADLINE.
  3501. (let ((relative-level (org-export-get-relative-level headline info)))
  3502. (unless (and n (> relative-level n)) headline)))
  3503. info))
  3504. (defun org-export-collect-elements (type info &optional predicate)
  3505. "Collect referenceable elements of a determined type.
  3506. TYPE can be a symbol or a list of symbols specifying element
  3507. types to search. Only elements with a caption are collected.
  3508. INFO is a plist used as a communication channel.
  3509. When non-nil, optional argument PREDICATE is a function accepting
  3510. one argument, an element of type TYPE. It returns a non-nil
  3511. value when that element should be collected.
  3512. Return a list of all elements found, in order of appearance."
  3513. (org-element-map
  3514. (plist-get info :parse-tree) type
  3515. (lambda (element)
  3516. (and (org-element-property :caption element)
  3517. (or (not predicate) (funcall predicate element))
  3518. element))
  3519. info))
  3520. (defun org-export-collect-tables (info)
  3521. "Build a list of tables.
  3522. INFO is a plist used as a communication channel.
  3523. Return a list of table elements with a caption."
  3524. (org-export-collect-elements 'table info))
  3525. (defun org-export-collect-figures (info predicate)
  3526. "Build a list of figures.
  3527. INFO is a plist used as a communication channel. PREDICATE is
  3528. a function which accepts one argument: a paragraph element and
  3529. whose return value is non-nil when that element should be
  3530. collected.
  3531. A figure is a paragraph type element, with a caption, verifying
  3532. PREDICATE. The latter has to be provided since a \"figure\" is
  3533. a vague concept that may depend on back-end.
  3534. Return a list of elements recognized as figures."
  3535. (org-export-collect-elements 'paragraph info predicate))
  3536. (defun org-export-collect-listings (info)
  3537. "Build a list of src blocks.
  3538. INFO is a plist used as a communication channel.
  3539. Return a list of src-block elements with a caption."
  3540. (org-export-collect-elements 'src-block info))
  3541. ;;;; Topology
  3542. ;;
  3543. ;; Here are various functions to retrieve information about the
  3544. ;; neighbourhood of a given element or object. Neighbours of interest
  3545. ;; are direct parent (`org-export-get-parent'), parent headline
  3546. ;; (`org-export-get-parent-headline'), first element containing an
  3547. ;; object, (`org-export-get-parent-element'), parent table
  3548. ;; (`org-export-get-parent-table'), previous element or object
  3549. ;; (`org-export-get-previous-element') and next element or object
  3550. ;; (`org-export-get-next-element').
  3551. ;;
  3552. ;; `org-export-get-genealogy' returns the full genealogy of a given
  3553. ;; element or object, from closest parent to full parse tree.
  3554. (defun org-export-get-parent (blob)
  3555. "Return BLOB parent or nil.
  3556. BLOB is the element or object considered."
  3557. (org-element-property :parent blob))
  3558. (defun org-export-get-genealogy (blob)
  3559. "Return full genealogy relative to a given element or object.
  3560. BLOB is the element or object being considered.
  3561. Ancestors are returned from closest to farthest, the last one
  3562. being the full parse tree."
  3563. (let (genealogy (parent blob))
  3564. (while (setq parent (org-element-property :parent parent))
  3565. (push parent genealogy))
  3566. (nreverse genealogy)))
  3567. (defun org-export-get-parent-headline (blob)
  3568. "Return BLOB parent headline or nil.
  3569. BLOB is the element or object being considered."
  3570. (let ((parent blob))
  3571. (while (and (setq parent (org-element-property :parent parent))
  3572. (not (eq (org-element-type parent) 'headline))))
  3573. parent))
  3574. (defun org-export-get-parent-element (object)
  3575. "Return first element containing OBJECT or nil.
  3576. OBJECT is the object to consider."
  3577. (let ((parent object))
  3578. (while (and (setq parent (org-element-property :parent parent))
  3579. (memq (org-element-type parent) org-element-all-objects)))
  3580. parent))
  3581. (defun org-export-get-parent-table (object)
  3582. "Return OBJECT parent table or nil.
  3583. OBJECT is either a `table-cell' or `table-element' type object."
  3584. (let ((parent object))
  3585. (while (and (setq parent (org-element-property :parent parent))
  3586. (not (eq (org-element-type parent) 'table))))
  3587. parent))
  3588. (defun org-export-get-previous-element (blob)
  3589. "Return previous element or object.
  3590. BLOB is an element or object. Return previous element or object,
  3591. a string, or nil."
  3592. (let ((parent (org-export-get-parent blob)))
  3593. (cadr (memq blob (reverse (org-element-contents parent))))))
  3594. (defun org-export-get-next-element (blob)
  3595. "Return next element or object.
  3596. BLOB is an element or object. Return next element or object,
  3597. a string, or nil."
  3598. (let ((parent (org-export-get-parent blob)))
  3599. (cadr (memq blob (org-element-contents parent)))))
  3600. ;;;; Translation
  3601. ;;
  3602. ;; `org-export-translate' translates a string according to language
  3603. ;; specified by LANGUAGE keyword or `org-export-language-setup'
  3604. ;; variable and a specified charset. `org-export-dictionary' contains
  3605. ;; the dictionary used for the translation.
  3606. (defconst org-export-dictionary
  3607. '(("Author"
  3608. ("fr"
  3609. :ascii "Auteur"
  3610. :latin1 "Auteur"
  3611. :utf-8 "Auteur"))
  3612. ("Date"
  3613. ("fr"
  3614. :ascii "Date"
  3615. :latin1 "Date"
  3616. :utf-8 "Date"))
  3617. ("Equation")
  3618. ("Figure")
  3619. ("Footnotes"
  3620. ("fr"
  3621. :ascii "Notes de bas de page"
  3622. :latin1 "Notes de bas de page"
  3623. :utf-8 "Notes de bas de page"))
  3624. ("List of Listings"
  3625. ("fr"
  3626. :ascii "Liste des programmes"
  3627. :latin1 "Liste des programmes"
  3628. :utf-8 "Liste des programmes"))
  3629. ("List of Tables"
  3630. ("fr"
  3631. :ascii "Liste des tableaux"
  3632. :latin1 "Liste des tableaux"
  3633. :utf-8 "Liste des tableaux"))
  3634. ("Listing %d:"
  3635. ("fr"
  3636. :ascii "Programme %d :"
  3637. :latin1 "Programme %d :"
  3638. :utf-8 "Programme nº %d :"))
  3639. ("Listing %d: %s"
  3640. ("fr"
  3641. :ascii "Programme %d : %s"
  3642. :latin1 "Programme %d : %s"
  3643. :utf-8 "Programme nº %d : %s"))
  3644. ("See section %s"
  3645. ("fr"
  3646. :ascii "cf. section %s"
  3647. :latin1 "cf. section %s"
  3648. :utf-8 "cf. section %s"))
  3649. ("Table %d:"
  3650. ("fr"
  3651. :ascii "Tableau %d :"
  3652. :latin1 "Tableau %d :"
  3653. :utf-8 "Tableau nº %d :"))
  3654. ("Table %d: %s"
  3655. ("fr"
  3656. :ascii "Tableau %d : %s"
  3657. :latin1 "Tableau %d : %s"
  3658. :utf-8 "Tableau nº %d : %s"))
  3659. ("Table of Contents"
  3660. ("fr"
  3661. :ascii "Sommaire"
  3662. :latin1 "Table des matières"
  3663. :utf-8 "Table des matières"))
  3664. ("Unknown reference"
  3665. ("fr"
  3666. :ascii "Destination inconnue"
  3667. :latin1 "Référence inconnue"
  3668. :utf-8 "Référence inconnue")))
  3669. "Dictionary for export engine.
  3670. Alist whose CAR is the string to translate and CDR is an alist
  3671. whose CAR is the language string and CDR is a plist whose
  3672. properties are possible charsets and values translated terms.
  3673. It is used as a database for `org-export-translate'. Since this
  3674. function returns the string as-is if no translation was found,
  3675. the variable only needs to record values different from the
  3676. entry.")
  3677. (defun org-export-translate (s encoding info)
  3678. "Translate string S according to language specification.
  3679. ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
  3680. and `:utf8'. INFO is a plist used as a communication channel.
  3681. Translation depends on `:language' property. Return the
  3682. translated string. If no translation is found return S."
  3683. (let ((lang (plist-get info :language))
  3684. (translations (cdr (assoc s org-export-dictionary))))
  3685. (or (plist-get (cdr (assoc lang translations)) encoding) s)))
  3686. ;;; The Dispatcher
  3687. ;;
  3688. ;; `org-export-dispatch' is the standard interactive way to start an
  3689. ;; export process. It uses `org-export-dispatch-ui' as a subroutine
  3690. ;; for its interface. Most commons back-ends should have an entry in
  3691. ;; it.
  3692. (defun org-export-dispatch ()
  3693. "Export dispatcher for Org mode.
  3694. It provides an access to common export related tasks in a buffer.
  3695. Its interface comes in two flavours: standard and expert. While
  3696. both share the same set of bindings, only the former displays the
  3697. valid keys associations. Set `org-export-dispatch-use-expert-ui'
  3698. to switch to one or the other.
  3699. Return an error if key pressed has no associated command."
  3700. (interactive)
  3701. (let* ((input (org-export-dispatch-ui
  3702. (if (listp org-export-initial-scope) org-export-initial-scope
  3703. (list org-export-initial-scope))
  3704. org-export-dispatch-use-expert-ui))
  3705. (raw-key (car input))
  3706. (optns (cdr input)))
  3707. ;; Translate "C-a", "C-b"... into "a", "b"... Then take action
  3708. ;; depending on user's key pressed.
  3709. (case (if (< raw-key 27) (+ raw-key 96) raw-key)
  3710. ;; Allow to quit with "q" key.
  3711. (?q nil)
  3712. ;; Export with `e-ascii' back-end.
  3713. ((?A ?N ?U)
  3714. (org-e-ascii-export-as-ascii
  3715. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)
  3716. `(:ascii-charset ,(case raw-key (?A 'ascii) (?N 'latin1) (t 'utf-8)))))
  3717. ((?a ?n ?u)
  3718. (org-e-ascii-export-to-ascii
  3719. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)
  3720. `(:ascii-charset ,(case raw-key (?a 'ascii) (?n 'latin1) (t 'utf-8)))))
  3721. ;; Export with `e-latex' back-end.
  3722. (?L (org-e-latex-export-as-latex
  3723. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  3724. (?l
  3725. (org-e-latex-export-to-latex
  3726. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  3727. (?p
  3728. (org-e-latex-export-to-pdf
  3729. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  3730. (?d
  3731. (org-open-file
  3732. (org-e-latex-export-to-pdf
  3733. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns))))
  3734. ;; Export with `e-html' back-end.
  3735. (?H
  3736. (org-e-html-export-as-html
  3737. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  3738. (?h
  3739. (org-e-html-export-to-html
  3740. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  3741. (?b
  3742. (org-open-file
  3743. (org-e-html-export-to-html
  3744. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns))))
  3745. ;; Export with `e-odt' back-end.
  3746. (?o
  3747. (org-e-odt-export-to-odt
  3748. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns)))
  3749. (?O
  3750. (org-open-file
  3751. (org-e-odt-export-to-odt
  3752. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns))))
  3753. ;; Publishing facilities
  3754. (?F
  3755. (org-e-publish-current-file (memq 'force optns)))
  3756. (?P
  3757. (org-e-publish-current-project (memq 'force optns)))
  3758. (?X
  3759. (let ((project
  3760. (assoc (org-icompleting-read
  3761. "Publish project: " org-e-publish-project-alist nil t)
  3762. org-e-publish-project-alist)))
  3763. (org-e-publish project (memq 'force optns))))
  3764. (?E
  3765. (org-e-publish-all (memq 'force optns)))
  3766. ;; Undefined command.
  3767. (t (error "No command associated with key %s"
  3768. (char-to-string raw-key))))))
  3769. (defun org-export-dispatch-ui (options expertp)
  3770. "Handle interface for `org-export-dispatch'.
  3771. OPTIONS is a list containing current interactive options set for
  3772. export. It can contain any of the following symbols:
  3773. `body' toggles a body-only export
  3774. `subtree' restricts export to current subtree
  3775. `visible' restricts export to visible part of buffer.
  3776. `force' force publishing files.
  3777. EXPERTP, when non-nil, triggers expert UI. In that case, no help
  3778. buffer is provided, but indications about currently active
  3779. options are given in the prompt. Moreover, \[?] allows to switch
  3780. back to standard interface.
  3781. Return value is a list with key pressed as CAR and a list of
  3782. final interactive export options as CDR."
  3783. (let ((help
  3784. (format "---- (Options) -------------------------------------------
  3785. \[1] Body only: %s [2] Export scope: %s
  3786. \[3] Visible only: %s [4] Force publishing: %s
  3787. --- (ASCII/Latin-1/UTF-8 Export) -------------------------
  3788. \[a/n/u] to TXT file [A/N/U] to temporary buffer
  3789. --- (HTML Export) ----------------------------------------
  3790. \[h] to HTML file [b] ... and open it
  3791. \[H] to temporary buffer
  3792. --- (LaTeX Export) ---------------------------------------
  3793. \[l] to TEX file [L] to temporary buffer
  3794. \[p] to PDF file [d] ... and open it
  3795. --- (ODF Export) -----------------------------------------
  3796. \[o] to ODT file [O] ... and open it
  3797. --- (Publish) --------------------------------------------
  3798. \[F] current file [P] current project
  3799. \[X] a project [E] every project"
  3800. (if (memq 'body options) "On " "Off")
  3801. (if (memq 'subtree options) "Subtree" "Buffer ")
  3802. (if (memq 'visible options) "On " "Off")
  3803. (if (memq 'force options) "On " "Off")))
  3804. (standard-prompt "Export command: ")
  3805. (expert-prompt (format "Export command (%s%s%s%s): "
  3806. (if (memq 'body options) "b" "-")
  3807. (if (memq 'subtree options) "s" "-")
  3808. (if (memq 'visible options) "v" "-")
  3809. (if (memq 'force options) "f" "-")))
  3810. (handle-keypress
  3811. (function
  3812. ;; Read a character from command input, toggling interactive
  3813. ;; options when applicable. PROMPT is the displayed prompt,
  3814. ;; as a string.
  3815. (lambda (prompt)
  3816. (let ((key (read-char-exclusive prompt)))
  3817. (cond
  3818. ;; Ignore non-standard characters (i.e. "M-a").
  3819. ((not (characterp key)) (org-export-dispatch-ui options expertp))
  3820. ;; Help key: Switch back to standard interface if
  3821. ;; expert UI was active.
  3822. ((eq key ??) (org-export-dispatch-ui options nil))
  3823. ;; Toggle export options.
  3824. ((memq key '(?1 ?2 ?3 ?4))
  3825. (org-export-dispatch-ui
  3826. (let ((option (case key (?1 'body) (?2 'subtree) (?3 'visible)
  3827. (?4 'force))))
  3828. (if (memq option options) (remq option options)
  3829. (cons option options)))
  3830. expertp))
  3831. ;; Action selected: Send key and options back to
  3832. ;; `org-export-dispatch'.
  3833. (t (cons key options))))))))
  3834. ;; With expert UI, just read key with a fancy prompt. In standard
  3835. ;; UI, display an intrusive help buffer.
  3836. (if expertp (funcall handle-keypress expert-prompt)
  3837. (save-window-excursion
  3838. (delete-other-windows)
  3839. (with-output-to-temp-buffer "*Org Export/Publishing Help*" (princ help))
  3840. (org-fit-window-to-buffer
  3841. (get-buffer-window "*Org Export/Publishing Help*"))
  3842. (funcall handle-keypress standard-prompt)))))
  3843. (provide 'org-export)
  3844. ;;; org-export.el ends here