org-exp.el 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  1. ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 6.27trans
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. (require 'org)
  25. (require 'org-agenda)
  26. (require 'org-exp-blocks)
  27. (eval-and-compile
  28. (require 'cl))
  29. (declare-function org-export-latex-preprocess "org-latex" (parameters))
  30. (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
  31. (declare-function org-export-html-preprocess "org-html" (parameters))
  32. (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
  33. (declare-function org-agenda-skip "org-agenda" ())
  34. (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
  35. (declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
  36. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  37. (defgroup org-export nil
  38. "Options for exporting org-listings."
  39. :tag "Org Export"
  40. :group 'org)
  41. (defgroup org-export-general nil
  42. "General options for exporting Org-mode files."
  43. :tag "Org Export General"
  44. :group 'org-export)
  45. ;; FIXME
  46. (defvar org-export-publishing-directory nil)
  47. (defcustom org-export-show-temporary-export-buffer t
  48. "Non-nil means, show buffer after exporting to temp buffer.
  49. When Org exports to a file, the buffer visiting that file is ever
  50. shown, but remains buried. However, when exporting to a temporary
  51. buffer, that buffer is popped up in a second window. When this variable
  52. is nil, the buffer remains buried also in these cases."
  53. :group 'org-export-general
  54. :type 'boolean)
  55. (defcustom org-export-copy-to-kill-ring t
  56. "Non-nil means, exported stuff will also be pushed onto the kill ring."
  57. :group 'org-export-general
  58. :type 'boolean)
  59. (defcustom org-export-run-in-background nil
  60. "Non-nil means export and publishing commands will run in background.
  61. This works by starting up a separate Emacs process visiting the same file
  62. and doing the export from there.
  63. Not all export commands are affected by this - only the ones which
  64. actually write to a file, and that do not depend on the buffer state.
  65. If this option is nil, you can still get background export by calling
  66. `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
  67. If this option is t, the double prefix can be used to exceptionally
  68. force an export command into the current process."
  69. :group 'org-export-general
  70. :type 'boolean)
  71. (defcustom org-export-select-tags '("export")
  72. "Tags that select a tree for export.
  73. If any such tag is found in a buffer, all trees that do not carry one
  74. of these tags will be deleted before export.
  75. Inside trees that are selected like this, you can still deselect a
  76. subtree by tagging it with one of the `org-export-exclude-tags'."
  77. :group 'org-export-general
  78. :type '(repeat (string :tag "Tag")))
  79. (defcustom org-export-exclude-tags '("noexport")
  80. "Tags that exclude a tree from export.
  81. All trees carrying any of these tags will be excluded from export.
  82. This is without condition, so even subtrees inside that carry one of the
  83. `org-export-select-tags' will be removed."
  84. :group 'org-export-general
  85. :type '(repeat (string :tag "Tag")))
  86. ;; FIXME: rename, this is a general variable
  87. (defcustom org-export-html-expand t
  88. "Non-nil means, for HTML export, treat @<...> as HTML tag.
  89. When nil, these tags will be exported as plain text and therefore
  90. not be interpreted by a browser.
  91. This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
  92. :group 'org-export-html
  93. :group 'org-export-general
  94. :type 'boolean)
  95. (defcustom org-export-with-special-strings t
  96. "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
  97. When this option is turned on, these strings will be exported as:
  98. Org HTML LaTeX
  99. -----+----------+--------
  100. \\- &shy; \\-
  101. -- &ndash; --
  102. --- &mdash; ---
  103. ... &hellip; \ldots
  104. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
  105. :group 'org-export-translation
  106. :type 'boolean)
  107. (defcustom org-export-html-link-up ""
  108. "Where should the \"UP\" link of exported HTML pages lead?"
  109. :group 'org-export-html
  110. :group 'org-export-general
  111. :type '(string :tag "File or URL"))
  112. (defcustom org-export-html-link-home ""
  113. "Where should the \"HOME\" link of exported HTML pages lead?"
  114. :group 'org-export-html
  115. :group 'org-export-general
  116. :type '(string :tag "File or URL"))
  117. (defcustom org-export-language-setup
  118. '(("en" "Author" "Date" "Table of Contents" "Footnotes")
  119. ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
  120. ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
  121. ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
  122. ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
  123. ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
  124. ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
  125. ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
  126. ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
  127. ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
  128. ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
  129. ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
  130. ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
  131. ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
  132. ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
  133. ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
  134. ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
  135. ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
  136. "Terms used in export text, translated to different languages.
  137. Use the variable `org-export-default-language' to set the language,
  138. or use the +OPTION lines for a per-file setting."
  139. :group 'org-export-general
  140. :type '(repeat
  141. (list
  142. (string :tag "HTML language tag")
  143. (string :tag "Author")
  144. (string :tag "Date")
  145. (string :tag "Table of Contents")
  146. (string :tag "Footnotes"))))
  147. (defcustom org-export-default-language "en"
  148. "The default language of HTML export, as a string.
  149. This should have an association in `org-export-language-setup'."
  150. :group 'org-export-general
  151. :type 'string)
  152. (defvar org-export-page-description ""
  153. "The page description, for the XHTML meta tag.
  154. This is best set with the #+DESCRIPTION line in a file, it does not make
  155. sense to set this globally.")
  156. (defvar org-export-page-keywords ""
  157. "The page description, for the XHTML meta tag.
  158. This is best set with the #+KEYWORDS line in a file, it does not make
  159. sense to set this globally.")
  160. (defcustom org-export-skip-text-before-1st-heading nil
  161. "Non-nil means, skip all text before the first headline when exporting.
  162. When nil, that text is exported as well."
  163. :group 'org-export-general
  164. :type 'boolean)
  165. (defcustom org-export-headline-levels 3
  166. "The last level which is still exported as a headline.
  167. Inferior levels will produce itemize lists when exported.
  168. Note that a numeric prefix argument to an exporter function overrides
  169. this setting.
  170. This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
  171. :group 'org-export-general
  172. :type 'integer)
  173. (defcustom org-export-with-section-numbers t
  174. "Non-nil means, add section numbers to headlines when exporting.
  175. This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
  176. :group 'org-export-general
  177. :type 'boolean)
  178. (defcustom org-export-section-number-format '((("1" ".")) . "")
  179. "Format of section numbers for export.
  180. The variable has two components.
  181. 1. A list of lists, each indicating a counter type and a separator.
  182. The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
  183. It causes causes numeric, alphabetic, or roman counters, respectively.
  184. The separator is only used if another counter for a subsection is being
  185. added.
  186. If there are more numbered section levels than entries in this lists,
  187. then the last entry will be reused.
  188. 2. A terminator string that will be added after the entire
  189. section number."
  190. :group 'org-export-general
  191. :type '(cons
  192. (repeat
  193. (list
  194. (string :tag "Counter Type")
  195. (string :tag "Separator ")))
  196. (string :tag "Terminator")))
  197. (defcustom org-export-with-toc t
  198. "Non-nil means, create a table of contents in exported files.
  199. The TOC contains headlines with levels up to`org-export-headline-levels'.
  200. When an integer, include levels up to N in the toc, this may then be
  201. different from `org-export-headline-levels', but it will not be allowed
  202. to be larger than the number of headline levels.
  203. When nil, no table of contents is made.
  204. Headlines which contain any TODO items will be marked with \"(*)\" in
  205. ASCII export, and with red color in HTML output, if the option
  206. `org-export-mark-todo-in-toc' is set.
  207. In HTML output, the TOC will be clickable.
  208. This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
  209. or \"toc:3\"."
  210. :group 'org-export-general
  211. :type '(choice
  212. (const :tag "No Table of Contents" nil)
  213. (const :tag "Full Table of Contents" t)
  214. (integer :tag "TOC to level")))
  215. (defcustom org-export-mark-todo-in-toc nil
  216. "Non-nil means, mark TOC lines that contain any open TODO items."
  217. :group 'org-export-general
  218. :type 'boolean)
  219. (defcustom org-export-with-todo-keywords t
  220. "Non-nil means, include TODO keywords in export.
  221. When nil, remove all these keywords from the export."
  222. :group 'org-export-general
  223. :type 'boolean)
  224. (defcustom org-export-with-priority nil
  225. "Non-nil means, include priority cookies in export.
  226. When nil, remove priority cookies for export."
  227. :group 'org-export-general
  228. :type 'boolean)
  229. (defcustom org-export-preserve-breaks nil
  230. "Non-nil means, preserve all line breaks when exporting.
  231. Normally, in HTML output paragraphs will be reformatted. In ASCII
  232. export, line breaks will always be preserved, regardless of this variable.
  233. This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
  234. :group 'org-export-general
  235. :type 'boolean)
  236. (defcustom org-export-with-archived-trees 'headline
  237. "Whether subtrees with the ARCHIVE tag should be exported.
  238. This can have three different values
  239. nil Do not export, pretend this tree is not present
  240. t Do export the entire tree
  241. headline Only export the headline, but skip the tree below it."
  242. :group 'org-export-general
  243. :group 'org-archive
  244. :type '(choice
  245. (const :tag "not at all" nil)
  246. (const :tag "headline only" 'headline)
  247. (const :tag "entirely" t)))
  248. (defcustom org-export-author-info t
  249. "Non-nil means, insert author name and email into the exported file.
  250. This option can also be set with the +OPTIONS line,
  251. e.g. \"author-info:nil\"."
  252. :group 'org-export-general
  253. :type 'boolean)
  254. (defcustom org-export-creator-info t
  255. "Non-nil means, the postamble should contain a creator sentence.
  256. This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
  257. :group 'org-export-general
  258. :type 'boolean)
  259. (defcustom org-export-time-stamp-file t
  260. "Non-nil means, insert a time stamp into the exported file.
  261. The time stamp shows when the file was created.
  262. This option can also be set with the +OPTIONS line,
  263. e.g. \"timestamp:nil\"."
  264. :group 'org-export-general
  265. :type 'boolean)
  266. (defcustom org-export-with-timestamps t
  267. "If nil, do not export time stamps and associated keywords."
  268. :group 'org-export-general
  269. :type 'boolean)
  270. (defcustom org-export-remove-timestamps-from-toc t
  271. "If nil, remove timestamps from the table of contents entries."
  272. :group 'org-export-general
  273. :type 'boolean)
  274. (defcustom org-export-with-tags 'not-in-toc
  275. "If nil, do not export tags, just remove them from headlines.
  276. If this is the symbol `not-in-toc', tags will be removed from table of
  277. contents entries, but still be shown in the headlines of the document.
  278. This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
  279. :group 'org-export-general
  280. :type '(choice
  281. (const :tag "Off" nil)
  282. (const :tag "Not in TOC" not-in-toc)
  283. (const :tag "On" t)))
  284. (defcustom org-export-with-drawers nil
  285. "Non-nil means, export with drawers like the property drawer.
  286. When t, all drawers are exported. This may also be a list of
  287. drawer names to export."
  288. :group 'org-export-general
  289. :type '(choice
  290. (const :tag "All drawers" t)
  291. (const :tag "None" nil)
  292. (repeat :tag "Selected drawers"
  293. (string :tag "Drawer name"))))
  294. (defvar org-export-preprocess-hook nil
  295. "Hook for preprocessing an export buffer.
  296. Pretty much the first thing when exporting is running this hook.")
  297. (defvar org-export-preprocess-after-include-files-hook nil
  298. "Hook for preprocessing an export buffer.
  299. This is run after the contents of included files have been inserted.")
  300. (defvar org-export-preprocess-after-tree-selection-hook nil
  301. "Hook for preprocessing an export buffer.
  302. This is run after selection of trees to be exported has happened.
  303. This selection includes tags-based selection, as well as removal
  304. of commented and archived trees.")
  305. (defvar org-export-preprocess-after-blockquote-hook nil
  306. "Hook for preprocessing an export buffer.
  307. This is run after blockquote/quote/verse/center have been marked
  308. with cookies.")
  309. (defvar org-export-preprocess-before-backend-specifics-hook nil
  310. "Hook run before backend-specific functions are called during preprocessing.")
  311. (defvar org-export-preprocess-final-hook nil
  312. "Hook for preprocessing an export buffer.
  313. This is run as the last thing in the preprocessing buffer, just before
  314. returning the buffer string to the backend.")
  315. (defgroup org-export-translation nil
  316. "Options for translating special ascii sequences for the export backends."
  317. :tag "Org Export Translation"
  318. :group 'org-export)
  319. (defcustom org-export-with-emphasize t
  320. "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
  321. If the export target supports emphasizing text, the word will be
  322. typeset in bold, italic, or underlined, respectively. Works only for
  323. single words, but you can say: I *really* *mean* *this*.
  324. Not all export backends support this.
  325. This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
  326. :group 'org-export-translation
  327. :type 'boolean)
  328. (defcustom org-export-with-footnotes t
  329. "If nil, export [1] as a footnote marker.
  330. Lines starting with [1] will be formatted as footnotes.
  331. This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
  332. :group 'org-export-translation
  333. :type 'boolean)
  334. (defcustom org-export-with-sub-superscripts t
  335. "Non-nil means, interpret \"_\" and \"^\" for export.
  336. When this option is turned on, you can use TeX-like syntax for sub- and
  337. superscripts. Several characters after \"_\" or \"^\" will be
  338. considered as a single item - so grouping with {} is normally not
  339. needed. For example, the following things will be parsed as single
  340. sub- or superscripts.
  341. 10^24 or 10^tau several digits will be considered 1 item.
  342. 10^-12 or 10^-tau a leading sign with digits or a word
  343. x^2-y^3 will be read as x^2 - y^3, because items are
  344. terminated by almost any nonword/nondigit char.
  345. x_{i^2} or x^(2-i) braces or parenthesis do grouping.
  346. Still, ambiguity is possible - so when in doubt use {} to enclose the
  347. sub/superscript. If you set this variable to the symbol `{}',
  348. the braces are *required* in order to trigger interpretations as
  349. sub/superscript. This can be helpful in documents that need \"_\"
  350. frequently in plain text.
  351. Not all export backends support this, but HTML does.
  352. This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
  353. :group 'org-export-translation
  354. :type '(choice
  355. (const :tag "Always interpret" t)
  356. (const :tag "Only with braces" {})
  357. (const :tag "Never interpret" nil)))
  358. (defcustom org-export-with-TeX-macros t
  359. "Non-nil means, interpret simple TeX-like macros when exporting.
  360. For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
  361. Not only real TeX macros will work here, but the standard HTML entities
  362. for math can be used as macro names as well. For a list of supported
  363. names in HTML export, see the constant `org-html-entities'.
  364. Not all export backends support this.
  365. This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
  366. :group 'org-export-translation
  367. :group 'org-export-latex
  368. :type 'boolean)
  369. (defcustom org-export-with-LaTeX-fragments nil
  370. "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
  371. When set, the exporter will find LaTeX environments if the \\begin line is
  372. the first non-white thing on a line. It will also find the math delimiters
  373. like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
  374. display math.
  375. This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\".
  376. The default is nil, because this option needs the `dvipng' program which
  377. is not available on all systems."
  378. :group 'org-export-translation
  379. :group 'org-export-latex
  380. :type 'boolean)
  381. (defcustom org-export-with-fixed-width t
  382. "Non-nil means, lines starting with \":\" will be in fixed width font.
  383. This can be used to have pre-formatted text, fragments of code etc. For
  384. example:
  385. : ;; Some Lisp examples
  386. : (while (defc cnt)
  387. : (ding))
  388. will be looking just like this in also HTML. See also the QUOTE keyword.
  389. Not all export backends support this.
  390. This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
  391. :group 'org-export-translation
  392. :type 'boolean)
  393. (defcustom org-match-sexp-depth 3
  394. "Number of stacked braces for sub/superscript matching.
  395. This has to be set before loading org.el to be effective."
  396. :group 'org-export-translation
  397. :type 'integer)
  398. (defgroup org-export-tables nil
  399. "Options for exporting tables in Org-mode."
  400. :tag "Org Export Tables"
  401. :group 'org-export)
  402. (defcustom org-export-with-tables t
  403. "If non-nil, lines starting with \"|\" define a table.
  404. For example:
  405. | Name | Address | Birthday |
  406. |-------------+----------+-----------|
  407. | Arthur Dent | England | 29.2.2100 |
  408. Not all export backends support this.
  409. This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
  410. :group 'org-export-tables
  411. :type 'boolean)
  412. (defcustom org-export-highlight-first-table-line t
  413. "Non-nil means, highlight the first table line.
  414. In HTML export, this means use <th> instead of <td>.
  415. In tables created with table.el, this applies to the first table line.
  416. In Org-mode tables, all lines before the first horizontal separator
  417. line will be formatted with <th> tags."
  418. :group 'org-export-tables
  419. :type 'boolean)
  420. (defcustom org-export-table-remove-special-lines t
  421. "Remove special lines and marking characters in calculating tables.
  422. This removes the special marking character column from tables that are set
  423. up for spreadsheet calculations. It also removes the entire lines
  424. marked with `!', `_', or `^'. The lines with `$' are kept, because
  425. the values of constants may be useful to have."
  426. :group 'org-export-tables
  427. :type 'boolean)
  428. (defcustom org-export-prefer-native-exporter-for-tables nil
  429. "Non-nil means, always export tables created with table.el natively.
  430. Natively means, use the HTML code generator in table.el.
  431. When nil, Org-mode's own HTML generator is used when possible (i.e. if
  432. the table does not use row- or column-spanning). This has the
  433. advantage, that the automatic HTML conversions for math symbols and
  434. sub/superscripts can be applied. Org-mode's HTML generator is also
  435. much faster."
  436. :group 'org-export-tables
  437. :type 'boolean)
  438. (defgroup org-export-xml nil
  439. "Options specific for XML export of Org-mode files."
  440. :tag "Org Export XML"
  441. :group 'org-export)
  442. ;;;; Exporting
  443. ;;; Variables, constants, and parameter plists
  444. (defconst org-level-max 20)
  445. (defvar org-current-export-file nil) ; dynamically scoped parameter
  446. (defvar org-current-export-dir nil) ; dynamically scoped parameter
  447. (defvar org-export-opt-plist nil
  448. "Contains the current option plist.")
  449. (defvar org-last-level nil) ; dynamically scoped variable
  450. (defvar org-min-level nil) ; dynamically scoped variable
  451. (defvar org-levels-open nil) ; dynamically scoped parameter
  452. (defconst org-export-plist-vars
  453. '((:link-up nil org-export-html-link-up)
  454. (:link-home nil org-export-html-link-home)
  455. (:language nil org-export-default-language)
  456. (:keywords nil org-export-page-keywords)
  457. (:description nil org-export-page-description)
  458. (:customtime nil org-display-custom-times)
  459. (:headline-levels "H" org-export-headline-levels)
  460. (:section-numbers "num" org-export-with-section-numbers)
  461. (:section-number-format nil org-export-section-number-format)
  462. (:table-of-contents "toc" org-export-with-toc)
  463. (:preserve-breaks "\\n" org-export-preserve-breaks)
  464. (:archived-trees nil org-export-with-archived-trees)
  465. (:emphasize "*" org-export-with-emphasize)
  466. (:sub-superscript "^" org-export-with-sub-superscripts)
  467. (:special-strings "-" org-export-with-special-strings)
  468. (:footnotes "f" org-export-with-footnotes)
  469. (:drawers "d" org-export-with-drawers)
  470. (:tags "tags" org-export-with-tags)
  471. (:todo-keywords "todo" org-export-with-todo-keywords)
  472. (:priority "pri" org-export-with-priority)
  473. (:TeX-macros "TeX" org-export-with-TeX-macros)
  474. (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
  475. (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
  476. (:fixed-width ":" org-export-with-fixed-width)
  477. (:timestamps "<" org-export-with-timestamps)
  478. (:author-info "author" org-export-author-info)
  479. (:creator-info "creator" org-export-creator-info)
  480. (:time-stamp-file "timestamp" org-export-time-stamp-file)
  481. (:tables "|" org-export-with-tables)
  482. (:table-auto-headline nil org-export-highlight-first-table-line)
  483. (:style-include-default nil org-export-html-style-include-default)
  484. (:style-include-scripts nil org-export-html-style-include-scripts)
  485. (:style nil org-export-html-style)
  486. (:style-extra nil org-export-html-style-extra)
  487. (:agenda-style nil org-agenda-export-html-style)
  488. (:convert-org-links nil org-export-html-link-org-files-as-html)
  489. (:inline-images nil org-export-html-inline-images)
  490. (:html-extension nil org-export-html-extension)
  491. (:xml-declaration nil org-export-html-xml-declaration)
  492. (:html-table-tag nil org-export-html-table-tag)
  493. (:expand-quoted-html "@" org-export-html-expand)
  494. (:timestamp nil org-export-html-with-timestamp)
  495. (:publishing-directory nil org-export-publishing-directory)
  496. (:preamble nil org-export-html-preamble)
  497. (:postamble nil org-export-html-postamble)
  498. (:auto-preamble nil org-export-html-auto-preamble)
  499. (:auto-postamble nil org-export-html-auto-postamble)
  500. (:author nil user-full-name)
  501. (:email nil user-mail-address)
  502. (:select-tags nil org-export-select-tags)
  503. (:exclude-tags nil org-export-exclude-tags)
  504. (:latex-image-options nil org-export-latex-image-default-option))
  505. "List of properties that represent export/publishing variables.
  506. Each element is a list of 3 items:
  507. 1. The property that is used internally, and also for org-publish-project-alist
  508. 2. The string that can be used in the OPTION lines to set this option,
  509. or nil if this option cannot be changed in this way
  510. 3. The customization variable that sets the default for this option."
  511. )
  512. (defun org-default-export-plist ()
  513. "Return the property list with default settings for the export variables."
  514. (let ((l org-export-plist-vars) rtn e s v)
  515. (while (setq e (pop l))
  516. (setq s (nth 2 e)
  517. v (if (boundp s) (symbol-value s) nil)
  518. rtn (cons (car e) (cons v rtn))))
  519. rtn))
  520. (defvar org-export-inbuffer-options-extra nil
  521. "List of additional in-buffer options that should be detected.
  522. Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
  523. etc. Extensions can add to this list to get their options detected, and they
  524. can then add a function to `org-export-options-filters' to process these
  525. options.
  526. Each element in this list must be a list, with the in-buffer keyword as car,
  527. and a property (a symbol) as the next element. All occurrences of the
  528. keyword will be found, the values concatenated with a space character
  529. in between, and the result stored in the export options property list.")
  530. (defvar org-export-options-filters nil
  531. "Functions to be called to finalize the export/publishing options.
  532. All these options are stored in a property list, and each of the functions
  533. in this hook gets a chance to modify this property list. Each function
  534. must accept the property list as an argument, and must return the (possibly
  535. modified) list.")
  536. ;; FIXME: should we fold case here?
  537. (defun org-infile-export-plist ()
  538. "Return the property list with file-local settings for export."
  539. (save-excursion
  540. (save-restriction
  541. (widen)
  542. (goto-char (point-min))
  543. (let ((re (org-make-options-regexp
  544. (append
  545. '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
  546. "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
  547. "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
  548. "KEYWORDS" "DESCRIPTION")
  549. (mapcar 'car org-export-inbuffer-options-extra))))
  550. p key val text options a pr style
  551. latex-header
  552. ext-setup-or-nil setup-contents (start 0))
  553. (while (or (and ext-setup-or-nil
  554. (string-match re ext-setup-or-nil start)
  555. (setq start (match-end 0)))
  556. (and (setq ext-setup-or-nil nil start 0)
  557. (re-search-forward re nil t)))
  558. (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
  559. val (org-match-string-no-properties 2 ext-setup-or-nil))
  560. (cond
  561. ((setq a (assoc key org-export-inbuffer-options-extra))
  562. (setq pr (nth 1 a))
  563. (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
  564. ((string-equal key "TITLE") (setq p (plist-put p :title val)))
  565. ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
  566. ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
  567. ((string-equal key "DATE") (setq p (plist-put p :date val)))
  568. ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
  569. ((string-equal key "DESCRIPTION")
  570. (setq p (plist-put p :description val)))
  571. ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
  572. ((string-equal key "STYLE")
  573. (setq style (concat style "\n" val)))
  574. ((string-equal key "LATEX_HEADER")
  575. (setq latex-header (concat latex-header "\n" val)))
  576. ((string-equal key "TEXT")
  577. (setq text (if text (concat text "\n" val) val)))
  578. ((string-equal key "OPTIONS")
  579. (setq options (concat val " " options)))
  580. ((string-equal key "LINK_UP")
  581. (setq p (plist-put p :link-up val)))
  582. ((string-equal key "LINK_HOME")
  583. (setq p (plist-put p :link-home val)))
  584. ((string-equal key "EXPORT_SELECT_TAGS")
  585. (setq p (plist-put p :select-tags (org-split-string val))))
  586. ((string-equal key "EXPORT_EXCLUDE_TAGS")
  587. (setq p (plist-put p :exclude-tags (org-split-string val))))
  588. ((equal key "SETUPFILE")
  589. (setq setup-contents (org-file-contents
  590. (expand-file-name
  591. (org-remove-double-quotes
  592. (org-trim val)))
  593. 'noerror))
  594. (if (not ext-setup-or-nil)
  595. (setq ext-setup-or-nil setup-contents start 0)
  596. (setq ext-setup-or-nil
  597. (concat (substring ext-setup-or-nil 0 start)
  598. "\n" setup-contents "\n"
  599. (substring ext-setup-or-nil start)))))))
  600. (setq p (plist-put p :text text))
  601. (when style (setq p (plist-put p :style-extra style)))
  602. (when latex-header
  603. (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
  604. (when options
  605. (setq p (org-export-add-options-to-plist p options)))
  606. ;; Add macro definitions
  607. (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
  608. (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
  609. (setq p (plist-put
  610. p :macro-modification-time
  611. (and (buffer-file-name)
  612. (file-exists-p (buffer-file-name))
  613. (concat
  614. "(eval (format-time-string \"$1\" '"
  615. (prin1-to-string (nth 5 (file-attributes
  616. (buffer-file-name))))
  617. "))"))))
  618. (setq p (plist-put p :macro-input-file (and (buffer-file-name)
  619. (file-name-nondirectory
  620. (buffer-file-name)))))
  621. (goto-char (point-min))
  622. (while (re-search-forward
  623. "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
  624. nil t)
  625. (setq p (plist-put p (intern (concat ":macro-"
  626. (downcase (match-string 1))))
  627. (match-string 2))))
  628. p))))
  629. (defun org-export-add-options-to-plist (p options)
  630. "Parse an OPTIONS line and set values in the property list P."
  631. (let (o)
  632. (when options
  633. (let ((op org-export-plist-vars))
  634. (while (setq o (pop op))
  635. (if (and (nth 1 o)
  636. (string-match (concat (regexp-quote (nth 1 o))
  637. ":\\([^ \t\n\r;,.]*\\)")
  638. options))
  639. (setq p (plist-put p (car o)
  640. (car (read-from-string
  641. (match-string 1 options))))))))))
  642. p)
  643. (defun org-export-add-subtree-options (p pos)
  644. "Add options in subtree at position POS to property list P."
  645. (save-excursion
  646. (goto-char pos)
  647. (when (org-at-heading-p)
  648. (let (a)
  649. ;; This is actually read in `org-export-get-title-from-subtree'
  650. ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
  651. ;; (setq p (plist-put p :title a)))
  652. (when (setq a (org-entry-get pos "EXPORT_TEXT"))
  653. (setq p (plist-put p :text a)))
  654. (when (setq a (org-entry-get pos "EXPORT_AUTHOR"))
  655. (setq p (plist-put p :author a)))
  656. (when (setq a (org-entry-get pos "EXPORT_DATE"))
  657. (setq p (plist-put p :date a)))
  658. (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
  659. (setq p (org-export-add-options-to-plist p a)))))
  660. p))
  661. (defun org-export-directory (type plist)
  662. (let* ((val (plist-get plist :publishing-directory))
  663. (dir (if (listp val)
  664. (or (cdr (assoc type val)) ".")
  665. val)))
  666. dir))
  667. (defun org-export-process-option-filters (plist)
  668. (let ((functions org-export-options-filters) f)
  669. (while (setq f (pop functions))
  670. (setq plist (funcall f plist))))
  671. plist)
  672. ;;;###autoload
  673. (defun org-export (&optional arg)
  674. "Export dispatcher for Org-mode.
  675. When `org-export-run-in-background' is non-nil, try to run the command
  676. in the background. This will be done only for commands that write
  677. to a file. For details see the docstring of `org-export-run-in-background'.
  678. The prefix argument ARG will be passed to the exporter. However, if
  679. ARG is a double universal prefix `C-u C-u', that means to inverse the
  680. value of `org-export-run-in-background'."
  681. (interactive "P")
  682. (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
  683. (help "[t] insert the export option template
  684. \[v] limit export to visible part of outline tree
  685. \[a] export as ASCII [A] to temporary buffer
  686. \[h] export as HTML [H] to temporary buffer [R] export region
  687. \[b] export as HTML and open in browser
  688. \[l] export as LaTeX [L] to temporary buffer
  689. \[p] export as LaTeX and process to PDF
  690. \[d] export as LaTeX, process to PDF, and open the resulting PDF document
  691. \[D] export as DocBook
  692. \[V] export as DocBook, process to PDF, and open the resulting PDF document
  693. \[x] export as XOXO
  694. \[i] export current file as iCalendar file
  695. \[I] export all agenda files as iCalendar files
  696. \[c] export agenda files into combined iCalendar file
  697. \[F] publish current file [P] publish current project
  698. \[X] publish a project... [E] publish every projects")
  699. (cmds
  700. '((?t org-insert-export-options-template nil)
  701. (?v org-export-visible nil)
  702. (?a org-export-as-ascii t)
  703. (?A org-export-as-ascii-to-buffer t)
  704. (?h org-export-as-html t)
  705. (?b org-export-as-html-and-open t)
  706. (?H org-export-as-html-to-buffer nil)
  707. (?R org-export-region-as-html nil)
  708. (?x org-export-as-xoxo t)
  709. (?D org-export-as-docbook t)
  710. (?V org-export-as-docbook-pdf-and-open t)
  711. (?l org-export-as-latex t)
  712. (?p org-export-as-pdf t)
  713. (?d org-export-as-pdf-and-open t)
  714. (?L org-export-as-latex-to-buffer nil)
  715. (?i org-export-icalendar-this-file t)
  716. (?I org-export-icalendar-all-agenda-files t)
  717. (?c org-export-icalendar-combine-agenda-files t)
  718. (?F org-publish-current-file t)
  719. (?P org-publish-current-project t)
  720. (?X org-publish t)
  721. (?E org-publish-all t)))
  722. r1 r2 ass)
  723. (save-excursion
  724. (save-window-excursion
  725. (delete-other-windows)
  726. (with-output-to-temp-buffer "*Org Export/Publishing Help*"
  727. (princ help))
  728. (org-fit-window-to-buffer (get-buffer-window
  729. "*Org Export/Publishing Help*"))
  730. (message "Select command: ")
  731. (setq r1 (read-char-exclusive))))
  732. (setq r2 (if (< r1 27) (+ r1 96) r1))
  733. (unless (setq ass (assq r2 cmds))
  734. (error "No command associated with key %c" r1))
  735. (if (and bg (nth 2 ass)
  736. (not (buffer-base-buffer))
  737. (not (org-region-active-p)))
  738. ;; execute in background
  739. (let ((p (start-process
  740. (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
  741. "*Org Processes*"
  742. (expand-file-name invocation-name invocation-directory)
  743. "-batch"
  744. "-l" user-init-file
  745. "--eval" "(require 'org-exp)"
  746. "--eval" "(setq org-wait .2)"
  747. (buffer-file-name)
  748. "-f" (symbol-name (nth 1 ass)))))
  749. (set-process-sentinel p 'org-export-process-sentinel)
  750. (message "Background process \"%s\": started" p))
  751. ;; background processing not requested, or not possible
  752. (call-interactively (nth 1 ass)))))
  753. (defun org-export-process-sentinel (process status)
  754. (if (string-match "\n+\\'" status)
  755. (setq status (substring status 0 -1)))
  756. (message "Background process \"%s\": %s" process status))
  757. (defconst org-html-entities
  758. '(("nbsp")
  759. ("iexcl")
  760. ("cent")
  761. ("pound")
  762. ("curren")
  763. ("yen")
  764. ("brvbar")
  765. ("vert" . "&#124;")
  766. ("sect")
  767. ("uml")
  768. ("copy")
  769. ("ordf")
  770. ("laquo")
  771. ("not")
  772. ("shy")
  773. ("reg")
  774. ("macr")
  775. ("deg")
  776. ("pm" . "&plusmn;")
  777. ("plusmn")
  778. ("sup2")
  779. ("sup3")
  780. ("acute")
  781. ("micro")
  782. ("para")
  783. ("middot")
  784. ("odot"."o")
  785. ("star"."*")
  786. ("cedil")
  787. ("sup1")
  788. ("ordm")
  789. ("raquo")
  790. ("frac14")
  791. ("frac12")
  792. ("frac34")
  793. ("iquest")
  794. ("Agrave")
  795. ("Aacute")
  796. ("Acirc")
  797. ("Atilde")
  798. ("Auml")
  799. ("Aring") ("AA"."&Aring;")
  800. ("AElig")
  801. ("Ccedil")
  802. ("Egrave")
  803. ("Eacute")
  804. ("Ecirc")
  805. ("Euml")
  806. ("Igrave")
  807. ("Iacute")
  808. ("Icirc")
  809. ("Iuml")
  810. ("ETH")
  811. ("Ntilde")
  812. ("Ograve")
  813. ("Oacute")
  814. ("Ocirc")
  815. ("Otilde")
  816. ("Ouml")
  817. ("times")
  818. ("Oslash")
  819. ("Ugrave")
  820. ("Uacute")
  821. ("Ucirc")
  822. ("Uuml")
  823. ("Yacute")
  824. ("THORN")
  825. ("szlig")
  826. ("agrave")
  827. ("aacute")
  828. ("acirc")
  829. ("atilde")
  830. ("auml")
  831. ("aring")
  832. ("aelig")
  833. ("ccedil")
  834. ("egrave")
  835. ("eacute")
  836. ("ecirc")
  837. ("euml")
  838. ("igrave")
  839. ("iacute")
  840. ("icirc")
  841. ("iuml")
  842. ("eth")
  843. ("ntilde")
  844. ("ograve")
  845. ("oacute")
  846. ("ocirc")
  847. ("otilde")
  848. ("ouml")
  849. ("divide")
  850. ("oslash")
  851. ("ugrave")
  852. ("uacute")
  853. ("ucirc")
  854. ("uuml")
  855. ("yacute")
  856. ("thorn")
  857. ("yuml")
  858. ("fnof")
  859. ("Alpha")
  860. ("Beta")
  861. ("Gamma")
  862. ("Delta")
  863. ("Epsilon")
  864. ("Zeta")
  865. ("Eta")
  866. ("Theta")
  867. ("Iota")
  868. ("Kappa")
  869. ("Lambda")
  870. ("Mu")
  871. ("Nu")
  872. ("Xi")
  873. ("Omicron")
  874. ("Pi")
  875. ("Rho")
  876. ("Sigma")
  877. ("Tau")
  878. ("Upsilon")
  879. ("Phi")
  880. ("Chi")
  881. ("Psi")
  882. ("Omega")
  883. ("alpha")
  884. ("beta")
  885. ("gamma")
  886. ("delta")
  887. ("epsilon")
  888. ("varepsilon"."&epsilon;")
  889. ("zeta")
  890. ("eta")
  891. ("theta")
  892. ("iota")
  893. ("kappa")
  894. ("lambda")
  895. ("mu")
  896. ("nu")
  897. ("xi")
  898. ("omicron")
  899. ("pi")
  900. ("rho")
  901. ("sigmaf") ("varsigma"."&sigmaf;")
  902. ("sigma")
  903. ("tau")
  904. ("upsilon")
  905. ("phi")
  906. ("chi")
  907. ("psi")
  908. ("omega")
  909. ("thetasym") ("vartheta"."&thetasym;")
  910. ("upsih")
  911. ("piv")
  912. ("bull") ("bullet"."&bull;")
  913. ("hellip") ("dots"."&hellip;")
  914. ("prime")
  915. ("Prime")
  916. ("oline")
  917. ("frasl")
  918. ("weierp")
  919. ("image")
  920. ("real")
  921. ("trade")
  922. ("alefsym")
  923. ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
  924. ("uarr") ("uparrow"."&uarr;")
  925. ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
  926. ("darr")("downarrow"."&darr;")
  927. ("harr") ("leftrightarrow"."&harr;")
  928. ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
  929. ("lArr") ("Leftarrow"."&lArr;")
  930. ("uArr") ("Uparrow"."&uArr;")
  931. ("rArr") ("Rightarrow"."&rArr;")
  932. ("dArr") ("Downarrow"."&dArr;")
  933. ("hArr") ("Leftrightarrow"."&hArr;")
  934. ("forall")
  935. ("part") ("partial"."&part;")
  936. ("exist") ("exists"."&exist;")
  937. ("empty") ("emptyset"."&empty;")
  938. ("nabla")
  939. ("isin") ("in"."&isin;")
  940. ("notin")
  941. ("ni")
  942. ("prod")
  943. ("sum")
  944. ("minus")
  945. ("lowast") ("ast"."&lowast;")
  946. ("radic")
  947. ("prop") ("proptp"."&prop;")
  948. ("infin") ("infty"."&infin;")
  949. ("ang") ("angle"."&ang;")
  950. ("and") ("wedge"."&and;")
  951. ("or") ("vee"."&or;")
  952. ("cap")
  953. ("cup")
  954. ("int")
  955. ("there4")
  956. ("sim")
  957. ("cong") ("simeq"."&cong;")
  958. ("asymp")("approx"."&asymp;")
  959. ("ne") ("neq"."&ne;")
  960. ("equiv")
  961. ("le")
  962. ("ge")
  963. ("sub") ("subset"."&sub;")
  964. ("sup") ("supset"."&sup;")
  965. ("nsub")
  966. ("sube")
  967. ("supe")
  968. ("oplus")
  969. ("otimes")
  970. ("perp")
  971. ("sdot") ("cdot"."&sdot;")
  972. ("lceil")
  973. ("rceil")
  974. ("lfloor")
  975. ("rfloor")
  976. ("lang")
  977. ("rang")
  978. ("loz") ("Diamond"."&loz;")
  979. ("spades") ("spadesuit"."&spades;")
  980. ("clubs") ("clubsuit"."&clubs;")
  981. ("hearts") ("diamondsuit"."&hearts;")
  982. ("diams") ("diamondsuit"."&diams;")
  983. ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
  984. ("quot")
  985. ("amp")
  986. ("lt")
  987. ("gt")
  988. ("OElig")
  989. ("oelig")
  990. ("Scaron")
  991. ("scaron")
  992. ("Yuml")
  993. ("circ")
  994. ("tilde")
  995. ("ensp")
  996. ("emsp")
  997. ("thinsp")
  998. ("zwnj")
  999. ("zwj")
  1000. ("lrm")
  1001. ("rlm")
  1002. ("ndash")
  1003. ("mdash")
  1004. ("lsquo")
  1005. ("rsquo")
  1006. ("sbquo")
  1007. ("ldquo")
  1008. ("rdquo")
  1009. ("bdquo")
  1010. ("dagger")
  1011. ("Dagger")
  1012. ("permil")
  1013. ("lsaquo")
  1014. ("rsaquo")
  1015. ("euro")
  1016. ("arccos"."arccos")
  1017. ("arcsin"."arcsin")
  1018. ("arctan"."arctan")
  1019. ("arg"."arg")
  1020. ("cos"."cos")
  1021. ("cosh"."cosh")
  1022. ("cot"."cot")
  1023. ("coth"."coth")
  1024. ("csc"."csc")
  1025. ("deg"."deg")
  1026. ("det"."det")
  1027. ("dim"."dim")
  1028. ("exp"."exp")
  1029. ("gcd"."gcd")
  1030. ("hom"."hom")
  1031. ("inf"."inf")
  1032. ("ker"."ker")
  1033. ("lg"."lg")
  1034. ("lim"."lim")
  1035. ("liminf"."liminf")
  1036. ("limsup"."limsup")
  1037. ("ln"."ln")
  1038. ("log"."log")
  1039. ("max"."max")
  1040. ("min"."min")
  1041. ("Pr"."Pr")
  1042. ("sec"."sec")
  1043. ("sin"."sin")
  1044. ("sinh"."sinh")
  1045. ("sup"."sup")
  1046. ("tan"."tan")
  1047. ("tanh"."tanh")
  1048. )
  1049. "Entities for TeX->HTML translation.
  1050. Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
  1051. \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
  1052. In that case, \"\\ent\" will be translated to \"&other;\".
  1053. The list contains HTML entities for Latin-1, Greek and other symbols.
  1054. It is supplemented by a number of commonly used TeX macros with appropriate
  1055. translations. There is currently no way for users to extend this.")
  1056. ;;; General functions for all backends
  1057. (defvar org-export-target-aliases nil
  1058. "Alist of targets with invisible aliases.")
  1059. (defvar org-export-preferred-target-alist nil
  1060. "Alist of section id's with preferred aliases.")
  1061. (defvar org-export-code-refs nil
  1062. "Alist of code references and line numbers")
  1063. (defun org-export-preprocess-string (string &rest parameters)
  1064. "Cleanup STRING so that that the true exported has a more consistent source.
  1065. This function takes STRING, which should be a buffer-string of an org-file
  1066. to export. It then creates a temporary buffer where it does its job.
  1067. The result is then again returned as a string, and the exporter works
  1068. on this string to produce the exported version."
  1069. (interactive)
  1070. (let* ((htmlp (plist-get parameters :for-html))
  1071. (asciip (plist-get parameters :for-ascii))
  1072. (latexp (plist-get parameters :for-LaTeX))
  1073. (docbookp (plist-get parameters :for-docbook))
  1074. (backend (cond (htmlp 'html)
  1075. (latexp 'latex)
  1076. (asciip 'ascii)
  1077. (docbookp 'docbook)))
  1078. (archived-trees (plist-get parameters :archived-trees))
  1079. (inhibit-read-only t)
  1080. (drawers org-drawers)
  1081. (outline-regexp "\\*+ ")
  1082. target-alist rtn)
  1083. (setq org-export-target-aliases nil)
  1084. (setq org-export-preferred-target-alist nil)
  1085. (setq org-export-code-refs nil)
  1086. (with-current-buffer (get-buffer-create " org-mode-tmp")
  1087. (erase-buffer)
  1088. (insert string)
  1089. (setq case-fold-search t)
  1090. ;; Remove license-to-kill stuff
  1091. ;; The caller marks some stuff for killing, stuff that has been
  1092. ;; used to create the page title, for example.
  1093. (org-export-kill-licensed-text)
  1094. (let ((org-inhibit-startup t)) (org-mode))
  1095. (setq case-fold-search t)
  1096. ;; Call the hook
  1097. (run-hooks 'org-export-preprocess-hook)
  1098. ;; Process the macros
  1099. (org-export-preprocess-apply-macros)
  1100. (run-hooks 'org-export-preprocess-after-macros-hook)
  1101. (untabify (point-min) (point-max))
  1102. ;; Handle include files, and call a hook
  1103. (org-export-handle-include-files)
  1104. (run-hooks 'org-export-preprocess-after-include-files-hook)
  1105. ;; Get rid of archived trees
  1106. (org-export-remove-archived-trees archived-trees)
  1107. ;; Remove comment environment and comment subtrees
  1108. (org-export-remove-comment-blocks-and-subtrees)
  1109. ;; Get rid of excluded trees, and call a hook
  1110. (org-export-handle-export-tags (plist-get parameters :select-tags)
  1111. (plist-get parameters :exclude-tags))
  1112. (run-hooks 'org-export-preprocess-after-tree-selection-hook)
  1113. ;; Handle source code snippets
  1114. (org-export-replace-src-segments-and-examples backend)
  1115. ;; Protect short examples marked by a leading colon
  1116. (org-export-protect-colon-examples)
  1117. ;; Normalize footnotes
  1118. (when (plist-get parameters :footnotes)
  1119. (org-footnote-normalize nil t))
  1120. ;; Find all headings and compute the targets for them
  1121. (setq target-alist (org-export-define-heading-targets target-alist))
  1122. ;; Get rid of drawers
  1123. (org-export-remove-or-extract-drawers drawers
  1124. (plist-get parameters :drawers))
  1125. ;; Get the correct stuff before the first headline
  1126. (when (plist-get parameters :skip-before-1st-heading)
  1127. (goto-char (point-min))
  1128. (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
  1129. (delete-region (point-min) (match-beginning 0))
  1130. (goto-char (point-min))
  1131. (insert "\n")))
  1132. (when (plist-get parameters :add-text)
  1133. (goto-char (point-min))
  1134. (insert (plist-get parameters :add-text) "\n"))
  1135. ;; Remove todo-keywords before exporting, if the user has requested so
  1136. (org-export-remove-headline-metadata parameters)
  1137. ;; Find targets in comments and move them out of comments,
  1138. ;; but mark them as targets that should be invisible
  1139. (setq target-alist (org-export-handle-invisible-targets target-alist))
  1140. ;; Select and protect backend specific stuff, throw away stuff
  1141. ;; that is specific for other backends
  1142. (org-export-select-backend-specific-text backend)
  1143. ;; Protect quoted subtrees
  1144. (org-export-protect-quoted-subtrees)
  1145. ;; Remove clock lines
  1146. (org-export-remove-clock-lines)
  1147. ;; Protect verbatim elements
  1148. (org-export-protect-verbatim)
  1149. ;; Blockquotes, verse, and center
  1150. (org-export-mark-blockquote-verse-center)
  1151. (run-hooks 'org-export-preprocess-after-blockquote-hook)
  1152. ;; Remove timestamps, if the user has requested so
  1153. (unless (plist-get parameters :timestamps)
  1154. (org-export-remove-timestamps))
  1155. ;; Attach captions to the correct object
  1156. (setq target-alist (org-export-attach-captions-and-attributes
  1157. backend target-alist))
  1158. ;; Find matches for radio targets and turn them into internal links
  1159. (org-export-mark-radio-links)
  1160. ;; Find all links that contain a newline and put them into a single line
  1161. (org-export-concatenate-multiline-links)
  1162. ;; Normalize links: Convert angle and plain links into bracket links
  1163. ;; and expand link abbreviations
  1164. (org-export-normalize-links)
  1165. ;; Find all internal links. If they have a fuzzy match (i.e. not
  1166. ;; a *dedicated* target match, let the link point to the
  1167. ;; corresponding section.
  1168. (org-export-target-internal-links target-alist)
  1169. ;; Find multiline emphasis and put them into single line
  1170. (when (plist-get parameters :emph-multiline)
  1171. (org-export-concatenate-multiline-emphasis))
  1172. ;; Remove special table lines
  1173. (when org-export-table-remove-special-lines
  1174. (org-export-remove-special-table-lines))
  1175. ;; Another hook
  1176. (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
  1177. ;; LaTeX-specific preprocessing
  1178. (when latexp
  1179. (require 'org-latex nil)
  1180. (org-export-latex-preprocess parameters))
  1181. ;; ASCII-specific preprocessing
  1182. (when asciip
  1183. (org-export-ascii-preprocess parameters))
  1184. ;; HTML-specific preprocessing
  1185. (when htmlp
  1186. (org-export-html-preprocess parameters))
  1187. ;; DocBook-specific preprocessing
  1188. (when docbookp
  1189. (require 'org-docbook nil)
  1190. (org-export-docbook-preprocess parameters))
  1191. ;; Remove or replace comments
  1192. (org-export-handle-comments (plist-get parameters :comments))
  1193. ;; Run the final hook
  1194. (run-hooks 'org-export-preprocess-final-hook)
  1195. (setq rtn (buffer-string)))
  1196. (kill-buffer " org-mode-tmp")
  1197. rtn))
  1198. (defun org-export-kill-licensed-text ()
  1199. "Remove all text that is marked with a :org-license-to-kill property."
  1200. (let (p)
  1201. (while (setq p (text-property-any (point-min) (point-max)
  1202. :org-license-to-kill t))
  1203. (delete-region
  1204. p (or (next-single-property-change p :org-license-to-kill)
  1205. (point-max))))))
  1206. (defun org-export-define-heading-targets (target-alist)
  1207. "Find all headings and define the targets for them.
  1208. The new targets are added to TARGET-ALIST, which is also returned."
  1209. (goto-char (point-min))
  1210. (org-init-section-numbers)
  1211. (let ((re (concat "^" org-outline-regexp
  1212. "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
  1213. level target last-section-target a id)
  1214. (while (re-search-forward re nil t)
  1215. (if (match-end 2)
  1216. (progn
  1217. (setq id (org-match-string-no-properties 2))
  1218. (push (cons id target) target-alist)
  1219. (setq a (or (assoc last-section-target org-export-target-aliases)
  1220. (progn
  1221. (push (list last-section-target)
  1222. org-export-target-aliases)
  1223. (car org-export-target-aliases))))
  1224. (push (caar target-alist) (cdr a))
  1225. (when (equal (match-string 1) "CUSTOM_ID")
  1226. (if (not (assoc last-section-target
  1227. org-export-preferred-target-alist))
  1228. (push (cons last-section-target id)
  1229. org-export-preferred-target-alist))))
  1230. (setq level (org-reduced-level
  1231. (save-excursion (goto-char (point-at-bol))
  1232. (org-outline-level))))
  1233. (setq target (org-solidify-link-text
  1234. (format "sec-%s" (org-section-number level))))
  1235. (setq last-section-target target)
  1236. (push (cons target target) target-alist)
  1237. (add-text-properties
  1238. (point-at-bol) (point-at-eol)
  1239. (list 'target target)))))
  1240. target-alist)
  1241. (defun org-export-handle-invisible-targets (target-alist)
  1242. "Find targets in comments and move them out of comments.
  1243. Mark them as invisible targets."
  1244. (let (target tmp a)
  1245. (goto-char (point-min))
  1246. (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
  1247. ;; Check if the line before or after is a headline with a target
  1248. (if (setq target (or (get-text-property (point-at-bol 0) 'target)
  1249. (get-text-property (point-at-bol 2) 'target)))
  1250. (progn
  1251. ;; use the existing target in a neighboring line
  1252. (setq tmp (match-string 2))
  1253. (replace-match "")
  1254. (and (looking-at "\n") (delete-char 1))
  1255. (push (cons (setq tmp (org-solidify-link-text tmp)) target)
  1256. target-alist)
  1257. (setq a (or (assoc target org-export-target-aliases)
  1258. (progn
  1259. (push (list target) org-export-target-aliases)
  1260. (car org-export-target-aliases))))
  1261. (push tmp (cdr a)))
  1262. ;; Make an invisible target
  1263. (replace-match "\\1(INVISIBLE)"))))
  1264. target-alist)
  1265. (defun org-export-target-internal-links (target-alist)
  1266. "Find all internal links and assign targets to them.
  1267. If a link has a fuzzy match (i.e. not a *dedicated* target match),
  1268. let the link point to the corresponding section.
  1269. This function also handles the id links, if they have a match in
  1270. the current file."
  1271. (goto-char (point-min))
  1272. (while (re-search-forward org-bracket-link-regexp nil t)
  1273. (org-if-unprotected
  1274. (let* ((md (match-data))
  1275. (desc (match-end 2))
  1276. (link (org-link-unescape (match-string 1)))
  1277. (slink (org-solidify-link-text link))
  1278. found props pos cref
  1279. (target
  1280. (cond
  1281. ((= (string-to-char link) ?#)
  1282. ;; user wants exactly this link
  1283. link)
  1284. ((cdr (assoc slink target-alist))
  1285. (or (cdr (assoc (assoc slink target-alist)
  1286. org-export-preferred-target-alist))
  1287. (cdr (assoc slink target-alist))))
  1288. ((and (string-match "^id:" link)
  1289. (cdr (assoc (substring link 3) target-alist))))
  1290. ((string-match "^(\\(.*\\))$" link)
  1291. (setq cref (match-string 1 link))
  1292. (concat "coderef:" cref))
  1293. ((string-match org-link-types-re link) nil)
  1294. ((or (file-name-absolute-p link)
  1295. (string-match "^\\." link))
  1296. nil)
  1297. (t
  1298. (save-excursion
  1299. (setq found (condition-case nil (org-link-search link)
  1300. (error nil)))
  1301. (when (and found
  1302. (or (org-on-heading-p)
  1303. (not (eq found 'dedicated))))
  1304. (or (get-text-property (point) 'target)
  1305. (get-text-property
  1306. (max (point-min)
  1307. (1- (or (previous-single-property-change
  1308. (point) 'target) 0)))
  1309. 'target))))))))
  1310. (when target
  1311. (set-match-data md)
  1312. (goto-char (match-beginning 1))
  1313. (setq props (text-properties-at (point)))
  1314. (delete-region (match-beginning 1) (match-end 1))
  1315. (setq pos (point))
  1316. (insert target)
  1317. (unless desc (insert "][" link))
  1318. (add-text-properties pos (point) props))))))
  1319. (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
  1320. "Remove drawers, or extract the content.
  1321. ALL-DRAWERS is a list of all drawer names valid in the current buffer.
  1322. EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
  1323. whose content to keep."
  1324. (unless (eq t exp-drawers)
  1325. (goto-char (point-min))
  1326. (let ((re (concat "^[ \t]*:\\("
  1327. (mapconcat
  1328. 'identity
  1329. (org-delete-all exp-drawers
  1330. (copy-sequence all-drawers))
  1331. "\\|")
  1332. "\\):[ \t]*$"))
  1333. beg eol)
  1334. (while (re-search-forward re nil t)
  1335. (org-if-unprotected
  1336. (setq beg (match-beginning 0)
  1337. eol (match-end 0))
  1338. (if (re-search-forward "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]"
  1339. nil t)
  1340. (if (match-end 1)
  1341. ;; terminated in this entry
  1342. (progn
  1343. (delete-region beg (match-end 1))
  1344. (goto-char beg))
  1345. (goto-char eol))))))))
  1346. (defun org-export-handle-export-tags (select-tags exclude-tags)
  1347. "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
  1348. Both arguments are lists of tags.
  1349. If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
  1350. will be removed.
  1351. After that, all subtrees that are marked by EXCLUDE-TAGS will be
  1352. removed as well."
  1353. (remove-text-properties (point-min) (point-max) '(:org-delete t))
  1354. (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
  1355. select-tags "\\|")
  1356. "\\):"))
  1357. (re-excl (concat ":\\(" (mapconcat 'regexp-quote
  1358. exclude-tags "\\|")
  1359. "\\):"))
  1360. beg end cont)
  1361. (goto-char (point-min))
  1362. (when (and select-tags
  1363. (re-search-forward
  1364. (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
  1365. ;; At least one tree is marked for export, this means
  1366. ;; all the unmarked stuff needs to go.
  1367. ;; Dig out the trees that should be exported
  1368. (goto-char (point-min))
  1369. (outline-next-heading)
  1370. (setq beg (point))
  1371. (put-text-property beg (point-max) :org-delete t)
  1372. (while (re-search-forward re-sel nil t)
  1373. (when (org-on-heading-p)
  1374. (org-back-to-heading)
  1375. (remove-text-properties
  1376. (max (1- (point)) (point-min))
  1377. (setq cont (save-excursion (org-end-of-subtree t t)))
  1378. '(:org-delete t))
  1379. (while (and (org-up-heading-safe)
  1380. (get-text-property (point) :org-delete))
  1381. (remove-text-properties (max (1- (point)) (point-min))
  1382. (point-at-eol) '(:org-delete t)))
  1383. (goto-char cont))))
  1384. ;; Remove the trees explicitly marked for noexport
  1385. (when exclude-tags
  1386. (goto-char (point-min))
  1387. (while (re-search-forward re-excl nil t)
  1388. (when (org-at-heading-p)
  1389. (org-back-to-heading t)
  1390. (setq beg (point))
  1391. (org-end-of-subtree t)
  1392. (delete-region beg (point)))))
  1393. ;; Remove everything that is now still marked for deletion
  1394. (goto-char (point-min))
  1395. (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
  1396. (setq end (or (next-single-property-change beg :org-delete)
  1397. (point-max)))
  1398. (delete-region beg end))))
  1399. (defun org-export-remove-archived-trees (export-archived-trees)
  1400. "Remove archived trees.
  1401. When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
  1402. When it is t, the entire archived tree will be exported.
  1403. When it is nil the entire tree including the headline will be removed
  1404. from the buffer."
  1405. (let ((re-archive (concat ":" org-archive-tag ":"))
  1406. a b)
  1407. (when (not (eq export-archived-trees t))
  1408. (goto-char (point-min))
  1409. (while (re-search-forward re-archive nil t)
  1410. (if (not (org-on-heading-p t))
  1411. (org-end-of-subtree t)
  1412. (beginning-of-line 1)
  1413. (setq a (if export-archived-trees
  1414. (1+ (point-at-eol)) (point))
  1415. b (org-end-of-subtree t))
  1416. (if (> b a) (delete-region a b)))))))
  1417. (defun org-export-remove-headline-metadata (opts)
  1418. "Remove meta data from the headline, according to user options."
  1419. (let ((re org-complex-heading-regexp)
  1420. (todo (plist-get opts :todo-keywords))
  1421. (tags (plist-get opts :tags))
  1422. (pri (plist-get opts :priority))
  1423. (elts '(1 2 3 4 5))
  1424. rpl)
  1425. (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
  1426. (when (or (not todo) (not tags) (not pri))
  1427. (goto-char (point-min))
  1428. (while (re-search-forward re nil t)
  1429. (org-if-unprotected
  1430. (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
  1431. elts " "))
  1432. (replace-match rpl t t))))))
  1433. (defun org-export-remove-timestamps ()
  1434. "Remove timestamps and keywords for export."
  1435. (goto-char (point-min))
  1436. (while (re-search-forward org-maybe-keyword-time-regexp nil t)
  1437. (backward-char 1)
  1438. (org-if-unprotected
  1439. (unless (save-match-data (org-at-table-p))
  1440. (replace-match "")
  1441. (beginning-of-line 1)
  1442. (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
  1443. (replace-match ""))))))
  1444. (defun org-export-remove-clock-lines ()
  1445. "Remove clock lines for export."
  1446. (goto-char (point-min))
  1447. (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
  1448. (while (re-search-forward re nil t)
  1449. (org-if-unprotected
  1450. (replace-match "")))))
  1451. (defun org-export-protect-quoted-subtrees ()
  1452. "Mark quoted subtrees with the protection property."
  1453. (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
  1454. (goto-char (point-min))
  1455. (while (re-search-forward re-quote nil t)
  1456. (goto-char (match-beginning 0))
  1457. (end-of-line 1)
  1458. (add-text-properties (point) (org-end-of-subtree t)
  1459. '(org-protected t)))))
  1460. (defun org-export-protect-verbatim ()
  1461. "Mark verbatim snippets with the protection property."
  1462. (goto-char (point-min))
  1463. (while (re-search-forward org-verbatim-re nil t)
  1464. (add-text-properties (match-beginning 4) (match-end 4)
  1465. '(org-protected t))
  1466. (goto-char (1+ (match-end 4)))))
  1467. (defun org-export-protect-colon-examples ()
  1468. "Protect lines starting with a colon."
  1469. (goto-char (point-min))
  1470. (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
  1471. (while (re-search-forward re nil t)
  1472. (beginning-of-line 1)
  1473. (setq beg (point))
  1474. (while (looking-at re)
  1475. (end-of-line 1)
  1476. (or (eobp) (forward-char 1)))
  1477. (add-text-properties beg (if (bolp) (1- (point)) (point))
  1478. '(org-protected t)))))
  1479. (defun org-export-select-backend-specific-text (backend)
  1480. (let ((formatters
  1481. '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
  1482. (html "HTML" "BEGIN_HTML" "END_HTML")
  1483. (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
  1484. (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1485. (case-fold-search t)
  1486. fmt)
  1487. (while formatters
  1488. (setq fmt (pop formatters))
  1489. (when (eq (car fmt) backend)
  1490. ;; This is selected code, put it into the file for real
  1491. (goto-char (point-min))
  1492. (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
  1493. ":[ \t]*\\(.*\\)") nil t)
  1494. (replace-match "\\1\\2" t)
  1495. (add-text-properties
  1496. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1497. '(org-protected t))))
  1498. (goto-char (point-min))
  1499. (while (re-search-forward
  1500. (concat "^[ \t]*#\\+" (caddr fmt)
  1501. "\\>.*\\(\\(\n.*\\)*?\n\\)[ \t]*#\\+" (cadddr fmt)
  1502. "\\>.*\n?") nil t)
  1503. (if (eq (car fmt) backend)
  1504. ;; yes, keep this
  1505. (add-text-properties (match-beginning 1) (1+ (match-end 1))
  1506. '(org-protected t))
  1507. ;; No, this is for a different backend, kill it
  1508. (delete-region (match-beginning 0) (match-end 0)))))))
  1509. (defun org-export-mark-blockquote-verse-center ()
  1510. "Mark block quote and verse environments with special cookies.
  1511. These special cookies will later be interpreted by the backend."
  1512. ;; Blockquotes
  1513. (let (type t1 ind beg end beg1 end1 content)
  1514. (goto-char (point-min))
  1515. (while (re-search-forward
  1516. "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
  1517. nil t)
  1518. (setq ind (length (match-string 1))
  1519. type (downcase (match-string 3))
  1520. t1 (if (equal type "quote") "blockquote" type))
  1521. (setq beg (match-beginning 0)
  1522. beg1 (1+ (match-end 0)))
  1523. (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
  1524. (setq end (1+ (point-at-eol))
  1525. end1 (1- (match-beginning 0)))
  1526. (setq content (org-remove-indentation (buffer-substring beg1 end1)))
  1527. (setq content (concat "ORG-" (upcase t1) "-START\n"
  1528. content "\n"
  1529. "ORG-" (upcase t1) "-END\n"))
  1530. (delete-region beg end)
  1531. (insert (org-add-props content nil 'original-indentation ind))))))
  1532. (defun org-export-attach-captions-and-attributes (backend target-alist)
  1533. "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
  1534. If the next thing following is a table, add the text properties to the first
  1535. table line. If it is a link, add it to the line containing the link."
  1536. (goto-char (point-min))
  1537. (remove-text-properties (point-min) (point-max)
  1538. '(org-caption nil org-attributes nil))
  1539. (let ((case-fold-search t)
  1540. (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
  1541. "\\|"
  1542. "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
  1543. "\\|"
  1544. "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
  1545. "\\|"
  1546. "^[ \t]*|[^-]"
  1547. "\\|"
  1548. "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
  1549. cap attr label)
  1550. (while (re-search-forward re nil t)
  1551. (cond
  1552. ((match-end 1)
  1553. (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
  1554. ((match-end 2)
  1555. (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
  1556. ((match-end 3)
  1557. (setq label (org-trim (match-string 3))))
  1558. (t
  1559. (add-text-properties (point-at-bol) (point-at-eol)
  1560. (list 'org-caption cap
  1561. 'org-attributes attr
  1562. 'org-label label))
  1563. (if label (push (cons label label) target-alist))
  1564. (setq cap nil attr nil label nil)))))
  1565. target-alist)
  1566. (defun org-export-remove-comment-blocks-and-subtrees ()
  1567. "Remove the comment environment, and also commented subtrees."
  1568. (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  1569. (case-fold-search nil))
  1570. ;; Remove comment environment
  1571. (goto-char (point-min))
  1572. (while (re-search-forward
  1573. "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
  1574. (replace-match "" t t))
  1575. ;; Remove subtrees that are commented
  1576. (goto-char (point-min))
  1577. (while (re-search-forward re-commented nil t)
  1578. (goto-char (match-beginning 0))
  1579. (delete-region (point) (org-end-of-subtree t)))))
  1580. (defun org-export-handle-comments (commentsp)
  1581. "Remove comments, or convert to backend-specific format.
  1582. COMMENTSP can be a format string for publishing comments.
  1583. When it is nil, all comments will be removed."
  1584. (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)")
  1585. pos)
  1586. (goto-char (point-min))
  1587. (while (or (looking-at re)
  1588. (re-search-forward re nil t))
  1589. (setq pos (match-beginning 0))
  1590. (if (and commentsp
  1591. (not (equal (char-before (match-end 1)) ?+)))
  1592. (progn (add-text-properties
  1593. (match-beginning 0) (match-end 0) '(org-protected t))
  1594. (replace-match (format commentsp (match-string 2)) t t))
  1595. (goto-char (1+ pos))
  1596. (org-if-unprotected
  1597. (replace-match "")
  1598. (goto-char (max (point-min) (1- pos))))))))
  1599. (defun org-export-mark-radio-links ()
  1600. "Find all matches for radio targets and turn them into internal links."
  1601. (let ((re-radio (and org-target-link-regexp
  1602. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
  1603. (goto-char (point-min))
  1604. (when re-radio
  1605. (while (re-search-forward re-radio nil t)
  1606. (org-if-unprotected
  1607. (replace-match "\\1[[\\2]]"))))))
  1608. (defun org-export-remove-special-table-lines ()
  1609. "Remove tables lines that are used for internal purposes."
  1610. (goto-char (point-min))
  1611. (while (re-search-forward "^[ \t]*|" nil t)
  1612. (beginning-of-line 1)
  1613. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1614. (and (looking-at ".*?| *<[0-9]+> *|")
  1615. (not (looking-at ".*?| *[^ <|]"))))
  1616. (delete-region (max (point-min) (1- (point-at-bol)))
  1617. (point-at-eol))
  1618. (end-of-line 1))))
  1619. (defun org-export-normalize-links ()
  1620. "Convert all links to bracket links, and expand link abbreviations."
  1621. (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  1622. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
  1623. (goto-char (point-min))
  1624. (while (re-search-forward re-plain-link nil t)
  1625. (goto-char (1- (match-end 0)))
  1626. (org-if-unprotected-at (1+ (match-beginning 0))
  1627. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1628. ":" (match-string 3) "]]")))
  1629. ;; added 'org-link face to links
  1630. (put-text-property 0 (length s) 'face 'org-link s)
  1631. (replace-match s t t))))
  1632. (goto-char (point-min))
  1633. (while (re-search-forward re-angle-link nil t)
  1634. (goto-char (1- (match-end 0)))
  1635. (org-if-unprotected
  1636. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1637. ":" (match-string 3) "]]")))
  1638. (put-text-property 0 (length s) 'face 'org-link s)
  1639. (replace-match s t t))))
  1640. (goto-char (point-min))
  1641. (while (re-search-forward org-bracket-link-regexp nil t)
  1642. (goto-char (1- (match-end 0)))
  1643. (org-if-unprotected
  1644. (let* ((xx (save-match-data
  1645. (org-translate-link
  1646. (org-link-expand-abbrev (match-string 1)))))
  1647. (s (concat
  1648. "[[" (org-add-props (copy-sequence xx)
  1649. nil 'org-protected t)
  1650. "]"
  1651. (if (match-end 3)
  1652. (match-string 2)
  1653. (concat "[" (copy-sequence xx)
  1654. "]"))
  1655. "]")))
  1656. (put-text-property 0 (length s) 'face 'org-link s)
  1657. (replace-match s t t))))))
  1658. (defun org-export-concatenate-multiline-links ()
  1659. "Find multi-line links and put it all into a single line.
  1660. This is to make sure that the line-processing export backends
  1661. can work correctly."
  1662. (goto-char (point-min))
  1663. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1664. (org-if-unprotected
  1665. (replace-match "\\1 \\3")
  1666. (goto-char (match-beginning 0)))))
  1667. (defun org-export-concatenate-multiline-emphasis ()
  1668. "Find multi-line emphasis and put it all into a single line.
  1669. This is to make sure that the line-processing export backends
  1670. can work correctly."
  1671. (goto-char (point-min))
  1672. (while (re-search-forward org-emph-re nil t)
  1673. (if (and (not (= (char-after (match-beginning 3))
  1674. (char-after (match-beginning 4))))
  1675. (save-excursion (goto-char (match-beginning 0))
  1676. (save-match-data (not (org-at-table-p)))))
  1677. (org-if-unprotected
  1678. (subst-char-in-region (match-beginning 0) (match-end 0)
  1679. ?\n ?\ t)
  1680. (goto-char (1- (match-end 0))))
  1681. (goto-char (1+ (match-beginning 0))))))
  1682. (defun org-export-grab-title-from-buffer ()
  1683. "Get a title for the current document, from looking at the buffer."
  1684. (let ((inhibit-read-only t))
  1685. (save-excursion
  1686. (goto-char (point-min))
  1687. (let ((end (if (looking-at org-outline-regexp)
  1688. (point)
  1689. (save-excursion (outline-next-heading) (point)))))
  1690. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1691. ;; Mark the line so that it will not be exported as normal text.
  1692. (org-unmodified
  1693. (add-text-properties (match-beginning 0) (match-end 0)
  1694. (list :org-license-to-kill t)))
  1695. ;; Return the title string
  1696. (org-trim (match-string 0)))))))
  1697. (defun org-export-get-title-from-subtree ()
  1698. "Return subtree title and exclude it from export."
  1699. (let (title (rbeg (region-beginning)) (rend (region-end)))
  1700. (save-excursion
  1701. (goto-char rbeg)
  1702. (when (and (org-at-heading-p)
  1703. (>= (org-end-of-subtree t t) rend))
  1704. ;; This is a subtree, we take the title from the first heading
  1705. (goto-char rbeg)
  1706. (looking-at org-todo-line-regexp)
  1707. (setq title (match-string 3))
  1708. (org-unmodified
  1709. (add-text-properties (point) (1+ (point-at-eol))
  1710. (list :org-license-to-kill t)))
  1711. (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
  1712. title))
  1713. (defun org-solidify-link-text (s &optional alist)
  1714. "Take link text and make a safe target out of it."
  1715. (save-match-data
  1716. (let* ((rtn
  1717. (mapconcat
  1718. 'identity
  1719. (org-split-string s "[ \t\r\n]+") "=="))
  1720. (a (assoc rtn alist)))
  1721. (or (cdr a) rtn))))
  1722. (defun org-get-min-level (lines &optional offset)
  1723. "Get the minimum level in LINES."
  1724. (let ((re "^\\(\\*+\\) ") l)
  1725. (catch 'exit
  1726. (while (setq l (pop lines))
  1727. (if (string-match re l)
  1728. (throw 'exit (org-tr-level (- (length (match-string 1 l))
  1729. (or offset 0))))))
  1730. 1)))
  1731. ;; Variable holding the vector with section numbers
  1732. (defvar org-section-numbers (make-vector org-level-max 0))
  1733. (defun org-init-section-numbers ()
  1734. "Initialize the vector for the section numbers."
  1735. (let* ((level -1)
  1736. (numbers (nreverse (org-split-string "" "\\.")))
  1737. (depth (1- (length org-section-numbers)))
  1738. (i depth) number-string)
  1739. (while (>= i 0)
  1740. (if (> i level)
  1741. (aset org-section-numbers i 0)
  1742. (setq number-string (or (car numbers) "0"))
  1743. (if (string-match "\\`[A-Z]\\'" number-string)
  1744. (aset org-section-numbers i
  1745. (- (string-to-char number-string) ?A -1))
  1746. (aset org-section-numbers i (string-to-number number-string)))
  1747. (pop numbers))
  1748. (setq i (1- i)))))
  1749. (defun org-section-number (&optional level)
  1750. "Return a string with the current section number.
  1751. When LEVEL is non-nil, increase section numbers on that level."
  1752. (let* ((depth (1- (length org-section-numbers)))
  1753. (string "")
  1754. (fmts (car org-export-section-number-format))
  1755. (term (cdr org-export-section-number-format))
  1756. (sep "")
  1757. ctype fmt idx n)
  1758. (when level
  1759. (when (> level -1)
  1760. (aset org-section-numbers
  1761. level (1+ (aref org-section-numbers level))))
  1762. (setq idx (1+ level))
  1763. (while (<= idx depth)
  1764. (if (not (= idx 1))
  1765. (aset org-section-numbers idx 0))
  1766. (setq idx (1+ idx))))
  1767. (setq idx 0)
  1768. (while (<= idx depth)
  1769. (when (> (aref org-section-numbers idx) 0)
  1770. (setq fmt (or (pop fmts) fmt)
  1771. ctype (car fmt)
  1772. n (aref org-section-numbers idx)
  1773. string (if (> n 0)
  1774. (concat string sep (org-number-to-counter n ctype))
  1775. (concat string ".0"))
  1776. sep (nth 1 fmt)))
  1777. (setq idx (1+ idx)))
  1778. (save-match-data
  1779. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1780. (setq string (replace-match "" t nil string)))
  1781. (if (string-match "\\(\\.0\\)+\\'" string)
  1782. (setq string (replace-match "" t nil string))))
  1783. (concat string term)))
  1784. (defun org-number-to-counter (n type)
  1785. "Concert number N to a string counter, according to TYPE.
  1786. TYPE must be a string, any of:
  1787. 1 number
  1788. A A,B,....
  1789. a a,b,....
  1790. I upper case roman numeral
  1791. i lower case roman numeral"
  1792. (cond
  1793. ((equal type "1") (number-to-string n))
  1794. ((equal type "A") (char-to-string (+ ?A n -1)))
  1795. ((equal type "a") (char-to-string (+ ?a n -1)))
  1796. ((equal type "I") (org-number-to-roman n))
  1797. ((equal type "i") (downcase (org-number-to-roman n)))
  1798. (t (error "Invalid counter type `%s'" type))))
  1799. (defun org-number-to-roman (n)
  1800. "Convert integer N into a roman numeral."
  1801. (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
  1802. ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
  1803. ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
  1804. ( 1 . "I")))
  1805. (res ""))
  1806. (if (<= n 0)
  1807. (number-to-string n)
  1808. (while roman
  1809. (if (>= n (caar roman))
  1810. (setq n (- n (caar roman))
  1811. res (concat res (cdar roman)))
  1812. (pop roman)))
  1813. res)))
  1814. ;;; Macros
  1815. (defun org-export-preprocess-apply-macros ()
  1816. "Replace macro references."
  1817. (goto-char (point-min))
  1818. (let (sy val key args args2 s n)
  1819. (while (re-search-forward
  1820. "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
  1821. nil t)
  1822. (setq key (downcase (match-string 1))
  1823. args (match-string 3))
  1824. (when (setq val (or (plist-get org-export-opt-plist
  1825. (intern (concat ":macro-" key)))
  1826. (plist-get org-export-opt-plist
  1827. (intern (concat ":" key)))))
  1828. (save-match-data
  1829. (when args
  1830. (setq args (org-split-string args ";") args2 nil)
  1831. (while args
  1832. (while (string-match "\\\\\\'" (car args))
  1833. ;; repair bad splits
  1834. (setcar (cdr args) (concat (substring (car args) 0 -1)
  1835. ";" (nth 1 args)))
  1836. (pop args))
  1837. (push (pop args) args2))
  1838. (setq args (nreverse args2))
  1839. (setq s 0)
  1840. (while (string-match "\\$\\([0-9]+\\)" val s)
  1841. (setq s (1+ (match-beginning 0))
  1842. n (string-to-number (match-string 1 val)))
  1843. (and (>= (length args) n)
  1844. (setq val (replace-match (nth (1- n) args) t t val)))))
  1845. (when (string-match "\\`(eval\\>" val)
  1846. (setq val (eval (read val))))
  1847. (if (and val (not (stringp val)))
  1848. (setq val (format "%s" val))))
  1849. (and (stringp val)
  1850. (replace-match val t t))))))
  1851. (defun org-export-apply-macros-in-string (s)
  1852. "Apply the macros in string S."
  1853. (when s
  1854. (with-temp-buffer
  1855. (insert s)
  1856. (org-export-preprocess-apply-macros)
  1857. (buffer-string))))
  1858. ;;; Include files
  1859. (defun org-export-handle-include-files ()
  1860. "Include the contents of include files, with proper formatting."
  1861. (let ((case-fold-search t)
  1862. params file markup lang start end prefix prefix1 switches)
  1863. (goto-char (point-min))
  1864. (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
  1865. (setq params (read (concat "(" (match-string 1) ")"))
  1866. prefix (org-get-and-remove-property 'params :prefix)
  1867. prefix1 (org-get-and-remove-property 'params :prefix1)
  1868. file (org-symname-or-string (pop params))
  1869. markup (org-symname-or-string (pop params))
  1870. lang (and (member markup '("src" "SRC"))
  1871. (org-symname-or-string (pop params)))
  1872. switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
  1873. (delete-region (match-beginning 0) (match-end 0))
  1874. (if (or (not file)
  1875. (not (file-exists-p file))
  1876. (not (file-readable-p file)))
  1877. (insert (format "CANNOT INCLUDE FILE %s" file))
  1878. (when markup
  1879. (if (equal (downcase markup) "src")
  1880. (setq start (format "#+begin_src %s %s\n"
  1881. (or lang "fundamental")
  1882. (or switches ""))
  1883. end "#+end_src")
  1884. (setq start (format "#+begin_%s %s\n" markup switches)
  1885. end (format "#+end_%s" markup))))
  1886. (insert (or start ""))
  1887. (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
  1888. (or (bolp) (newline))
  1889. (insert (or end ""))))))
  1890. (defun org-get-file-contents (file &optional prefix prefix1)
  1891. "Get the contents of FILE and return them as a string.
  1892. If PREFIX is a string, prepend it to each line. If PREFIX1
  1893. is a string, prepend it to the first line instead of PREFIX."
  1894. (with-temp-buffer
  1895. (insert-file-contents file)
  1896. (when (or prefix prefix1)
  1897. (goto-char (point-min))
  1898. (while (not (eobp))
  1899. (insert (or prefix1 prefix))
  1900. (setq prefix1 nil)
  1901. (beginning-of-line 2)))
  1902. (buffer-string)))
  1903. (defun org-get-and-remove-property (listvar prop)
  1904. "Check if the value of LISTVAR contains PROP as a property.
  1905. If yes, return the value of that property (i.e. the element following
  1906. in the list) and remove property and value from the list in LISTVAR."
  1907. (let ((list (symbol-value listvar)) m v)
  1908. (when (setq m (member prop list))
  1909. (setq v (nth 1 m))
  1910. (if (equal (car list) prop)
  1911. (set listvar (cddr list))
  1912. (setcdr (nthcdr (- (length list) (length m) 1) list)
  1913. (cddr m))
  1914. (set listvar list)))
  1915. v))
  1916. (defun org-symname-or-string (s)
  1917. (if (symbolp s)
  1918. (if s (symbol-name s) s)
  1919. s))
  1920. ;;; Fontification and line numbers for code examples
  1921. (defvar org-export-last-code-line-counter-value 0)
  1922. (defun org-export-replace-src-segments-and-examples (backend)
  1923. "Replace source code segments with special code for export."
  1924. (setq org-export-last-code-line-counter-value 0)
  1925. (let ((case-fold-search t)
  1926. lang code trans opts indent)
  1927. (goto-char (point-min))
  1928. (while (re-search-forward
  1929. "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
  1930. nil t)
  1931. (if (match-end 1)
  1932. ;; src segments
  1933. (setq lang (match-string 3)
  1934. opts (match-string 4)
  1935. code (match-string 5)
  1936. indent (length (match-string 2)))
  1937. (setq lang nil
  1938. opts (match-string 8)
  1939. code (match-string 9)
  1940. indent (length (match-string 7))))
  1941. (setq trans (org-export-format-source-code-or-example
  1942. backend lang code opts indent))
  1943. (replace-match trans t t))))
  1944. (defvar htmlp) ;; dynamically scoped
  1945. (defvar latexp) ;; dynamically scoped
  1946. (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
  1947. (defun org-export-format-source-code-or-example
  1948. (backend lang code &optional opts indent)
  1949. "Format CODE from language LANG and return it formatted for export.
  1950. If LANG is nil, do not add any fontification.
  1951. OPTS contains formatting optons, like `-n' for triggering numbering lines,
  1952. and `+n' for continuing previous numering.
  1953. Code formatting according to language currently only works for HTML.
  1954. Numbering lines works for all three major backends (html, latex, and ascii).
  1955. INDENT was the original indentation of the block."
  1956. (save-match-data
  1957. (let (num cont rtn rpllbl keepp textareap cols rows fmt)
  1958. (setq opts (or opts "")
  1959. num (string-match "[-+]n\\>" opts)
  1960. cont (string-match "\\+n\\>" opts)
  1961. rpllbl (string-match "-r\\>" opts)
  1962. keepp (string-match "-k\\>" opts)
  1963. textareap (string-match "-t\\>" opts)
  1964. cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
  1965. (string-to-number (match-string 1 opts))
  1966. 80)
  1967. rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
  1968. (string-to-number (match-string 1 opts))
  1969. (org-count-lines code))
  1970. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  1971. (match-string 1 opts)))
  1972. (when (and textareap (eq backend 'html))
  1973. ;; we cannot use numbering or highlighting.
  1974. (setq num nil cont nil lang nil))
  1975. (if keepp (setq rpllbl 'keep))
  1976. (setq rtn (org-remove-indentation code))
  1977. (when (string-match "^," rtn)
  1978. (setq rtn (with-temp-buffer
  1979. (insert rtn)
  1980. ;; Free up the protected lines
  1981. (goto-char (point-min))
  1982. (while (re-search-forward "^," nil t)
  1983. (if (or (equal lang "org")
  1984. (save-match-data
  1985. (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
  1986. (replace-match ""))
  1987. (end-of-line 1))
  1988. (buffer-string))))
  1989. ;; Now backend-specific coding
  1990. (setq rtn
  1991. (cond
  1992. ((eq backend 'docbook)
  1993. (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
  1994. (concat "\n#+BEGIN_DOCBOOK\n"
  1995. (org-add-props (concat "<programlisting><![CDATA["
  1996. rtn
  1997. "]]>\n</programlisting>\n")
  1998. '(org-protected t))
  1999. "#+END_DOCBOOK\n"))
  2000. ((eq backend 'html)
  2001. ;; We are exporting to HTML
  2002. (when lang
  2003. (require 'htmlize nil t)
  2004. (when (not (fboundp 'htmlize-region-for-paste))
  2005. ;; we do not have htmlize.el, or an old version of it
  2006. (setq lang nil)
  2007. (message
  2008. "htmlize.el 1.34 or later is needed for source code formatting")))
  2009. (if lang
  2010. (let* ((mode (and lang (intern (concat lang "-mode"))))
  2011. (org-inhibit-startup t)
  2012. (org-startup-folded nil))
  2013. (setq rtn
  2014. (with-temp-buffer
  2015. (insert rtn)
  2016. (if (functionp mode)
  2017. (funcall mode)
  2018. (fundamental-mode))
  2019. (font-lock-fontify-buffer)
  2020. (org-src-mode)
  2021. (set-buffer-modified-p nil)
  2022. (org-export-htmlize-region-for-paste
  2023. (point-min) (point-max))))
  2024. (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
  2025. (setq rtn (replace-match
  2026. (format "<pre class=\"src src-%s\">\n" lang)
  2027. t t rtn))))
  2028. (if textareap
  2029. (setq rtn (concat
  2030. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
  2031. cols rows)
  2032. rtn "</textarea>\n</p>\n"))
  2033. (with-temp-buffer
  2034. (insert rtn)
  2035. (goto-char (point-min))
  2036. (while (re-search-forward "[<>&]" nil t)
  2037. (replace-match (cdr (assq (char-before)
  2038. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  2039. t t))
  2040. (setq rtn (buffer-string)))
  2041. (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
  2042. (unless textareap
  2043. (setq rtn (org-export-number-lines rtn 'html 1 1 num
  2044. cont rpllbl fmt)))
  2045. (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
  2046. ((eq backend 'latex)
  2047. (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
  2048. (concat "\n#+BEGIN_LaTeX\n"
  2049. (org-add-props (concat (car org-export-latex-verbatim-wrap)
  2050. rtn (cdr org-export-latex-verbatim-wrap))
  2051. '(org-protected t))
  2052. "#+END_LaTeX\n\n"))
  2053. ((eq backend 'ascii)
  2054. ;; This is not HTML or LaTeX, so just make it an example.
  2055. (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
  2056. (concat "#+BEGIN_ASCII\n"
  2057. (org-add-props
  2058. (concat
  2059. (mapconcat
  2060. (lambda (l) (concat " " l))
  2061. (org-split-string rtn "\n")
  2062. "\n")
  2063. "\n")
  2064. '(org-protected t))
  2065. "#+END_ASCII\n"))))
  2066. (org-add-props rtn nil 'original-indentation indent))))
  2067. (defun org-export-number-lines (text backend
  2068. &optional skip1 skip2 number cont
  2069. replace-labels label-format)
  2070. (if (and (not number) (not (eq replace-labels 'keep)))
  2071. (setq replace-labels nil)) ;; must use names if no numbers
  2072. (setq skip1 (or skip1 0) skip2 (or skip2 0))
  2073. (if (not cont) (setq org-export-last-code-line-counter-value 0))
  2074. (with-temp-buffer
  2075. (insert text)
  2076. (goto-char (point-max))
  2077. (skip-chars-backward " \t\n\r")
  2078. (delete-region (point) (point-max))
  2079. (beginning-of-line (- 1 skip2))
  2080. (let* ((last (org-current-line))
  2081. (n org-export-last-code-line-counter-value)
  2082. (nmax (+ n (- last skip1)))
  2083. (fmt (format "%%%dd: " (length (number-to-string nmax))))
  2084. (fm
  2085. (cond
  2086. ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
  2087. fmt))
  2088. ((eq backend 'ascii) fmt)
  2089. ((eq backend 'latex) fmt)
  2090. ((eq backend 'docbook) fmt)
  2091. (t "")))
  2092. (label-format (or label-format org-coderef-label-format))
  2093. (label-pre (if (string-match "%s" label-format)
  2094. (substring label-format 0 (match-beginning 0))
  2095. label-format))
  2096. (label-post (if (string-match "%s" label-format)
  2097. (substring label-format (match-end 0))
  2098. ""))
  2099. (lbl-re
  2100. (concat
  2101. ".*?\\S-.*?\\([ \t]*\\("
  2102. (regexp-quote label-pre)
  2103. "\\([-a-zA-Z0-9_]+\\)"
  2104. (regexp-quote label-post)
  2105. "\\)\\)"))
  2106. ref)
  2107. (goto-line (1+ skip1))
  2108. (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
  2109. (if number
  2110. (insert (format fm (incf n)))
  2111. (forward-char 1))
  2112. (when (and (not (eq replace-labels 'keep))
  2113. (looking-at lbl-re))
  2114. (setq ref (match-string 3))
  2115. (if replace-labels
  2116. (progn
  2117. (delete-region (match-beginning 1) (match-end 1))
  2118. (push (cons ref n) org-export-code-refs))
  2119. (goto-char (match-beginning 2))
  2120. (delete-region (match-beginning 2) (match-end 2))
  2121. (insert "(" ref ")")
  2122. (push (cons ref (concat "(" ref ")")) org-export-code-refs))
  2123. (when (eq backend 'html)
  2124. (save-excursion
  2125. (beginning-of-line 1)
  2126. (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
  2127. ref))
  2128. (end-of-line 1)
  2129. (insert "</span>")))))
  2130. (setq org-export-last-code-line-counter-value n)
  2131. (goto-char (point-max))
  2132. (newline)
  2133. (buffer-string))))
  2134. (defun org-search-todo-below (line lines level)
  2135. "Search the subtree below LINE for any TODO entries."
  2136. (let ((rest (cdr (memq line lines)))
  2137. (re org-todo-line-regexp)
  2138. line lv todo)
  2139. (catch 'exit
  2140. (while (setq line (pop rest))
  2141. (if (string-match re line)
  2142. (progn
  2143. (setq lv (- (match-end 1) (match-beginning 1))
  2144. todo (and (match-beginning 2)
  2145. (not (member (match-string 2 line)
  2146. org-done-keywords))))
  2147. ; TODO, not DONE
  2148. (if (<= lv level) (throw 'exit nil))
  2149. (if todo (throw 'exit t))))))))
  2150. ;;;###autoload
  2151. (defun org-export-visible (type arg)
  2152. "Create a copy of the visible part of the current buffer, and export it.
  2153. The copy is created in a temporary buffer and removed after use.
  2154. TYPE is the final key (as a string) that also select the export command in
  2155. the `C-c C-e' export dispatcher.
  2156. As a special case, if the you type SPC at the prompt, the temporary
  2157. org-mode file will not be removed but presented to you so that you can
  2158. continue to use it. The prefix arg ARG is passed through to the exporting
  2159. command."
  2160. (interactive
  2161. (list (progn
  2162. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
  2163. (read-char-exclusive))
  2164. current-prefix-arg))
  2165. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
  2166. (error "Invalid export key"))
  2167. (let* ((binding (cdr (assoc type
  2168. '((?a . org-export-as-ascii)
  2169. (?A . org-export-as-ascii-to-buffer)
  2170. (?\C-a . org-export-as-ascii)
  2171. (?b . org-export-as-html-and-open)
  2172. (?\C-b . org-export-as-html-and-open)
  2173. (?h . org-export-as-html)
  2174. (?H . org-export-as-html-to-buffer)
  2175. (?R . org-export-region-as-html)
  2176. (?D . org-export-as-docbook)
  2177. (?x . org-export-as-xoxo)))))
  2178. (keepp (equal type ?\ ))
  2179. (file buffer-file-name)
  2180. (buffer (get-buffer-create "*Org Export Visible*"))
  2181. s e)
  2182. ;; Need to hack the drawers here.
  2183. (save-excursion
  2184. (goto-char (point-min))
  2185. (while (re-search-forward org-drawer-regexp nil t)
  2186. (goto-char (match-beginning 1))
  2187. (or (org-invisible-p) (org-flag-drawer nil))))
  2188. (with-current-buffer buffer (erase-buffer))
  2189. (save-excursion
  2190. (setq s (goto-char (point-min)))
  2191. (while (not (= (point) (point-max)))
  2192. (goto-char (org-find-invisible))
  2193. (append-to-buffer buffer s (point))
  2194. (setq s (goto-char (org-find-visible))))
  2195. (org-cycle-hide-drawers 'all)
  2196. (goto-char (point-min))
  2197. (unless keepp
  2198. ;; Copy all comment lines to the end, to make sure #+ settings are
  2199. ;; still available for the second export step. Kind of a hack, but
  2200. ;; does do the trick.
  2201. (if (looking-at "#[^\r\n]*")
  2202. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  2203. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  2204. (append-to-buffer buffer (1+ (match-beginning 0))
  2205. (min (point-max) (1+ (match-end 0))))))
  2206. (set-buffer buffer)
  2207. (let ((buffer-file-name file)
  2208. (org-inhibit-startup t))
  2209. (org-mode)
  2210. (show-all)
  2211. (unless keepp (funcall binding arg))))
  2212. (if (not keepp)
  2213. (kill-buffer buffer)
  2214. (switch-to-buffer-other-window buffer)
  2215. (goto-char (point-min)))))
  2216. (defun org-find-visible ()
  2217. (let ((s (point)))
  2218. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2219. (get-char-property s 'invisible)))
  2220. s))
  2221. (defun org-find-invisible ()
  2222. (let ((s (point)))
  2223. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2224. (not (get-char-property s 'invisible))))
  2225. s))
  2226. (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el
  2227. ;;;###autoload
  2228. (defun org-export-as-org (arg &optional hidden ext-plist
  2229. to-buffer body-only pub-dir)
  2230. "Make a copy wiht not-exporting stuff removed.
  2231. The purpose of this function is to provide a way to export the source
  2232. Org file of a webpage in Org format, but with sensitive and/or irrelevant
  2233. stuff removed. This command will remove the following:
  2234. - archived trees (if the variable `org-export-with-archived-trees' is nil)
  2235. - comment blocks and trees starting with the COMMENT keyword
  2236. - only trees that are consistent with `org-export-select-tags'
  2237. and `org-export-exclude-tags'.
  2238. The only arguments that will be used are EXT-PLIST and PUB-DIR,
  2239. all the others will be ignored (but are present so that the general
  2240. mechanism to call publishing functions will work).
  2241. EXT-PLIST is a property list with external parameters overriding
  2242. org-mode's default settings, but still inferior to file-local
  2243. settings. When PUB-DIR is set, use this as the publishing
  2244. directory."
  2245. (interactive "P")
  2246. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  2247. ext-plist
  2248. (org-infile-export-plist)))
  2249. (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2250. (filename (concat (file-name-as-directory
  2251. (or pub-dir
  2252. (org-export-directory :org opt-plist)))
  2253. (file-name-sans-extension
  2254. (file-name-nondirectory bfname))
  2255. ".org"))
  2256. (filename (and filename
  2257. (if (equal (file-truename filename)
  2258. (file-truename bfname))
  2259. (concat filename "-source")
  2260. filename)))
  2261. (backup-inhibited t)
  2262. (buffer (find-file-noselect filename))
  2263. (region (buffer-string)))
  2264. (save-excursion
  2265. (switch-to-buffer buffer)
  2266. (erase-buffer)
  2267. (insert region)
  2268. (let ((org-inhibit-startup t)) (org-mode))
  2269. ;; Get rid of archived trees
  2270. (org-export-remove-archived-trees (plist-get opt-plist :archived-trees))
  2271. ;; Remove comment environment and comment subtrees
  2272. (org-export-remove-comment-blocks-and-subtrees)
  2273. ;; Get rid of excluded trees
  2274. (org-export-handle-export-tags (plist-get opt-plist :select-tags)
  2275. (plist-get opt-plist :exclude-tags))
  2276. (when (or (plist-get opt-plist :plain-source)
  2277. (not (or (plist-get opt-plist :plain-source)
  2278. (plist-get opt-plist :htmlized-source))))
  2279. ;; Either nothing special is requested (default call)
  2280. ;; or the plain source is explicitly requested
  2281. ;; so: save it
  2282. (save-buffer))
  2283. (when (plist-get opt-plist :htmlized-source)
  2284. ;; Make the htmlized version
  2285. (require 'htmlize)
  2286. (require 'org-html)
  2287. (font-lock-fontify-buffer)
  2288. (let* ((htmlize-output-type 'css)
  2289. (newbuf (htmlize-buffer)))
  2290. (with-current-buffer newbuf
  2291. (when org-export-htmlized-org-css-url
  2292. (goto-char (point-min))
  2293. (and (re-search-forward
  2294. "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
  2295. nil t)
  2296. (replace-match
  2297. (format
  2298. "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
  2299. org-export-htmlized-org-css-url)
  2300. t t)))
  2301. (write-file (concat filename ".html")))
  2302. (kill-buffer newbuf)))
  2303. (set-buffer-modified-p nil)
  2304. (kill-buffer (current-buffer)))))
  2305. (defvar org-archive-location) ;; gets loaded with the org-archive require.
  2306. (defun org-get-current-options ()
  2307. "Return a string with current options as keyword options.
  2308. Does include HTML export options as well as TODO and CATEGORY stuff."
  2309. (require 'org-archive)
  2310. (format
  2311. "#+TITLE: %s
  2312. #+AUTHOR: %s
  2313. #+EMAIL: %s
  2314. #+DATE: %s
  2315. #+DESCRIPTION:
  2316. #+KEYWORDS:
  2317. #+LANGUAGE: %s
  2318. #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
  2319. #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
  2320. %s
  2321. #+EXPORT_SELECT_TAGS: %s
  2322. #+EXPORT_EXCLUDE_TAGS: %s
  2323. #+LINK_UP: %s
  2324. #+LINK_HOME: %s
  2325. #+CATEGORY: %s
  2326. #+SEQ_TODO: %s
  2327. #+TYP_TODO: %s
  2328. #+PRIORITIES: %c %c %c
  2329. #+DRAWERS: %s
  2330. #+STARTUP: %s %s %s %s %s
  2331. #+TAGS: %s
  2332. #+FILETAGS: %s
  2333. #+ARCHIVE: %s
  2334. #+LINK: %s
  2335. "
  2336. (buffer-name) (user-full-name) user-mail-address
  2337. (format-time-string (substring (car org-time-stamp-formats) 1 -1))
  2338. org-export-default-language
  2339. org-export-headline-levels
  2340. org-export-with-section-numbers
  2341. org-export-with-toc
  2342. org-export-preserve-breaks
  2343. org-export-html-expand
  2344. org-export-with-fixed-width
  2345. org-export-with-tables
  2346. org-export-with-sub-superscripts
  2347. org-export-with-special-strings
  2348. org-export-with-footnotes
  2349. org-export-with-emphasize
  2350. org-export-with-timestamps
  2351. org-export-with-TeX-macros
  2352. org-export-with-LaTeX-fragments
  2353. org-export-skip-text-before-1st-heading
  2354. org-export-with-drawers
  2355. org-export-with-todo-keywords
  2356. org-export-with-priority
  2357. org-export-with-tags
  2358. (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
  2359. (mapconcat 'identity org-export-select-tags " ")
  2360. (mapconcat 'identity org-export-exclude-tags " ")
  2361. org-export-html-link-up
  2362. org-export-html-link-home
  2363. (or (ignore-errors
  2364. (file-name-sans-extension
  2365. (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
  2366. "NOFILENAME")
  2367. "TODO FEEDBACK VERIFY DONE"
  2368. "Me Jason Marie DONE"
  2369. org-highest-priority org-lowest-priority org-default-priority
  2370. (mapconcat 'identity org-drawers " ")
  2371. (cdr (assoc org-startup-folded
  2372. '((nil . "showall") (t . "overview") (content . "content"))))
  2373. (if org-odd-levels-only "odd" "oddeven")
  2374. (if org-hide-leading-stars "hidestars" "showstars")
  2375. (if org-startup-align-all-tables "align" "noalign")
  2376. (cond ((eq org-log-done t) "logdone")
  2377. ((equal org-log-done 'note) "lognotedone")
  2378. ((not org-log-done) "nologdone"))
  2379. (or (mapconcat (lambda (x)
  2380. (cond
  2381. ((equal '(:startgroup) x) "{")
  2382. ((equal '(:endgroup) x) "}")
  2383. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  2384. (t (car x))))
  2385. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  2386. (mapconcat 'identity org-file-tags " ")
  2387. org-archive-location
  2388. "org file:~/org/%s.org"
  2389. ))
  2390. ;;;###autoload
  2391. (defun org-insert-export-options-template ()
  2392. "Insert into the buffer a template with information for exporting."
  2393. (interactive)
  2394. (if (not (bolp)) (newline))
  2395. (let ((s (org-get-current-options)))
  2396. (and (string-match "#\\+CATEGORY" s)
  2397. (setq s (substring s 0 (match-beginning 0))))
  2398. (insert s)))
  2399. (defvar org-table-colgroup-info nil)
  2400. (defun org-table-clean-before-export (lines &optional maybe-quoted)
  2401. "Check if the table has a marking column.
  2402. If yes remove the column and the special lines."
  2403. (setq org-table-colgroup-info nil)
  2404. (if (memq nil
  2405. (mapcar
  2406. (lambda (x) (or (string-match "^[ \t]*|-" x)
  2407. (string-match
  2408. (if maybe-quoted
  2409. "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
  2410. "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
  2411. x)))
  2412. lines))
  2413. (progn
  2414. (setq org-table-clean-did-remove-column nil)
  2415. (delq nil
  2416. (mapcar
  2417. (lambda (x)
  2418. (cond
  2419. ((string-match "^[ \t]*| */ *|" x)
  2420. (setq org-table-colgroup-info
  2421. (mapcar (lambda (x)
  2422. (cond ((member x '("<" "&lt;")) :start)
  2423. ((member x '(">" "&gt;")) :end)
  2424. ((member x '("<>" "&lt;&gt;")) :startend)
  2425. (t nil)))
  2426. (org-split-string x "[ \t]*|[ \t]*")))
  2427. nil)
  2428. (t x)))
  2429. lines)))
  2430. (setq org-table-clean-did-remove-column t)
  2431. (delq nil
  2432. (mapcar
  2433. (lambda (x)
  2434. (cond
  2435. ((string-match "^[ \t]*| */ *|" x)
  2436. (setq org-table-colgroup-info
  2437. (mapcar (lambda (x)
  2438. (cond ((member x '("<" "&lt;")) :start)
  2439. ((member x '(">" "&gt;")) :end)
  2440. ((member x '("<>" "&lt;&gt;")) :startend)
  2441. (t nil)))
  2442. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  2443. nil)
  2444. ((string-match "^[ \t]*| *[!_^/] *|" x)
  2445. nil) ; ignore this line
  2446. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  2447. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  2448. ;; remove the first column
  2449. (replace-match "\\1|" t nil x))))
  2450. lines))))
  2451. (defun org-export-cleanup-toc-line (s)
  2452. "Remove tags and timestamps from lines going into the toc."
  2453. (when (memq org-export-with-tags '(not-in-toc nil))
  2454. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  2455. (setq s (replace-match "" t t s))))
  2456. (when org-export-remove-timestamps-from-toc
  2457. (while (string-match org-maybe-keyword-time-regexp s)
  2458. (setq s (replace-match "" t t s))))
  2459. (while (string-match org-bracket-link-regexp s)
  2460. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  2461. t t s)))
  2462. s)
  2463. (defun org-create-multibrace-regexp (left right n)
  2464. "Create a regular expression which will match a balanced sexp.
  2465. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  2466. as single character strings.
  2467. The regexp returned will match the entire expression including the
  2468. delimiters. It will also define a single group which contains the
  2469. match except for the outermost delimiters. The maximum depth of
  2470. stacked delimiters is N. Escaping delimiters is not possible."
  2471. (let* ((nothing (concat "[^" left right "]*?"))
  2472. (or "\\|")
  2473. (re nothing)
  2474. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  2475. (while (> n 1)
  2476. (setq n (1- n)
  2477. re (concat re or next)
  2478. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  2479. (concat left "\\(" re "\\)" right)))
  2480. (defvar org-match-substring-regexp
  2481. (concat
  2482. "\\([^\\]\\)\\([_^]\\)\\("
  2483. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2484. "\\|"
  2485. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  2486. "\\|"
  2487. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  2488. "The regular expression matching a sub- or superscript.")
  2489. (defvar org-match-substring-with-braces-regexp
  2490. (concat
  2491. "\\([^\\]\\)\\([_^]\\)\\("
  2492. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2493. "\\)")
  2494. "The regular expression matching a sub- or superscript, forcing braces.")
  2495. (defun org-get-text-property-any (pos prop &optional object)
  2496. (or (get-text-property pos prop object)
  2497. (and (setq pos (next-single-property-change pos prop object))
  2498. (get-text-property pos prop object))))
  2499. (defun org-export-get-coderef-format (path desc)
  2500. (save-match-data
  2501. (if (and desc (string-match
  2502. (regexp-quote (concat "(" path ")"))
  2503. desc))
  2504. (replace-match "%s" t t desc)
  2505. (or desc "%s"))))
  2506. (defun org-export-push-to-kill-ring (format)
  2507. "Push buffer content to kill ring.
  2508. The depends on the variable `org-export-copy-to-kill'."
  2509. (when org-export-copy-to-kill-ring
  2510. (kill-new (buffer-string))
  2511. (when (fboundp 'x-set-selection)
  2512. (ignore-errors (x-set-selection 'PRIMARY (buffer-string)))
  2513. (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string))))
  2514. (message "%s export done, pushed to kill ring and clipboard" format)))
  2515. (provide 'org-exp)
  2516. ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
  2517. ;;; org-exp.el ends here