org-export.el 105 KB

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