org-exp.el 125 KB

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