org-exp.el 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587
  1. ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 6.00pre-1
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 3, or (at your option)
  13. ;; any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. (require 'org)
  26. (require 'org-agenda)
  27. (eval-and-compile
  28. (require 'cl))
  29. (declare-function org-export-latex-cleaned-string "org-export-latex" ())
  30. (declare-function org-agenda-skip "org-agenda" ())
  31. (defgroup org-export nil
  32. "Options for exporting org-listings."
  33. :tag "Org Export"
  34. :group 'org)
  35. (defgroup org-export-general nil
  36. "General options for exporting Org-mode files."
  37. :tag "Org Export General"
  38. :group 'org-export)
  39. ;; FIXME
  40. (defvar org-export-publishing-directory nil)
  41. (defcustom org-export-with-special-strings t
  42. "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
  43. When this option is turned on, these strings will be exported as:
  44. Org HTML LaTeX
  45. -----+----------+--------
  46. \\- &shy; \\-
  47. -- &ndash; --
  48. --- &mdash; ---
  49. ... &hellip; \ldots
  50. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
  51. :group 'org-export-translation
  52. :type 'boolean)
  53. (defcustom org-export-language-setup
  54. '(("en" "Author" "Date" "Table of Contents")
  55. ("cs" "Autor" "Datum" "Obsah")
  56. ("da" "Ophavsmand" "Dato" "Indhold")
  57. ("de" "Autor" "Datum" "Inhaltsverzeichnis")
  58. ("es" "Autor" "Fecha" "\xcdndice")
  59. ("fr" "Auteur" "Date" "Table des mati\xe8res")
  60. ("it" "Autore" "Data" "Indice")
  61. ("nl" "Auteur" "Datum" "Inhoudsopgave")
  62. ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
  63. ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
  64. "Terms used in export text, translated to different languages.
  65. Use the variable `org-export-default-language' to set the language,
  66. or use the +OPTION lines for a per-file setting."
  67. :group 'org-export-general
  68. :type '(repeat
  69. (list
  70. (string :tag "HTML language tag")
  71. (string :tag "Author")
  72. (string :tag "Date")
  73. (string :tag "Table of Contents"))))
  74. (defcustom org-export-default-language "en"
  75. "The default language of HTML export, as a string.
  76. This should have an association in `org-export-language-setup'."
  77. :group 'org-export-general
  78. :type 'string)
  79. (defcustom org-export-skip-text-before-1st-heading t
  80. "Non-nil means, skip all text before the first headline when exporting.
  81. When nil, that text is exported as well."
  82. :group 'org-export-general
  83. :type 'boolean)
  84. (defcustom org-export-headline-levels 3
  85. "The last level which is still exported as a headline.
  86. Inferior levels will produce itemize lists when exported.
  87. Note that a numeric prefix argument to an exporter function overrides
  88. this setting.
  89. This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
  90. :group 'org-export-general
  91. :type 'number)
  92. (defcustom org-export-with-section-numbers t
  93. "Non-nil means, add section numbers to headlines when exporting.
  94. This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
  95. :group 'org-export-general
  96. :type 'boolean)
  97. (defcustom org-export-with-toc t
  98. "Non-nil means, create a table of contents in exported files.
  99. The TOC contains headlines with levels up to`org-export-headline-levels'.
  100. When an integer, include levels up to N in the toc, this may then be
  101. different from `org-export-headline-levels', but it will not be allowed
  102. to be larger than the number of headline levels.
  103. When nil, no table of contents is made.
  104. Headlines which contain any TODO items will be marked with \"(*)\" in
  105. ASCII export, and with red color in HTML output, if the option
  106. `org-export-mark-todo-in-toc' is set.
  107. In HTML output, the TOC will be clickable.
  108. This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
  109. or \"toc:3\"."
  110. :group 'org-export-general
  111. :type '(choice
  112. (const :tag "No Table of Contents" nil)
  113. (const :tag "Full Table of Contents" t)
  114. (integer :tag "TOC to level")))
  115. (defcustom org-export-mark-todo-in-toc nil
  116. "Non-nil means, mark TOC lines that contain any open TODO items."
  117. :group 'org-export-general
  118. :type 'boolean)
  119. (defcustom org-export-preserve-breaks nil
  120. "Non-nil means, preserve all line breaks when exporting.
  121. Normally, in HTML output paragraphs will be reformatted. In ASCII
  122. export, line breaks will always be preserved, regardless of this variable.
  123. This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
  124. :group 'org-export-general
  125. :type 'boolean)
  126. (defcustom org-export-with-archived-trees 'headline
  127. "Whether subtrees with the ARCHIVE tag should be exported.
  128. This can have three different values
  129. nil Do not export, pretend this tree is not present
  130. t Do export the entire tree
  131. headline Only export the headline, but skip the tree below it."
  132. :group 'org-export-general
  133. :group 'org-archive
  134. :type '(choice
  135. (const :tag "not at all" nil)
  136. (const :tag "headline only" 'headline)
  137. (const :tag "entirely" t)))
  138. (defcustom org-export-author-info t
  139. "Non-nil means, insert author name and email into the exported file.
  140. This option can also be set with the +OPTIONS line,
  141. e.g. \"author-info:nil\"."
  142. :group 'org-export-general
  143. :type 'boolean)
  144. (defcustom org-export-time-stamp-file t
  145. "Non-nil means, insert a time stamp into the exported file.
  146. The time stamp shows when the file was created.
  147. This option can also be set with the +OPTIONS line,
  148. e.g. \"timestamp:nil\"."
  149. :group 'org-export-general
  150. :type 'boolean)
  151. (defcustom org-export-with-timestamps t
  152. "If nil, do not export time stamps and associated keywords."
  153. :group 'org-export-general
  154. :type 'boolean)
  155. (defcustom org-export-remove-timestamps-from-toc t
  156. "If nil, remove timestamps from the table of contents entries."
  157. :group 'org-export-general
  158. :type 'boolean)
  159. (defcustom org-export-with-tags 'not-in-toc
  160. "If nil, do not export tags, just remove them from headlines.
  161. If this is the symbol `not-in-toc', tags will be removed from table of
  162. contents entries, but still be shown in the headlines of the document.
  163. This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
  164. :group 'org-export-general
  165. :type '(choice
  166. (const :tag "Off" nil)
  167. (const :tag "Not in TOC" not-in-toc)
  168. (const :tag "On" t)))
  169. (defcustom org-export-with-drawers nil
  170. "Non-nil means, export with drawers like the property drawer.
  171. When t, all drawers are exported. This may also be a list of
  172. drawer names to export."
  173. :group 'org-export-general
  174. :type '(choice
  175. (const :tag "All drawers" t)
  176. (const :tag "None" nil)
  177. (repeat :tag "Selected drawers"
  178. (string :tag "Drawer name"))))
  179. (defgroup org-export-translation nil
  180. "Options for translating special ascii sequences for the export backends."
  181. :tag "Org Export Translation"
  182. :group 'org-export)
  183. (defcustom org-export-with-emphasize t
  184. "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
  185. If the export target supports emphasizing text, the word will be
  186. typeset in bold, italic, or underlined, respectively. Works only for
  187. single words, but you can say: I *really* *mean* *this*.
  188. Not all export backends support this.
  189. This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
  190. :group 'org-export-translation
  191. :type 'boolean)
  192. (defcustom org-export-with-footnotes t
  193. "If nil, export [1] as a footnote marker.
  194. Lines starting with [1] will be formatted as footnotes.
  195. This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
  196. :group 'org-export-translation
  197. :type 'boolean)
  198. (defcustom org-export-with-sub-superscripts t
  199. "Non-nil means, interpret \"_\" and \"^\" for export.
  200. When this option is turned on, you can use TeX-like syntax for sub- and
  201. superscripts. Several characters after \"_\" or \"^\" will be
  202. considered as a single item - so grouping with {} is normally not
  203. needed. For example, the following things will be parsed as single
  204. sub- or superscripts.
  205. 10^24 or 10^tau several digits will be considered 1 item.
  206. 10^-12 or 10^-tau a leading sign with digits or a word
  207. x^2-y^3 will be read as x^2 - y^3, because items are
  208. terminated by almost any nonword/nondigit char.
  209. x_{i^2} or x^(2-i) braces or parenthesis do grouping.
  210. Still, ambiguity is possible - so when in doubt use {} to enclose the
  211. sub/superscript. If you set this variable to the symbol `{}',
  212. the braces are *required* in order to trigger interpretations as
  213. sub/superscript. This can be helpful in documents that need \"_\"
  214. frequently in plain text.
  215. Not all export backends support this, but HTML does.
  216. This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
  217. :group 'org-export-translation
  218. :type '(choice
  219. (const :tag "Always interpret" t)
  220. (const :tag "Only with braces" {})
  221. (const :tag "Never interpret" nil)))
  222. (defcustom org-export-with-special-strings t
  223. "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
  224. When this option is turned on, these strings will be exported as:
  225. \\- : &shy;
  226. -- : &ndash;
  227. --- : &mdash;
  228. Not all export backends support this, but HTML does.
  229. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
  230. :group 'org-export-translation
  231. :type 'boolean)
  232. (defcustom org-export-with-TeX-macros t
  233. "Non-nil means, interpret simple TeX-like macros when exporting.
  234. For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
  235. No only real TeX macros will work here, but the standard HTML entities
  236. for math can be used as macro names as well. For a list of supported
  237. names in HTML export, see the constant `org-html-entities'.
  238. Not all export backends support this.
  239. This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
  240. :group 'org-export-translation
  241. :group 'org-export-latex
  242. :type 'boolean)
  243. (defcustom org-export-with-LaTeX-fragments nil
  244. "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
  245. When set, the exporter will find LaTeX environments if the \\begin line is
  246. the first non-white thing on a line. It will also find the math delimiters
  247. like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
  248. display math.
  249. This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
  250. :group 'org-export-translation
  251. :group 'org-export-latex
  252. :type 'boolean)
  253. (defcustom org-export-with-fixed-width t
  254. "Non-nil means, lines starting with \":\" will be in fixed width font.
  255. This can be used to have pre-formatted text, fragments of code etc. For
  256. example:
  257. : ;; Some Lisp examples
  258. : (while (defc cnt)
  259. : (ding))
  260. will be looking just like this in also HTML. See also the QUOTE keyword.
  261. Not all export backends support this.
  262. This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
  263. :group 'org-export-translation
  264. :type 'boolean)
  265. (defcustom org-match-sexp-depth 3
  266. "Number of stacked braces for sub/superscript matching.
  267. This has to be set before loading org.el to be effective."
  268. :group 'org-export-translation
  269. :type 'integer)
  270. (defgroup org-export-tables nil
  271. "Options for exporting tables in Org-mode."
  272. :tag "Org Export Tables"
  273. :group 'org-export)
  274. (defcustom org-export-with-tables t
  275. "If non-nil, lines starting with \"|\" define a table.
  276. For example:
  277. | Name | Address | Birthday |
  278. |-------------+----------+-----------|
  279. | Arthur Dent | England | 29.2.2100 |
  280. Not all export backends support this.
  281. This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
  282. :group 'org-export-tables
  283. :type 'boolean)
  284. (defcustom org-export-highlight-first-table-line t
  285. "Non-nil means, highlight the first table line.
  286. In HTML export, this means use <th> instead of <td>.
  287. In tables created with table.el, this applies to the first table line.
  288. In Org-mode tables, all lines before the first horizontal separator
  289. line will be formatted with <th> tags."
  290. :group 'org-export-tables
  291. :type 'boolean)
  292. (defcustom org-export-table-remove-special-lines t
  293. "Remove special lines and marking characters in calculating tables.
  294. This removes the special marking character column from tables that are set
  295. up for spreadsheet calculations. It also removes the entire lines
  296. marked with `!', `_', or `^'. The lines with `$' are kept, because
  297. the values of constants may be useful to have."
  298. :group 'org-export-tables
  299. :type 'boolean)
  300. (defcustom org-export-prefer-native-exporter-for-tables nil
  301. "Non-nil means, always export tables created with table.el natively.
  302. Natively means, use the HTML code generator in table.el.
  303. When nil, Org-mode's own HTML generator is used when possible (i.e. if
  304. the table does not use row- or column-spanning). This has the
  305. advantage, that the automatic HTML conversions for math symbols and
  306. sub/superscripts can be applied. Org-mode's HTML generator is also
  307. much faster."
  308. :group 'org-export-tables
  309. :type 'boolean)
  310. (defgroup org-export-ascii nil
  311. "Options specific for ASCII export of Org-mode files."
  312. :tag "Org Export ASCII"
  313. :group 'org-export)
  314. (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
  315. "Characters for underlining headings in ASCII export.
  316. In the given sequence, these characters will be used for level 1, 2, ..."
  317. :group 'org-export-ascii
  318. :type '(repeat character))
  319. (defcustom org-export-ascii-bullets '(?* ?+ ?-)
  320. "Bullet characters for headlines converted to lists in ASCII export.
  321. The first character is used for the first lest level generated in this
  322. way, and so on. If there are more levels than characters given here,
  323. the list will be repeated.
  324. Note that plain lists will keep the same bullets as the have in the
  325. Org-mode file."
  326. :group 'org-export-ascii
  327. :type '(repeat character))
  328. (defgroup org-export-xml nil
  329. "Options specific for XML export of Org-mode files."
  330. :tag "Org Export XML"
  331. :group 'org-export)
  332. (defgroup org-export-html nil
  333. "Options specific for HTML export of Org-mode files."
  334. :tag "Org Export HTML"
  335. :group 'org-export)
  336. (defcustom org-export-html-coding-system nil
  337. ""
  338. :group 'org-export-html
  339. :type 'coding-system)
  340. (defcustom org-export-html-extension "html"
  341. "The extension for exported HTML files."
  342. :group 'org-export-html
  343. :type 'string)
  344. (defcustom org-export-html-style
  345. "<style type=\"text/css\">
  346. html {
  347. font-family: Times, serif;
  348. font-size: 12pt;
  349. }
  350. .title { text-align: center; }
  351. .todo { color: red; }
  352. .done { color: green; }
  353. .timestamp { color: grey }
  354. .timestamp-kwd { color: CadetBlue }
  355. .tag { background-color:lightblue; font-weight:normal }
  356. .target { background-color: lavender; }
  357. pre {
  358. border: 1pt solid #AEBDCC;
  359. background-color: #F3F5F7;
  360. padding: 5pt;
  361. font-family: courier, monospace;
  362. }
  363. table { border-collapse: collapse; }
  364. td, th {
  365. vertical-align: top;
  366. <!--border: 1pt solid #ADB9CC;-->
  367. }
  368. </style>"
  369. "The default style specification for exported HTML files.
  370. Since there are different ways of setting style information, this variable
  371. needs to contain the full HTML structure to provide a style, including the
  372. surrounding HTML tags. The style specifications should include definitions
  373. for new classes todo, done, title, and deadline. For example, valid values
  374. would be:
  375. <style type=\"text/css\">
  376. p { font-weight: normal; color: gray; }
  377. h1 { color: black; }
  378. .title { text-align: center; }
  379. .todo, .deadline { color: red; }
  380. .done { color: green; }
  381. </style>
  382. or, if you want to keep the style in a file,
  383. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  384. As the value of this option simply gets inserted into the HTML <head> header,
  385. you can \"misuse\" it to add arbitrary text to the header."
  386. :group 'org-export-html
  387. :type 'string)
  388. (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
  389. "Format for typesetting the document title in HTML export."
  390. :group 'org-export-html
  391. :type 'string)
  392. (defcustom org-export-html-toplevel-hlevel 2
  393. "The <H> level for level 1 headings in HTML export."
  394. :group 'org-export-html
  395. :type 'string)
  396. (defcustom org-export-html-link-org-files-as-html t
  397. "Non-nil means, make file links to `file.org' point to `file.html'.
  398. When org-mode is exporting an org-mode file to HTML, links to
  399. non-html files are directly put into a href tag in HTML.
  400. However, links to other Org-mode files (recognized by the
  401. extension `.org.) should become links to the corresponding html
  402. file, assuming that the linked org-mode file will also be
  403. converted to HTML.
  404. When nil, the links still point to the plain `.org' file."
  405. :group 'org-export-html
  406. :type 'boolean)
  407. (defcustom org-export-html-inline-images 'maybe
  408. "Non-nil means, inline images into exported HTML pages.
  409. This is done using an <img> tag. When nil, an anchor with href is used to
  410. link to the image. If this option is `maybe', then images in links with
  411. an empty description will be inlined, while images with a description will
  412. be linked only."
  413. :group 'org-export-html
  414. :type '(choice (const :tag "Never" nil)
  415. (const :tag "Always" t)
  416. (const :tag "When there is no description" maybe)))
  417. ;; FIXME: rename
  418. (defcustom org-export-html-expand t
  419. "Non-nil means, for HTML export, treat @<...> as HTML tag.
  420. When nil, these tags will be exported as plain text and therefore
  421. not be interpreted by a browser.
  422. This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
  423. :group 'org-export-html
  424. :type 'boolean)
  425. (defcustom org-export-html-table-tag
  426. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  427. "The HTML tag that is used to start a table.
  428. This must be a <table> tag, but you may change the options like
  429. borders and spacing."
  430. :group 'org-export-html
  431. :type 'string)
  432. (defcustom org-export-table-header-tags '("<th>" . "</th>")
  433. "The opening tag for table header fields.
  434. This is customizable so that alignment options can be specified."
  435. :group 'org-export-tables
  436. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  437. (defcustom org-export-table-data-tags '("<td>" . "</td>")
  438. "The opening tag for table data fields.
  439. This is customizable so that alignment options can be specified."
  440. :group 'org-export-tables
  441. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  442. (defcustom org-export-html-with-timestamp nil
  443. "If non-nil, write `org-export-html-html-helper-timestamp'
  444. into the exported HTML text. Otherwise, the buffer will just be saved
  445. to a file."
  446. :group 'org-export-html
  447. :type 'boolean)
  448. (defcustom org-export-html-html-helper-timestamp
  449. "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
  450. "The HTML tag used as timestamp delimiter for HTML-helper-mode."
  451. :group 'org-export-html
  452. :type 'string)
  453. (defgroup org-export-icalendar nil
  454. "Options specific for iCalendar export of Org-mode files."
  455. :tag "Org Export iCalendar"
  456. :group 'org-export)
  457. (defcustom org-combined-agenda-icalendar-file "~/org.ics"
  458. "The file name for the iCalendar file covering all agenda files.
  459. This file is created with the command \\[org-export-icalendar-all-agenda-files].
  460. The file name should be absolute, the file will be overwritten without warning."
  461. :group 'org-export-icalendar
  462. :type 'file)
  463. (defcustom org-icalendar-include-todo nil
  464. "Non-nil means, export to iCalendar files should also cover TODO items."
  465. :group 'org-export-icalendar
  466. :type '(choice
  467. (const :tag "None" nil)
  468. (const :tag "Unfinished" t)
  469. (const :tag "All" all)))
  470. (defcustom org-icalendar-include-sexps t
  471. "Non-nil means, export to iCalendar files should also cover sexp entries.
  472. These are entries like in the diary, but directly in an Org-mode file."
  473. :group 'org-export-icalendar
  474. :type 'boolean)
  475. (defcustom org-icalendar-include-body 100
  476. "Amount of text below headline to be included in iCalendar export.
  477. This is a number of characters that should maximally be included.
  478. Properties, scheduling and clocking lines will always be removed.
  479. The text will be inserted into the DESCRIPTION field."
  480. :group 'org-export-icalendar
  481. :type '(choice
  482. (const :tag "Nothing" nil)
  483. (const :tag "Everything" t)
  484. (integer :tag "Max characters")))
  485. (defcustom org-icalendar-combined-name "OrgMode"
  486. "Calendar name for the combined iCalendar representing all agenda files."
  487. :group 'org-export-icalendar
  488. :type 'string)
  489. ;;;; Exporting
  490. ;;; Variables, constants, and parameter plists
  491. (defconst org-level-max 20)
  492. (defvar org-export-html-preamble nil
  493. "Preamble, to be inserted just after <body>. Set by publishing functions.")
  494. (defvar org-export-html-postamble nil
  495. "Preamble, to be inserted just before </body>. Set by publishing functions.")
  496. (defvar org-export-html-auto-preamble t
  497. "Should default preamble be inserted? Set by publishing functions.")
  498. (defvar org-export-html-auto-postamble t
  499. "Should default postamble be inserted? Set by publishing functions.")
  500. (defvar org-current-export-file nil) ; dynamically scoped parameter
  501. (defvar org-current-export-dir nil) ; dynamically scoped parameter
  502. (defconst org-export-plist-vars
  503. '((:language . org-export-default-language)
  504. (:customtime . org-display-custom-times)
  505. (:headline-levels . org-export-headline-levels)
  506. (:section-numbers . org-export-with-section-numbers)
  507. (:table-of-contents . org-export-with-toc)
  508. (:preserve-breaks . org-export-preserve-breaks)
  509. (:archived-trees . org-export-with-archived-trees)
  510. (:emphasize . org-export-with-emphasize)
  511. (:sub-superscript . org-export-with-sub-superscripts)
  512. (:special-strings . org-export-with-special-strings)
  513. (:footnotes . org-export-with-footnotes)
  514. (:drawers . org-export-with-drawers)
  515. (:tags . org-export-with-tags)
  516. (:TeX-macros . org-export-with-TeX-macros)
  517. (:LaTeX-fragments . org-export-with-LaTeX-fragments)
  518. (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
  519. (:fixed-width . org-export-with-fixed-width)
  520. (:timestamps . org-export-with-timestamps)
  521. (:author-info . org-export-author-info)
  522. (:time-stamp-file . org-export-time-stamp-file)
  523. (:tables . org-export-with-tables)
  524. (:table-auto-headline . org-export-highlight-first-table-line)
  525. (:style . org-export-html-style)
  526. (:agenda-style . org-agenda-export-html-style)
  527. (:convert-org-links . org-export-html-link-org-files-as-html)
  528. (:inline-images . org-export-html-inline-images)
  529. (:html-extension . org-export-html-extension)
  530. (:html-table-tag . org-export-html-table-tag)
  531. (:expand-quoted-html . org-export-html-expand)
  532. (:timestamp . org-export-html-with-timestamp)
  533. (:publishing-directory . org-export-publishing-directory)
  534. (:preamble . org-export-html-preamble)
  535. (:postamble . org-export-html-postamble)
  536. (:auto-preamble . org-export-html-auto-preamble)
  537. (:auto-postamble . org-export-html-auto-postamble)
  538. (:author . user-full-name)
  539. (:email . user-mail-address)))
  540. (defun org-default-export-plist ()
  541. "Return the property list with default settings for the export variables."
  542. (let ((l org-export-plist-vars) rtn e)
  543. (while (setq e (pop l))
  544. (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
  545. rtn))
  546. (defun org-infile-export-plist ()
  547. "Return the property list with file-local settings for export."
  548. (save-excursion
  549. (save-restriction
  550. (widen)
  551. (goto-char 0)
  552. (let ((re (org-make-options-regexp
  553. '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE")))
  554. p key val text options)
  555. (while (re-search-forward re nil t)
  556. (setq key (org-match-string-no-properties 1)
  557. val (org-match-string-no-properties 2))
  558. (cond
  559. ((string-equal key "TITLE") (setq p (plist-put p :title val)))
  560. ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
  561. ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
  562. ((string-equal key "DATE") (setq p (plist-put p :date val)))
  563. ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
  564. ((string-equal key "TEXT")
  565. (setq text (if text (concat text "\n" val) val)))
  566. ((string-equal key "OPTIONS") (setq options val))))
  567. (setq p (plist-put p :text text))
  568. (when options
  569. (let ((op '(("H" . :headline-levels)
  570. ("num" . :section-numbers)
  571. ("toc" . :table-of-contents)
  572. ("\\n" . :preserve-breaks)
  573. ("@" . :expand-quoted-html)
  574. (":" . :fixed-width)
  575. ("|" . :tables)
  576. ("^" . :sub-superscript)
  577. ("-" . :special-strings)
  578. ("f" . :footnotes)
  579. ("d" . :drawers)
  580. ("tags" . :tags)
  581. ("*" . :emphasize)
  582. ("TeX" . :TeX-macros)
  583. ("LaTeX" . :LaTeX-fragments)
  584. ("skip" . :skip-before-1st-heading)
  585. ("author" . :author-info)
  586. ("timestamp" . :time-stamp-file)))
  587. o)
  588. (while (setq o (pop op))
  589. (if (string-match (concat (regexp-quote (car o))
  590. ":\\([^ \t\n\r;,.]*\\)")
  591. options)
  592. (setq p (plist-put p (cdr o)
  593. (car (read-from-string
  594. (match-string 1 options)))))))))
  595. p))))
  596. (defun org-export-directory (type plist)
  597. (let* ((val (plist-get plist :publishing-directory))
  598. (dir (if (listp val)
  599. (or (cdr (assoc type val)) ".")
  600. val)))
  601. dir))
  602. ;;;###autoload
  603. (defun org-export (&optional arg)
  604. "Export dispatcher for Org-mode."
  605. (interactive)
  606. (let ((help "[t] insert the export option template
  607. \[v] limit export to visible part of outline tree
  608. \[a] export as ASCII
  609. \[h] export as HTML
  610. \[H] export as HTML to temporary buffer
  611. \[R] export region as HTML
  612. \[b] export as HTML and browse immediately
  613. \[x] export as XOXO
  614. \[l] export as LaTeX
  615. \[L] export as LaTeX to temporary buffer
  616. \[i] export current file as iCalendar file
  617. \[I] export all agenda files as iCalendar files
  618. \[c] export agenda files into combined iCalendar file
  619. \[F] publish current file
  620. \[P] publish current project
  621. \[X] publish... (project will be prompted for)
  622. \[A] publish all projects")
  623. (cmds
  624. '((?t . org-insert-export-options-template)
  625. (?v . org-export-visible)
  626. (?a . org-export-as-ascii)
  627. (?h . org-export-as-html)
  628. (?b . org-export-as-html-and-open)
  629. (?H . org-export-as-html-to-buffer)
  630. (?R . org-export-region-as-html)
  631. (?x . org-export-as-xoxo)
  632. (?l . org-export-as-latex)
  633. (?L . org-export-as-latex-to-buffer)
  634. (?i . org-export-icalendar-this-file)
  635. (?I . org-export-icalendar-all-agenda-files)
  636. (?c . org-export-icalendar-combine-agenda-files)
  637. (?F . org-publish-current-file)
  638. (?P . org-publish-current-project)
  639. (?X . org-publish)
  640. (?A . org-publish-all)))
  641. r1 r2 ass)
  642. (save-window-excursion
  643. (delete-other-windows)
  644. (with-output-to-temp-buffer "*Org Export/Publishing Help*"
  645. (princ help))
  646. (message "Select command: ")
  647. (setq r1 (read-char-exclusive)))
  648. (setq r2 (if (< r1 27) (+ r1 96) r1))
  649. (if (setq ass (assq r2 cmds))
  650. (call-interactively (cdr ass))
  651. (error "No command associated with key %c" r1))))
  652. (defconst org-html-entities
  653. '(("nbsp")
  654. ("iexcl")
  655. ("cent")
  656. ("pound")
  657. ("curren")
  658. ("yen")
  659. ("brvbar")
  660. ("vert" . "&#124;")
  661. ("sect")
  662. ("uml")
  663. ("copy")
  664. ("ordf")
  665. ("laquo")
  666. ("not")
  667. ("shy")
  668. ("reg")
  669. ("macr")
  670. ("deg")
  671. ("plusmn")
  672. ("sup2")
  673. ("sup3")
  674. ("acute")
  675. ("micro")
  676. ("para")
  677. ("middot")
  678. ("odot"."o")
  679. ("star"."*")
  680. ("cedil")
  681. ("sup1")
  682. ("ordm")
  683. ("raquo")
  684. ("frac14")
  685. ("frac12")
  686. ("frac34")
  687. ("iquest")
  688. ("Agrave")
  689. ("Aacute")
  690. ("Acirc")
  691. ("Atilde")
  692. ("Auml")
  693. ("Aring") ("AA"."&Aring;")
  694. ("AElig")
  695. ("Ccedil")
  696. ("Egrave")
  697. ("Eacute")
  698. ("Ecirc")
  699. ("Euml")
  700. ("Igrave")
  701. ("Iacute")
  702. ("Icirc")
  703. ("Iuml")
  704. ("ETH")
  705. ("Ntilde")
  706. ("Ograve")
  707. ("Oacute")
  708. ("Ocirc")
  709. ("Otilde")
  710. ("Ouml")
  711. ("times")
  712. ("Oslash")
  713. ("Ugrave")
  714. ("Uacute")
  715. ("Ucirc")
  716. ("Uuml")
  717. ("Yacute")
  718. ("THORN")
  719. ("szlig")
  720. ("agrave")
  721. ("aacute")
  722. ("acirc")
  723. ("atilde")
  724. ("auml")
  725. ("aring")
  726. ("aelig")
  727. ("ccedil")
  728. ("egrave")
  729. ("eacute")
  730. ("ecirc")
  731. ("euml")
  732. ("igrave")
  733. ("iacute")
  734. ("icirc")
  735. ("iuml")
  736. ("eth")
  737. ("ntilde")
  738. ("ograve")
  739. ("oacute")
  740. ("ocirc")
  741. ("otilde")
  742. ("ouml")
  743. ("divide")
  744. ("oslash")
  745. ("ugrave")
  746. ("uacute")
  747. ("ucirc")
  748. ("uuml")
  749. ("yacute")
  750. ("thorn")
  751. ("yuml")
  752. ("fnof")
  753. ("Alpha")
  754. ("Beta")
  755. ("Gamma")
  756. ("Delta")
  757. ("Epsilon")
  758. ("Zeta")
  759. ("Eta")
  760. ("Theta")
  761. ("Iota")
  762. ("Kappa")
  763. ("Lambda")
  764. ("Mu")
  765. ("Nu")
  766. ("Xi")
  767. ("Omicron")
  768. ("Pi")
  769. ("Rho")
  770. ("Sigma")
  771. ("Tau")
  772. ("Upsilon")
  773. ("Phi")
  774. ("Chi")
  775. ("Psi")
  776. ("Omega")
  777. ("alpha")
  778. ("beta")
  779. ("gamma")
  780. ("delta")
  781. ("epsilon")
  782. ("varepsilon"."&epsilon;")
  783. ("zeta")
  784. ("eta")
  785. ("theta")
  786. ("iota")
  787. ("kappa")
  788. ("lambda")
  789. ("mu")
  790. ("nu")
  791. ("xi")
  792. ("omicron")
  793. ("pi")
  794. ("rho")
  795. ("sigmaf") ("varsigma"."&sigmaf;")
  796. ("sigma")
  797. ("tau")
  798. ("upsilon")
  799. ("phi")
  800. ("chi")
  801. ("psi")
  802. ("omega")
  803. ("thetasym") ("vartheta"."&thetasym;")
  804. ("upsih")
  805. ("piv")
  806. ("bull") ("bullet"."&bull;")
  807. ("hellip") ("dots"."&hellip;")
  808. ("prime")
  809. ("Prime")
  810. ("oline")
  811. ("frasl")
  812. ("weierp")
  813. ("image")
  814. ("real")
  815. ("trade")
  816. ("alefsym")
  817. ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
  818. ("uarr") ("uparrow"."&uarr;")
  819. ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
  820. ("darr")("downarrow"."&darr;")
  821. ("harr") ("leftrightarrow"."&harr;")
  822. ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
  823. ("lArr") ("Leftarrow"."&lArr;")
  824. ("uArr") ("Uparrow"."&uArr;")
  825. ("rArr") ("Rightarrow"."&rArr;")
  826. ("dArr") ("Downarrow"."&dArr;")
  827. ("hArr") ("Leftrightarrow"."&hArr;")
  828. ("forall")
  829. ("part") ("partial"."&part;")
  830. ("exist") ("exists"."&exist;")
  831. ("empty") ("emptyset"."&empty;")
  832. ("nabla")
  833. ("isin") ("in"."&isin;")
  834. ("notin")
  835. ("ni")
  836. ("prod")
  837. ("sum")
  838. ("minus")
  839. ("lowast") ("ast"."&lowast;")
  840. ("radic")
  841. ("prop") ("proptp"."&prop;")
  842. ("infin") ("infty"."&infin;")
  843. ("ang") ("angle"."&ang;")
  844. ("and") ("wedge"."&and;")
  845. ("or") ("vee"."&or;")
  846. ("cap")
  847. ("cup")
  848. ("int")
  849. ("there4")
  850. ("sim")
  851. ("cong") ("simeq"."&cong;")
  852. ("asymp")("approx"."&asymp;")
  853. ("ne") ("neq"."&ne;")
  854. ("equiv")
  855. ("le")
  856. ("ge")
  857. ("sub") ("subset"."&sub;")
  858. ("sup") ("supset"."&sup;")
  859. ("nsub")
  860. ("sube")
  861. ("supe")
  862. ("oplus")
  863. ("otimes")
  864. ("perp")
  865. ("sdot") ("cdot"."&sdot;")
  866. ("lceil")
  867. ("rceil")
  868. ("lfloor")
  869. ("rfloor")
  870. ("lang")
  871. ("rang")
  872. ("loz") ("Diamond"."&loz;")
  873. ("spades") ("spadesuit"."&spades;")
  874. ("clubs") ("clubsuit"."&clubs;")
  875. ("hearts") ("diamondsuit"."&hearts;")
  876. ("diams") ("diamondsuit"."&diams;")
  877. ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
  878. ("quot")
  879. ("amp")
  880. ("lt")
  881. ("gt")
  882. ("OElig")
  883. ("oelig")
  884. ("Scaron")
  885. ("scaron")
  886. ("Yuml")
  887. ("circ")
  888. ("tilde")
  889. ("ensp")
  890. ("emsp")
  891. ("thinsp")
  892. ("zwnj")
  893. ("zwj")
  894. ("lrm")
  895. ("rlm")
  896. ("ndash")
  897. ("mdash")
  898. ("lsquo")
  899. ("rsquo")
  900. ("sbquo")
  901. ("ldquo")
  902. ("rdquo")
  903. ("bdquo")
  904. ("dagger")
  905. ("Dagger")
  906. ("permil")
  907. ("lsaquo")
  908. ("rsaquo")
  909. ("euro")
  910. ("arccos"."arccos")
  911. ("arcsin"."arcsin")
  912. ("arctan"."arctan")
  913. ("arg"."arg")
  914. ("cos"."cos")
  915. ("cosh"."cosh")
  916. ("cot"."cot")
  917. ("coth"."coth")
  918. ("csc"."csc")
  919. ("deg"."deg")
  920. ("det"."det")
  921. ("dim"."dim")
  922. ("exp"."exp")
  923. ("gcd"."gcd")
  924. ("hom"."hom")
  925. ("inf"."inf")
  926. ("ker"."ker")
  927. ("lg"."lg")
  928. ("lim"."lim")
  929. ("liminf"."liminf")
  930. ("limsup"."limsup")
  931. ("ln"."ln")
  932. ("log"."log")
  933. ("max"."max")
  934. ("min"."min")
  935. ("Pr"."Pr")
  936. ("sec"."sec")
  937. ("sin"."sin")
  938. ("sinh"."sinh")
  939. ("sup"."sup")
  940. ("tan"."tan")
  941. ("tanh"."tanh")
  942. )
  943. "Entities for TeX->HTML translation.
  944. Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
  945. \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
  946. In that case, \"\\ent\" will be translated to \"&other;\".
  947. The list contains HTML entities for Latin-1, Greek and other symbols.
  948. It is supplemented by a number of commonly used TeX macros with appropriate
  949. translations. There is currently no way for users to extend this.")
  950. ;;; General functions for all backends
  951. (defun org-cleaned-string-for-export (string &rest parameters)
  952. "Cleanup a buffer STRING so that links can be created safely."
  953. (interactive)
  954. (let* ((re-radio (and org-target-link-regexp
  955. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
  956. (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  957. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
  958. (re-archive (concat ":" org-archive-tag ":"))
  959. (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
  960. (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  961. (htmlp (plist-get parameters :for-html))
  962. (asciip (plist-get parameters :for-ascii))
  963. (latexp (plist-get parameters :for-LaTeX))
  964. (commentsp (plist-get parameters :comments))
  965. (archived-trees (plist-get parameters :archived-trees))
  966. (inhibit-read-only t)
  967. (drawers org-drawers)
  968. (exp-drawers (plist-get parameters :drawers))
  969. (outline-regexp "\\*+ ")
  970. a b xx
  971. rtn p)
  972. (with-current-buffer (get-buffer-create " org-mode-tmp")
  973. (erase-buffer)
  974. (insert string)
  975. ;; Remove license-to-kill stuff
  976. (while (setq p (text-property-any (point-min) (point-max)
  977. :org-license-to-kill t))
  978. (delete-region p (next-single-property-change p :org-license-to-kill)))
  979. (let ((org-inhibit-startup t)) (org-mode))
  980. (untabify (point-min) (point-max))
  981. ;; Get rid of drawers
  982. (unless (eq t exp-drawers)
  983. (goto-char (point-min))
  984. (let ((re (concat "^[ \t]*:\\("
  985. (mapconcat
  986. 'identity
  987. (org-delete-all exp-drawers
  988. (copy-sequence drawers))
  989. "\\|")
  990. "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
  991. (while (re-search-forward re nil t)
  992. (replace-match ""))))
  993. ;; Get the correct stuff before the first headline
  994. (when (plist-get parameters :skip-before-1st-heading)
  995. (goto-char (point-min))
  996. (when (re-search-forward "^\\*+[ \t]" nil t)
  997. (delete-region (point-min) (match-beginning 0))
  998. (goto-char (point-min))
  999. (insert "\n")))
  1000. (when (plist-get parameters :add-text)
  1001. (goto-char (point-min))
  1002. (insert (plist-get parameters :add-text) "\n"))
  1003. ;; Get rid of archived trees
  1004. (when (not (eq archived-trees t))
  1005. (goto-char (point-min))
  1006. (while (re-search-forward re-archive nil t)
  1007. (if (not (org-on-heading-p t))
  1008. (org-end-of-subtree t)
  1009. (beginning-of-line 1)
  1010. (setq a (if archived-trees
  1011. (1+ (point-at-eol)) (point))
  1012. b (org-end-of-subtree t))
  1013. (if (> b a) (delete-region a b)))))
  1014. ;; Find targets in comments and move them out of comments,
  1015. ;; but mark them as targets that should be invisible
  1016. (goto-char (point-min))
  1017. (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t)
  1018. (replace-match "\\1(INVISIBLE)"))
  1019. ;; Protect backend specific stuff, throw away the others.
  1020. (let ((formatters
  1021. `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
  1022. (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
  1023. (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1024. fmt)
  1025. (goto-char (point-min))
  1026. (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
  1027. (goto-char (match-end 0))
  1028. (while (not (looking-at "#\\+END_EXAMPLE"))
  1029. (insert ": ")
  1030. (beginning-of-line 2)))
  1031. (goto-char (point-min))
  1032. (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
  1033. (add-text-properties (match-beginning 0) (match-end 0)
  1034. '(org-protected t)))
  1035. (while formatters
  1036. (setq fmt (pop formatters))
  1037. (when (car fmt)
  1038. (goto-char (point-min))
  1039. (while (re-search-forward (concat "^#\\+" (cadr fmt)
  1040. ":[ \t]*\\(.*\\)") nil t)
  1041. (replace-match "\\1" t)
  1042. (add-text-properties
  1043. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1044. '(org-protected t))))
  1045. (goto-char (point-min))
  1046. (while (re-search-forward
  1047. (concat "^#\\+"
  1048. (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
  1049. (cadddr fmt) "\\>.*\n?") nil t)
  1050. (if (car fmt)
  1051. (add-text-properties (match-beginning 1) (1+ (match-end 1))
  1052. '(org-protected t))
  1053. (delete-region (match-beginning 0) (match-end 0))))))
  1054. ;; Protect quoted subtrees
  1055. (goto-char (point-min))
  1056. (while (re-search-forward re-quote nil t)
  1057. (goto-char (match-beginning 0))
  1058. (end-of-line 1)
  1059. (add-text-properties (point) (org-end-of-subtree t)
  1060. '(org-protected t)))
  1061. ;; Protect verbatim elements
  1062. (goto-char (point-min))
  1063. (while (re-search-forward org-verbatim-re nil t)
  1064. (add-text-properties (match-beginning 4) (match-end 4)
  1065. '(org-protected t))
  1066. (goto-char (1+ (match-end 4))))
  1067. ;; Remove subtrees that are commented
  1068. (goto-char (point-min))
  1069. (while (re-search-forward re-commented nil t)
  1070. (goto-char (match-beginning 0))
  1071. (delete-region (point) (org-end-of-subtree t)))
  1072. ;; Remove special table lines
  1073. (when org-export-table-remove-special-lines
  1074. (goto-char (point-min))
  1075. (while (re-search-forward "^[ \t]*|" nil t)
  1076. (beginning-of-line 1)
  1077. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1078. (and (looking-at ".*?| *<[0-9]+> *|")
  1079. (not (looking-at ".*?| *[^ <|]"))))
  1080. (delete-region (max (point-min) (1- (point-at-bol)))
  1081. (point-at-eol))
  1082. (end-of-line 1))))
  1083. ;; Specific LaTeX stuff
  1084. (when latexp
  1085. (require 'org-export-latex nil)
  1086. (org-export-latex-cleaned-string))
  1087. (when asciip
  1088. (org-export-ascii-clean-string))
  1089. ;; Specific HTML stuff
  1090. (when htmlp
  1091. ;; Convert LaTeX fragments to images
  1092. (when (plist-get parameters :LaTeX-fragments)
  1093. (org-format-latex
  1094. (concat "ltxpng/" (file-name-sans-extension
  1095. (file-name-nondirectory
  1096. org-current-export-file)))
  1097. org-current-export-dir nil "Creating LaTeX image %s"))
  1098. (message "Exporting..."))
  1099. ;; Remove or replace comments
  1100. (goto-char (point-min))
  1101. (while (re-search-forward "^#\\(.*\n?\\)" nil t)
  1102. (if commentsp
  1103. (progn (add-text-properties
  1104. (match-beginning 0) (match-end 0) '(org-protected t))
  1105. (replace-match (format commentsp (match-string 1)) t t))
  1106. (replace-match "")))
  1107. ;; Find matches for radio targets and turn them into internal links
  1108. (goto-char (point-min))
  1109. (when re-radio
  1110. (while (re-search-forward re-radio nil t)
  1111. (org-if-unprotected
  1112. (replace-match "\\1[[\\2]]"))))
  1113. ;; Find all links that contain a newline and put them into a single line
  1114. (goto-char (point-min))
  1115. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1116. (org-if-unprotected
  1117. (replace-match "\\1 \\3")
  1118. (goto-char (match-beginning 0))))
  1119. ;; Normalize links: Convert angle and plain links into bracket links
  1120. ;; Expand link abbreviations
  1121. (goto-char (point-min))
  1122. (while (re-search-forward re-plain-link nil t)
  1123. (goto-char (1- (match-end 0)))
  1124. (org-if-unprotected
  1125. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1126. ":" (match-string 3) "]]")))
  1127. ;; added 'org-link face to links
  1128. (put-text-property 0 (length s) 'face 'org-link s)
  1129. (replace-match s t t))))
  1130. (goto-char (point-min))
  1131. (while (re-search-forward re-angle-link nil t)
  1132. (goto-char (1- (match-end 0)))
  1133. (org-if-unprotected
  1134. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1135. ":" (match-string 3) "]]")))
  1136. (put-text-property 0 (length s) 'face 'org-link s)
  1137. (replace-match s t t))))
  1138. (goto-char (point-min))
  1139. (while (re-search-forward org-bracket-link-regexp nil t)
  1140. (org-if-unprotected
  1141. (let* ((s (concat "[[" (setq xx (save-match-data
  1142. (org-link-expand-abbrev (match-string 1))))
  1143. "]"
  1144. (if (match-end 3)
  1145. (match-string 2)
  1146. (concat "[" xx "]"))
  1147. "]")))
  1148. (put-text-property 0 (length s) 'face 'org-link s)
  1149. (replace-match s t t))))
  1150. ;; Find multiline emphasis and put them into single line
  1151. (when (plist-get parameters :emph-multiline)
  1152. (goto-char (point-min))
  1153. (while (re-search-forward org-emph-re nil t)
  1154. (if (not (= (char-after (match-beginning 3))
  1155. (char-after (match-beginning 4))))
  1156. (org-if-unprotected
  1157. (subst-char-in-region (match-beginning 0) (match-end 0)
  1158. ?\n ?\ t)
  1159. (goto-char (1- (match-end 0))))
  1160. (goto-char (1+ (match-beginning 0))))))
  1161. (setq rtn (buffer-string)))
  1162. (kill-buffer " org-mode-tmp")
  1163. rtn))
  1164. (defun org-export-grab-title-from-buffer ()
  1165. "Get a title for the current document, from looking at the buffer."
  1166. (let ((inhibit-read-only t))
  1167. (save-excursion
  1168. (goto-char (point-min))
  1169. (let ((end (save-excursion (outline-next-heading) (point))))
  1170. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1171. ;; Mark the line so that it will not be exported as normal text.
  1172. (org-unmodified
  1173. (add-text-properties (match-beginning 0) (match-end 0)
  1174. (list :org-license-to-kill t)))
  1175. ;; Return the title string
  1176. (org-trim (match-string 0)))))))
  1177. (defun org-export-get-title-from-subtree ()
  1178. "Return subtree title and exclude it from export."
  1179. (let (title (m (mark)))
  1180. (save-excursion
  1181. (goto-char (region-beginning))
  1182. (when (and (org-at-heading-p)
  1183. (>= (org-end-of-subtree t t) (region-end)))
  1184. ;; This is a subtree, we take the title from the first heading
  1185. (goto-char (region-beginning))
  1186. (looking-at org-todo-line-regexp)
  1187. (setq title (match-string 3))
  1188. (org-unmodified
  1189. (add-text-properties (point) (1+ (point-at-eol))
  1190. (list :org-license-to-kill t)))))
  1191. title))
  1192. (defun org-solidify-link-text (s &optional alist)
  1193. "Take link text and make a safe target out of it."
  1194. (save-match-data
  1195. (let* ((rtn
  1196. (mapconcat
  1197. 'identity
  1198. (org-split-string s "[ \t\r\n]+") "--"))
  1199. (a (assoc rtn alist)))
  1200. (or (cdr a) rtn))))
  1201. (defun org-get-min-level (lines)
  1202. "Get the minimum level in LINES."
  1203. (let ((re "^\\(\\*+\\) ") l min)
  1204. (catch 'exit
  1205. (while (setq l (pop lines))
  1206. (if (string-match re l)
  1207. (throw 'exit (org-tr-level (length (match-string 1 l))))))
  1208. 1)))
  1209. ;; Variable holding the vector with section numbers
  1210. (defvar org-section-numbers (make-vector org-level-max 0))
  1211. (defun org-init-section-numbers ()
  1212. "Initialize the vector for the section numbers."
  1213. (let* ((level -1)
  1214. (numbers (nreverse (org-split-string "" "\\.")))
  1215. (depth (1- (length org-section-numbers)))
  1216. (i depth) number-string)
  1217. (while (>= i 0)
  1218. (if (> i level)
  1219. (aset org-section-numbers i 0)
  1220. (setq number-string (or (car numbers) "0"))
  1221. (if (string-match "\\`[A-Z]\\'" number-string)
  1222. (aset org-section-numbers i
  1223. (- (string-to-char number-string) ?A -1))
  1224. (aset org-section-numbers i (string-to-number number-string)))
  1225. (pop numbers))
  1226. (setq i (1- i)))))
  1227. (defun org-section-number (&optional level)
  1228. "Return a string with the current section number.
  1229. When LEVEL is non-nil, increase section numbers on that level."
  1230. (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
  1231. (when level
  1232. (when (> level -1)
  1233. (aset org-section-numbers
  1234. level (1+ (aref org-section-numbers level))))
  1235. (setq idx (1+ level))
  1236. (while (<= idx depth)
  1237. (if (not (= idx 1))
  1238. (aset org-section-numbers idx 0))
  1239. (setq idx (1+ idx))))
  1240. (setq idx 0)
  1241. (while (<= idx depth)
  1242. (setq n (aref org-section-numbers idx))
  1243. (setq string (concat string (if (not (string= string "")) "." "")
  1244. (int-to-string n)))
  1245. (setq idx (1+ idx)))
  1246. (save-match-data
  1247. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1248. (setq string (replace-match "" t nil string)))
  1249. (if (string-match "\\(\\.0\\)+\\'" string)
  1250. (setq string (replace-match "" t nil string))))
  1251. string))
  1252. ;;; ASCII export
  1253. (defvar org-last-level nil) ; dynamically scoped variable
  1254. (defvar org-min-level nil) ; dynamically scoped variable
  1255. (defvar org-levels-open nil) ; dynamically scoped parameter
  1256. (defvar org-ascii-current-indentation nil) ; For communication
  1257. ;;;###autoload
  1258. (defun org-export-as-ascii (arg)
  1259. "Export the outline as a pretty ASCII file.
  1260. If there is an active region, export only the region.
  1261. The prefix ARG specifies how many levels of the outline should become
  1262. underlined headlines. The default is 3."
  1263. (interactive "P")
  1264. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1265. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  1266. (org-infile-export-plist)))
  1267. (region-p (org-region-active-p))
  1268. (subtree-p
  1269. (when region-p
  1270. (save-excursion
  1271. (goto-char (region-beginning))
  1272. (and (org-at-heading-p)
  1273. (>= (org-end-of-subtree t t) (region-end))))))
  1274. (custom-times org-display-custom-times)
  1275. (org-ascii-current-indentation '(0 . 0))
  1276. (level 0) line txt
  1277. (umax nil)
  1278. (umax-toc nil)
  1279. (case-fold-search nil)
  1280. (filename (concat (file-name-as-directory
  1281. (org-export-directory :ascii opt-plist))
  1282. (file-name-sans-extension
  1283. (or (and subtree-p
  1284. (org-entry-get (region-beginning)
  1285. "EXPORT_FILE_NAME" t))
  1286. (file-name-nondirectory buffer-file-name)))
  1287. ".txt"))
  1288. (filename (if (equal (file-truename filename)
  1289. (file-truename buffer-file-name))
  1290. (concat filename ".txt")
  1291. filename))
  1292. (buffer (find-file-noselect filename))
  1293. (org-levels-open (make-vector org-level-max nil))
  1294. (odd org-odd-levels-only)
  1295. (date (plist-get opt-plist :date))
  1296. (author (plist-get opt-plist :author))
  1297. (title (or (and subtree-p (org-export-get-title-from-subtree))
  1298. (plist-get opt-plist :title)
  1299. (and (not
  1300. (plist-get opt-plist :skip-before-1st-heading))
  1301. (org-export-grab-title-from-buffer))
  1302. (file-name-sans-extension
  1303. (file-name-nondirectory buffer-file-name))))
  1304. (email (plist-get opt-plist :email))
  1305. (language (plist-get opt-plist :language))
  1306. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  1307. ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
  1308. (todo nil)
  1309. (lang-words nil)
  1310. (region
  1311. (buffer-substring
  1312. (if (org-region-active-p) (region-beginning) (point-min))
  1313. (if (org-region-active-p) (region-end) (point-max))))
  1314. (lines (org-split-string
  1315. (org-cleaned-string-for-export
  1316. region
  1317. :for-ascii t
  1318. :skip-before-1st-heading
  1319. (plist-get opt-plist :skip-before-1st-heading)
  1320. :drawers (plist-get opt-plist :drawers)
  1321. :verbatim-multiline t
  1322. :archived-trees
  1323. (plist-get opt-plist :archived-trees)
  1324. :add-text (plist-get opt-plist :text))
  1325. "\n"))
  1326. thetoc have-headings first-heading-pos
  1327. table-open table-buffer)
  1328. (let ((inhibit-read-only t))
  1329. (org-unmodified
  1330. (remove-text-properties (point-min) (point-max)
  1331. '(:org-license-to-kill t))))
  1332. (setq org-min-level (org-get-min-level lines))
  1333. (setq org-last-level org-min-level)
  1334. (org-init-section-numbers)
  1335. (find-file-noselect filename)
  1336. (setq lang-words (or (assoc language org-export-language-setup)
  1337. (assoc "en" org-export-language-setup)))
  1338. (switch-to-buffer-other-window buffer)
  1339. (erase-buffer)
  1340. (fundamental-mode)
  1341. ;; create local variables for all options, to make sure all called
  1342. ;; functions get the correct information
  1343. (mapc (lambda (x)
  1344. (set (make-local-variable (cdr x))
  1345. (plist-get opt-plist (car x))))
  1346. org-export-plist-vars)
  1347. (org-set-local 'org-odd-levels-only odd)
  1348. (setq umax (if arg (prefix-numeric-value arg)
  1349. org-export-headline-levels))
  1350. (setq umax-toc (if (integerp org-export-with-toc)
  1351. (min org-export-with-toc umax)
  1352. umax))
  1353. ;; File header
  1354. (if title (org-insert-centered title ?=))
  1355. (insert "\n")
  1356. (if (and (or author email)
  1357. org-export-author-info)
  1358. (insert (concat (nth 1 lang-words) ": " (or author "")
  1359. (if email (concat " <" email ">") "")
  1360. "\n")))
  1361. (cond
  1362. ((and date (string-match "%" date))
  1363. (setq date (format-time-string date)))
  1364. (date)
  1365. (t (setq date (format-time-string "%Y/%m/%d %X"))))
  1366. (if (and date org-export-time-stamp-file)
  1367. (insert (concat (nth 2 lang-words) ": " date"\n")))
  1368. (insert "\n\n")
  1369. (if org-export-with-toc
  1370. (progn
  1371. (push (concat (nth 3 lang-words) "\n") thetoc)
  1372. (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
  1373. (mapc '(lambda (line)
  1374. (if (string-match org-todo-line-regexp
  1375. line)
  1376. ;; This is a headline
  1377. (progn
  1378. (setq have-headings t)
  1379. (setq level (- (match-end 1) (match-beginning 1))
  1380. level (org-tr-level level)
  1381. txt (match-string 3 line)
  1382. todo
  1383. (or (and org-export-mark-todo-in-toc
  1384. (match-beginning 2)
  1385. (not (member (match-string 2 line)
  1386. org-done-keywords)))
  1387. ; TODO, not DONE
  1388. (and org-export-mark-todo-in-toc
  1389. (= level umax-toc)
  1390. (org-search-todo-below
  1391. line lines level))))
  1392. (setq txt (org-html-expand-for-ascii txt))
  1393. (while (string-match org-bracket-link-regexp txt)
  1394. (setq txt
  1395. (replace-match
  1396. (match-string (if (match-end 2) 3 1) txt)
  1397. t t txt)))
  1398. (if (and (memq org-export-with-tags '(not-in-toc nil))
  1399. (string-match
  1400. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  1401. txt))
  1402. (setq txt (replace-match "" t t txt)))
  1403. (if (string-match quote-re0 txt)
  1404. (setq txt (replace-match "" t t txt)))
  1405. (if org-export-with-section-numbers
  1406. (setq txt (concat (org-section-number level)
  1407. " " txt)))
  1408. (if (<= level umax-toc)
  1409. (progn
  1410. (push
  1411. (concat
  1412. (make-string
  1413. (* (max 0 (- level org-min-level)) 4) ?\ )
  1414. (format (if todo "%s (*)\n" "%s\n") txt))
  1415. thetoc)
  1416. (setq org-last-level level))
  1417. ))))
  1418. lines)
  1419. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  1420. (org-init-section-numbers)
  1421. (while (setq line (pop lines))
  1422. ;; Remove the quoted HTML tags.
  1423. (setq line (org-html-expand-for-ascii line))
  1424. ;; Remove targets
  1425. (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
  1426. (setq line (replace-match "" t t line)))
  1427. ;; Replace internal links
  1428. (while (string-match org-bracket-link-regexp line)
  1429. (setq line (replace-match
  1430. (if (match-end 3) "[\\3]" "[\\1]")
  1431. t nil line)))
  1432. (when custom-times
  1433. (setq line (org-translate-time line)))
  1434. (cond
  1435. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  1436. ;; a Headline
  1437. (setq first-heading-pos (or first-heading-pos (point)))
  1438. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  1439. txt (match-string 2 line))
  1440. (org-ascii-level-start level txt umax lines))
  1441. ((and org-export-with-tables
  1442. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  1443. (if (not table-open)
  1444. ;; New table starts
  1445. (setq table-open t table-buffer nil))
  1446. ;; Accumulate lines
  1447. (setq table-buffer (cons line table-buffer))
  1448. (when (or (not lines)
  1449. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1450. (car lines))))
  1451. (setq table-open nil
  1452. table-buffer (nreverse table-buffer))
  1453. (insert (mapconcat
  1454. (lambda (x)
  1455. (org-fix-indentation x org-ascii-current-indentation))
  1456. (org-format-table-ascii table-buffer)
  1457. "\n") "\n")))
  1458. (t
  1459. (setq line (org-fix-indentation line org-ascii-current-indentation))
  1460. (if (and org-export-with-fixed-width
  1461. (string-match "^\\([ \t]*\\)\\(:\\)" line))
  1462. (setq line (replace-match "\\1" nil nil line)))
  1463. (insert line "\n"))))
  1464. (normal-mode)
  1465. ;; insert the table of contents
  1466. (when thetoc
  1467. (goto-char (point-min))
  1468. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  1469. (progn
  1470. (goto-char (match-beginning 0))
  1471. (replace-match ""))
  1472. (goto-char first-heading-pos))
  1473. (mapc 'insert thetoc)
  1474. (or (looking-at "[ \t]*\n[ \t]*\n")
  1475. (insert "\n\n")))
  1476. ;; Convert whitespace place holders
  1477. (goto-char (point-min))
  1478. (let (beg end)
  1479. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1480. (setq end (next-single-property-change beg 'org-whitespace))
  1481. (goto-char beg)
  1482. (delete-region beg end)
  1483. (insert (make-string (- end beg) ?\ ))))
  1484. (save-buffer)
  1485. ;; remove display and invisible chars
  1486. (let (beg end)
  1487. (goto-char (point-min))
  1488. (while (setq beg (next-single-property-change (point) 'display))
  1489. (setq end (next-single-property-change beg 'display))
  1490. (delete-region beg end)
  1491. (goto-char beg)
  1492. (insert "=>"))
  1493. (goto-char (point-min))
  1494. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  1495. (setq end (next-single-property-change beg 'org-cwidth))
  1496. (delete-region beg end)
  1497. (goto-char beg)))
  1498. (goto-char (point-min))))
  1499. (defun org-export-ascii-clean-string ()
  1500. "Do extra work for ASCII export"
  1501. (goto-char (point-min))
  1502. (while (re-search-forward org-verbatim-re nil t)
  1503. (goto-char (match-end 2))
  1504. (backward-delete-char 1) (insert "'")
  1505. (goto-char (match-beginning 2))
  1506. (delete-char 1) (insert "`")
  1507. (goto-char (match-end 2))))
  1508. (defun org-search-todo-below (line lines level)
  1509. "Search the subtree below LINE for any TODO entries."
  1510. (let ((rest (cdr (memq line lines)))
  1511. (re org-todo-line-regexp)
  1512. line lv todo)
  1513. (catch 'exit
  1514. (while (setq line (pop rest))
  1515. (if (string-match re line)
  1516. (progn
  1517. (setq lv (- (match-end 1) (match-beginning 1))
  1518. todo (and (match-beginning 2)
  1519. (not (member (match-string 2 line)
  1520. org-done-keywords))))
  1521. ; TODO, not DONE
  1522. (if (<= lv level) (throw 'exit nil))
  1523. (if todo (throw 'exit t))))))))
  1524. (defun org-html-expand-for-ascii (line)
  1525. "Handle quoted HTML for ASCII export."
  1526. (if org-export-html-expand
  1527. (while (string-match "@<[^<>\n]*>" line)
  1528. ;; We just remove the tags for now.
  1529. (setq line (replace-match "" nil nil line))))
  1530. line)
  1531. (defun org-insert-centered (s &optional underline)
  1532. "Insert the string S centered and underline it with character UNDERLINE."
  1533. (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
  1534. (insert (make-string ind ?\ ) s "\n")
  1535. (if underline
  1536. (insert (make-string ind ?\ )
  1537. (make-string (string-width s) underline)
  1538. "\n"))))
  1539. (defun org-ascii-level-start (level title umax &optional lines)
  1540. "Insert a new level in ASCII export."
  1541. (let (char (n (- level umax 1)) (ind 0))
  1542. (if (> level umax)
  1543. (progn
  1544. (insert (make-string (* 2 n) ?\ )
  1545. (char-to-string (nth (% n (length org-export-ascii-bullets))
  1546. org-export-ascii-bullets))
  1547. " " title "\n")
  1548. ;; find the indentation of the next non-empty line
  1549. (catch 'stop
  1550. (while lines
  1551. (if (string-match "^\\* " (car lines)) (throw 'stop nil))
  1552. (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
  1553. (throw 'stop (setq ind (org-get-indentation (car lines)))))
  1554. (pop lines)))
  1555. (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
  1556. (if (or (not (equal (char-before) ?\n))
  1557. (not (equal (char-before (1- (point))) ?\n)))
  1558. (insert "\n"))
  1559. (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
  1560. (unless org-export-with-tags
  1561. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  1562. (setq title (replace-match "" t t title))))
  1563. (if org-export-with-section-numbers
  1564. (setq title (concat (org-section-number level) " " title)))
  1565. (insert title "\n" (make-string (string-width title) char) "\n")
  1566. (setq org-ascii-current-indentation '(0 . 0)))))
  1567. ;;;###autoload
  1568. (defun org-export-visible (type arg)
  1569. "Create a copy of the visible part of the current buffer, and export it.
  1570. The copy is created in a temporary buffer and removed after use.
  1571. TYPE is the final key (as a string) that also select the export command in
  1572. the `C-c C-e' export dispatcher.
  1573. As a special case, if the you type SPC at the prompt, the temporary
  1574. org-mode file will not be removed but presented to you so that you can
  1575. continue to use it. The prefix arg ARG is passed through to the exporting
  1576. command."
  1577. (interactive
  1578. (list (progn
  1579. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
  1580. (read-char-exclusive))
  1581. current-prefix-arg))
  1582. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
  1583. (error "Invalid export key"))
  1584. (let* ((binding (cdr (assoc type
  1585. '((?a . org-export-as-ascii)
  1586. (?\C-a . org-export-as-ascii)
  1587. (?b . org-export-as-html-and-open)
  1588. (?\C-b . org-export-as-html-and-open)
  1589. (?h . org-export-as-html)
  1590. (?H . org-export-as-html-to-buffer)
  1591. (?R . org-export-region-as-html)
  1592. (?x . org-export-as-xoxo)))))
  1593. (keepp (equal type ?\ ))
  1594. (file buffer-file-name)
  1595. (buffer (get-buffer-create "*Org Export Visible*"))
  1596. s e)
  1597. ;; Need to hack the drawers here.
  1598. (save-excursion
  1599. (goto-char (point-min))
  1600. (while (re-search-forward org-drawer-regexp nil t)
  1601. (goto-char (match-beginning 1))
  1602. (or (org-invisible-p) (org-flag-drawer nil))))
  1603. (with-current-buffer buffer (erase-buffer))
  1604. (save-excursion
  1605. (setq s (goto-char (point-min)))
  1606. (while (not (= (point) (point-max)))
  1607. (goto-char (org-find-invisible))
  1608. (append-to-buffer buffer s (point))
  1609. (setq s (goto-char (org-find-visible))))
  1610. (org-cycle-hide-drawers 'all)
  1611. (goto-char (point-min))
  1612. (unless keepp
  1613. ;; Copy all comment lines to the end, to make sure #+ settings are
  1614. ;; still available for the second export step. Kind of a hack, but
  1615. ;; does do the trick.
  1616. (if (looking-at "#[^\r\n]*")
  1617. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  1618. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  1619. (append-to-buffer buffer (1+ (match-beginning 0))
  1620. (min (point-max) (1+ (match-end 0))))))
  1621. (set-buffer buffer)
  1622. (let ((buffer-file-name file)
  1623. (org-inhibit-startup t))
  1624. (org-mode)
  1625. (show-all)
  1626. (unless keepp (funcall binding arg))))
  1627. (if (not keepp)
  1628. (kill-buffer buffer)
  1629. (switch-to-buffer-other-window buffer)
  1630. (goto-char (point-min)))))
  1631. (defun org-find-visible ()
  1632. (let ((s (point)))
  1633. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  1634. (get-char-property s 'invisible)))
  1635. s))
  1636. (defun org-find-invisible ()
  1637. (let ((s (point)))
  1638. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  1639. (not (get-char-property s 'invisible))))
  1640. s))
  1641. ;;; HTML export
  1642. (defun org-get-current-options ()
  1643. "Return a string with current options as keyword options.
  1644. Does include HTML export options as well as TODO and CATEGORY stuff."
  1645. (format
  1646. "#+TITLE: %s
  1647. #+AUTHOR: %s
  1648. #+EMAIL: %s
  1649. #+DATE: %s
  1650. #+LANGUAGE: %s
  1651. #+TEXT: Some descriptive text to be emitted. Several lines OK.
  1652. #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s tags:%s
  1653. #+CATEGORY: %s
  1654. #+SEQ_TODO: %s
  1655. #+TYP_TODO: %s
  1656. #+PRIORITIES: %c %c %c
  1657. #+DRAWERS: %s
  1658. #+STARTUP: %s %s %s %s %s
  1659. #+TAGS: %s
  1660. #+ARCHIVE: %s
  1661. #+LINK: %s
  1662. "
  1663. (buffer-name) (user-full-name) user-mail-address
  1664. (format-time-string (car org-time-stamp-formats))
  1665. org-export-default-language
  1666. org-export-headline-levels
  1667. org-export-with-section-numbers
  1668. org-export-with-toc
  1669. org-export-preserve-breaks
  1670. org-export-html-expand
  1671. org-export-with-fixed-width
  1672. org-export-with-tables
  1673. org-export-with-sub-superscripts
  1674. org-export-with-special-strings
  1675. org-export-with-footnotes
  1676. org-export-with-emphasize
  1677. org-export-with-TeX-macros
  1678. org-export-with-LaTeX-fragments
  1679. org-export-skip-text-before-1st-heading
  1680. org-export-with-drawers
  1681. org-export-with-tags
  1682. (file-name-nondirectory buffer-file-name)
  1683. "TODO FEEDBACK VERIFY DONE"
  1684. "Me Jason Marie DONE"
  1685. org-highest-priority org-lowest-priority org-default-priority
  1686. (mapconcat 'identity org-drawers " ")
  1687. (cdr (assoc org-startup-folded
  1688. '((nil . "showall") (t . "overview") (content . "content"))))
  1689. (if org-odd-levels-only "odd" "oddeven")
  1690. (if org-hide-leading-stars "hidestars" "showstars")
  1691. (if org-startup-align-all-tables "align" "noalign")
  1692. (cond ((eq org-log-done t) "logdone")
  1693. ((equal org-log-done 'note) "lognotedone")
  1694. ((not org-log-done) "nologdone"))
  1695. (or (mapconcat (lambda (x)
  1696. (cond
  1697. ((equal '(:startgroup) x) "{")
  1698. ((equal '(:endgroup) x) "}")
  1699. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  1700. (t (car x))))
  1701. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  1702. org-archive-location
  1703. "org file:~/org/%s.org"
  1704. ))
  1705. ;;;###autoload
  1706. (defun org-insert-export-options-template ()
  1707. "Insert into the buffer a template with information for exporting."
  1708. (interactive)
  1709. (if (not (bolp)) (newline))
  1710. (let ((s (org-get-current-options)))
  1711. (and (string-match "#\\+CATEGORY" s)
  1712. (setq s (substring s 0 (match-beginning 0))))
  1713. (insert s)))
  1714. ;;;###autoload
  1715. (defun org-export-as-html-and-open (arg)
  1716. "Export the outline as HTML and immediately open it with a browser.
  1717. If there is an active region, export only the region.
  1718. The prefix ARG specifies how many levels of the outline should become
  1719. headlines. The default is 3. Lower levels will become bulleted lists."
  1720. (interactive "P")
  1721. (org-export-as-html arg 'hidden)
  1722. (org-open-file buffer-file-name))
  1723. ;;;###autoload
  1724. (defun org-export-as-html-batch ()
  1725. "Call `org-export-as-html', may be used in batch processing as
  1726. emacs --batch
  1727. --load=$HOME/lib/emacs/org.el
  1728. --eval \"(setq org-export-headline-levels 2)\"
  1729. --visit=MyFile --funcall org-export-as-html-batch"
  1730. (org-export-as-html org-export-headline-levels 'hidden))
  1731. ;;;###autoload
  1732. (defun org-export-as-html-to-buffer (arg)
  1733. "Call `org-exort-as-html` with output to a temporary buffer.
  1734. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  1735. (interactive "P")
  1736. (org-export-as-html arg nil nil "*Org HTML Export*")
  1737. (switch-to-buffer-other-window "*Org HTML Export*"))
  1738. ;;;###autoload
  1739. (defun org-replace-region-by-html (beg end)
  1740. "Assume the current region has org-mode syntax, and convert it to HTML.
  1741. This can be used in any buffer. For example, you could write an
  1742. itemized list in org-mode syntax in an HTML buffer and then use this
  1743. command to convert it."
  1744. (interactive "r")
  1745. (let (reg html buf pop-up-frames)
  1746. (save-window-excursion
  1747. (if (org-mode-p)
  1748. (setq html (org-export-region-as-html
  1749. beg end t 'string))
  1750. (setq reg (buffer-substring beg end)
  1751. buf (get-buffer-create "*Org tmp*"))
  1752. (with-current-buffer buf
  1753. (erase-buffer)
  1754. (insert reg)
  1755. (org-mode)
  1756. (setq html (org-export-region-as-html
  1757. (point-min) (point-max) t 'string)))
  1758. (kill-buffer buf)))
  1759. (delete-region beg end)
  1760. (insert html)))
  1761. ;;;###autoload
  1762. (defun org-export-region-as-html (beg end &optional body-only buffer)
  1763. "Convert region from BEG to END in org-mode buffer to HTML.
  1764. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  1765. contents, and only produce the region of converted text, useful for
  1766. cut-and-paste operations.
  1767. If BUFFER is a buffer or a string, use/create that buffer as a target
  1768. of the converted HTML. If BUFFER is the symbol `string', return the
  1769. produced HTML as a string and leave not buffer behind. For example,
  1770. a Lisp program could call this function in the following way:
  1771. (setq html (org-export-region-as-html beg end t 'string))
  1772. When called interactively, the output buffer is selected, and shown
  1773. in a window. A non-interactive call will only retunr the buffer."
  1774. (interactive "r\nP")
  1775. (when (interactive-p)
  1776. (setq buffer "*Org HTML Export*"))
  1777. (let ((transient-mark-mode t) (zmacs-regions t)
  1778. rtn)
  1779. (goto-char end)
  1780. (set-mark (point)) ;; to activate the region
  1781. (goto-char beg)
  1782. (setq rtn (org-export-as-html
  1783. nil nil nil
  1784. buffer body-only))
  1785. (if (fboundp 'deactivate-mark) (deactivate-mark))
  1786. (if (and (interactive-p) (bufferp rtn))
  1787. (switch-to-buffer-other-window rtn)
  1788. rtn)))
  1789. (defvar html-table-tag nil) ; dynamically scoped into this.
  1790. ;;;###autoload
  1791. (defun org-export-as-html (arg &optional hidden ext-plist
  1792. to-buffer body-only pub-dir)
  1793. "Export the outline as a pretty HTML file.
  1794. If there is an active region, export only the region. The prefix
  1795. ARG specifies how many levels of the outline should become
  1796. headlines. The default is 3. Lower levels will become bulleted
  1797. lists. When HIDDEN is non-nil, don't display the HTML buffer.
  1798. EXT-PLIST is a property list with external parameters overriding
  1799. org-mode's default settings, but still inferior to file-local
  1800. settings. When TO-BUFFER is non-nil, create a buffer with that
  1801. name and export to that buffer. If TO-BUFFER is the symbol
  1802. `string', don't leave any buffer behind but just return the
  1803. resulting HTML as a string. When BODY-ONLY is set, don't produce
  1804. the file header and footer, simply return the content of
  1805. <body>...</body>, without even the body tags themselves. When
  1806. PUB-DIR is set, use this as the publishing directory."
  1807. (interactive "P")
  1808. ;; Make sure we have a file name when we need it.
  1809. (when (and (not (or to-buffer body-only))
  1810. (not buffer-file-name))
  1811. (if (buffer-base-buffer)
  1812. (org-set-local 'buffer-file-name
  1813. (with-current-buffer (buffer-base-buffer)
  1814. buffer-file-name))
  1815. (error "Need a file name to be able to export.")))
  1816. (message "Exporting...")
  1817. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1818. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  1819. (setq-default org-done-keywords org-done-keywords)
  1820. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  1821. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  1822. ext-plist
  1823. (org-infile-export-plist)))
  1824. (style (plist-get opt-plist :style))
  1825. (html-extension (plist-get opt-plist :html-extension))
  1826. (link-validate (plist-get opt-plist :link-validation-function))
  1827. valid thetoc have-headings first-heading-pos
  1828. (odd org-odd-levels-only)
  1829. (region-p (org-region-active-p))
  1830. (subtree-p
  1831. (when region-p
  1832. (save-excursion
  1833. (goto-char (region-beginning))
  1834. (and (org-at-heading-p)
  1835. (>= (org-end-of-subtree t t) (region-end))))))
  1836. ;; The following two are dynamically scoped into other
  1837. ;; routines below.
  1838. (org-current-export-dir
  1839. (or pub-dir (org-export-directory :html opt-plist)))
  1840. (org-current-export-file buffer-file-name)
  1841. (level 0) (line "") (origline "") txt todo
  1842. (umax nil)
  1843. (umax-toc nil)
  1844. (filename (if to-buffer nil
  1845. (expand-file-name
  1846. (concat
  1847. (file-name-sans-extension
  1848. (or (and subtree-p
  1849. (org-entry-get (region-beginning)
  1850. "EXPORT_FILE_NAME" t))
  1851. (file-name-nondirectory buffer-file-name)))
  1852. "." html-extension)
  1853. (file-name-as-directory
  1854. (or pub-dir (org-export-directory :html opt-plist))))))
  1855. (current-dir (if buffer-file-name
  1856. (file-name-directory buffer-file-name)
  1857. default-directory))
  1858. (buffer (if to-buffer
  1859. (cond
  1860. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  1861. (t (get-buffer-create to-buffer)))
  1862. (find-file-noselect filename)))
  1863. (org-levels-open (make-vector org-level-max nil))
  1864. (date (plist-get opt-plist :date))
  1865. (author (plist-get opt-plist :author))
  1866. (title (or (and subtree-p (org-export-get-title-from-subtree))
  1867. (plist-get opt-plist :title)
  1868. (and (not
  1869. (plist-get opt-plist :skip-before-1st-heading))
  1870. (org-export-grab-title-from-buffer))
  1871. (and buffer-file-name
  1872. (file-name-sans-extension
  1873. (file-name-nondirectory buffer-file-name)))
  1874. "UNTITLED"))
  1875. (html-table-tag (plist-get opt-plist :html-table-tag))
  1876. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  1877. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  1878. (inquote nil)
  1879. (infixed nil)
  1880. (in-local-list nil)
  1881. (local-list-num nil)
  1882. (local-list-indent nil)
  1883. (llt org-plain-list-ordered-item-terminator)
  1884. (email (plist-get opt-plist :email))
  1885. (language (plist-get opt-plist :language))
  1886. (lang-words nil)
  1887. (target-alist nil) tg
  1888. (head-count 0) cnt
  1889. (start 0)
  1890. (coding-system (and (boundp 'buffer-file-coding-system)
  1891. buffer-file-coding-system))
  1892. (coding-system-for-write (or org-export-html-coding-system
  1893. coding-system))
  1894. (save-buffer-coding-system (or org-export-html-coding-system
  1895. coding-system))
  1896. (charset (and coding-system-for-write
  1897. (fboundp 'coding-system-get)
  1898. (coding-system-get coding-system-for-write
  1899. 'mime-charset)))
  1900. (region
  1901. (buffer-substring
  1902. (if region-p (region-beginning) (point-min))
  1903. (if region-p (region-end) (point-max))))
  1904. (lines
  1905. (org-split-string
  1906. (org-cleaned-string-for-export
  1907. region
  1908. :emph-multiline t
  1909. :for-html t
  1910. :skip-before-1st-heading
  1911. (plist-get opt-plist :skip-before-1st-heading)
  1912. :drawers (plist-get opt-plist :drawers)
  1913. :archived-trees
  1914. (plist-get opt-plist :archived-trees)
  1915. :add-text
  1916. (plist-get opt-plist :text)
  1917. :LaTeX-fragments
  1918. (plist-get opt-plist :LaTeX-fragments))
  1919. "[\r\n]"))
  1920. table-open type
  1921. table-buffer table-orig-buffer
  1922. ind start-is-num starter didclose
  1923. rpl path desc descp desc1 desc2 link
  1924. snumber fnc
  1925. )
  1926. (let ((inhibit-read-only t))
  1927. (org-unmodified
  1928. (remove-text-properties (point-min) (point-max)
  1929. '(:org-license-to-kill t))))
  1930. (message "Exporting...")
  1931. (setq org-min-level (org-get-min-level lines))
  1932. (setq org-last-level org-min-level)
  1933. (org-init-section-numbers)
  1934. (cond
  1935. ((and date (string-match "%" date))
  1936. (setq date (format-time-string date)))
  1937. (date)
  1938. (t (setq date (format-time-string "%Y/%m/%d %X"))))
  1939. ;; Get the language-dependent settings
  1940. (setq lang-words (or (assoc language org-export-language-setup)
  1941. (assoc "en" org-export-language-setup)))
  1942. ;; Switch to the output buffer
  1943. (set-buffer buffer)
  1944. (let ((inhibit-read-only t)) (erase-buffer))
  1945. (fundamental-mode)
  1946. (and (fboundp 'set-buffer-file-coding-system)
  1947. (set-buffer-file-coding-system coding-system-for-write))
  1948. (let ((case-fold-search nil)
  1949. (org-odd-levels-only odd))
  1950. ;; create local variables for all options, to make sure all called
  1951. ;; functions get the correct information
  1952. (mapc (lambda (x)
  1953. (set (make-local-variable (cdr x))
  1954. (plist-get opt-plist (car x))))
  1955. org-export-plist-vars)
  1956. (setq umax (if arg (prefix-numeric-value arg)
  1957. org-export-headline-levels))
  1958. (setq umax-toc (if (integerp org-export-with-toc)
  1959. (min org-export-with-toc umax)
  1960. umax))
  1961. (unless body-only
  1962. ;; File header
  1963. (insert (format
  1964. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1965. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  1966. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  1967. lang=\"%s\" xml:lang=\"%s\">
  1968. <head>
  1969. <title>%s</title>
  1970. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  1971. <meta name=\"generator\" content=\"Org-mode\"/>
  1972. <meta name=\"generated\" content=\"%s\"/>
  1973. <meta name=\"author\" content=\"%s\"/>
  1974. %s
  1975. </head><body>
  1976. "
  1977. language language (org-html-expand title)
  1978. (or charset "iso-8859-1") date author style))
  1979. (insert (or (plist-get opt-plist :preamble) ""))
  1980. (when (plist-get opt-plist :auto-preamble)
  1981. (if title (insert (format org-export-html-title-format
  1982. (org-html-expand title))))))
  1983. (if (and org-export-with-toc (not body-only))
  1984. (progn
  1985. (push (format "<h%d>%s</h%d>\n"
  1986. org-export-html-toplevel-hlevel
  1987. (nth 3 lang-words)
  1988. org-export-html-toplevel-hlevel)
  1989. thetoc)
  1990. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  1991. (push "<ul>\n<li>" thetoc)
  1992. (setq lines
  1993. (mapcar '(lambda (line)
  1994. (if (string-match org-todo-line-regexp line)
  1995. ;; This is a headline
  1996. (progn
  1997. (setq have-headings t)
  1998. (setq level (- (match-end 1) (match-beginning 1))
  1999. level (org-tr-level level)
  2000. txt (save-match-data
  2001. (org-html-expand
  2002. (org-export-cleanup-toc-line
  2003. (match-string 3 line))))
  2004. todo
  2005. (or (and org-export-mark-todo-in-toc
  2006. (match-beginning 2)
  2007. (not (member (match-string 2 line)
  2008. org-done-keywords)))
  2009. ; TODO, not DONE
  2010. (and org-export-mark-todo-in-toc
  2011. (= level umax-toc)
  2012. (org-search-todo-below
  2013. line lines level))))
  2014. (if (string-match
  2015. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  2016. (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  2017. (if (string-match quote-re0 txt)
  2018. (setq txt (replace-match "" t t txt)))
  2019. (setq snumber (org-section-number level))
  2020. (if org-export-with-section-numbers
  2021. (setq txt (concat snumber " " txt)))
  2022. (if (<= level (max umax umax-toc))
  2023. (setq head-count (+ head-count 1)))
  2024. (if (<= level umax-toc)
  2025. (progn
  2026. (if (> level org-last-level)
  2027. (progn
  2028. (setq cnt (- level org-last-level))
  2029. (while (>= (setq cnt (1- cnt)) 0)
  2030. (push "\n<ul>\n<li>" thetoc))
  2031. (push "\n" thetoc)))
  2032. (if (< level org-last-level)
  2033. (progn
  2034. (setq cnt (- org-last-level level))
  2035. (while (>= (setq cnt (1- cnt)) 0)
  2036. (push "</li>\n</ul>" thetoc))
  2037. (push "\n" thetoc)))
  2038. ;; Check for targets
  2039. (while (string-match org-target-regexp line)
  2040. (setq tg (match-string 1 line)
  2041. line (replace-match
  2042. (concat "@<span class=\"target\">" tg "@</span> ")
  2043. t t line))
  2044. (push (cons (org-solidify-link-text tg)
  2045. (format "sec-%s" snumber))
  2046. target-alist))
  2047. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  2048. (setq txt (replace-match "" t t txt)))
  2049. (push
  2050. (format
  2051. (if todo
  2052. "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
  2053. "</li>\n<li><a href=\"#sec-%s\">%s</a>")
  2054. snumber txt) thetoc)
  2055. (setq org-last-level level))
  2056. )))
  2057. line)
  2058. lines))
  2059. (while (> org-last-level (1- org-min-level))
  2060. (setq org-last-level (1- org-last-level))
  2061. (push "</li>\n</ul>\n" thetoc))
  2062. (push "</div>\n" thetoc)
  2063. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  2064. (setq head-count 0)
  2065. (org-init-section-numbers)
  2066. (while (setq line (pop lines) origline line)
  2067. (catch 'nextline
  2068. ;; end of quote section?
  2069. (when (and inquote (string-match "^\\*+ " line))
  2070. (insert "</pre>\n")
  2071. (setq inquote nil))
  2072. ;; inside a quote section?
  2073. (when inquote
  2074. (insert (org-html-protect line) "\n")
  2075. (throw 'nextline nil))
  2076. ;; verbatim lines
  2077. (when (and org-export-with-fixed-width
  2078. (string-match "^[ \t]*:\\(.*\\)" line))
  2079. (when (not infixed)
  2080. (setq infixed t)
  2081. (insert "<pre>\n"))
  2082. (insert (org-html-protect (match-string 1 line)) "\n")
  2083. (when (and lines
  2084. (not (string-match "^[ \t]*\\(:.*\\)"
  2085. (car lines))))
  2086. (setq infixed nil)
  2087. (insert "</pre>\n"))
  2088. (throw 'nextline nil))
  2089. ;; Protected HTML
  2090. (when (get-text-property 0 'org-protected line)
  2091. (let (par)
  2092. (when (re-search-backward
  2093. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  2094. (setq par (match-string 1))
  2095. (replace-match "\\2\n"))
  2096. (insert line "\n")
  2097. (while (and lines
  2098. (or (= (length (car lines)) 0)
  2099. (get-text-property 0 'org-protected (car lines))))
  2100. (insert (pop lines) "\n"))
  2101. (and par (insert "<p>\n")))
  2102. (throw 'nextline nil))
  2103. ;; Horizontal line
  2104. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  2105. (insert "\n<hr/>\n")
  2106. (throw 'nextline nil))
  2107. ;; make targets to anchors
  2108. (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
  2109. (cond
  2110. ((match-end 2)
  2111. (setq line (replace-match
  2112. (concat "@<a name=\""
  2113. (org-solidify-link-text (match-string 1 line))
  2114. "\">\\nbsp@</a>")
  2115. t t line)))
  2116. ((and org-export-with-toc (equal (string-to-char line) ?*))
  2117. (setq line (replace-match
  2118. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2119. ; (concat "@<i>" (match-string 1 line) "@</i> ")
  2120. t t line)))
  2121. (t
  2122. (setq line (replace-match
  2123. (concat "@<a name=\""
  2124. (org-solidify-link-text (match-string 1 line))
  2125. "\" class=\"target\">" (match-string 1 line) "@</a> ")
  2126. t t line)))))
  2127. (setq line (org-html-handle-time-stamps line))
  2128. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  2129. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  2130. ;; Also handle sub_superscripts and checkboxes
  2131. (or (string-match org-table-hline-regexp line)
  2132. (setq line (org-html-expand line)))
  2133. ;; Format the links
  2134. (setq start 0)
  2135. (while (string-match org-bracket-link-analytic-regexp line start)
  2136. (setq start (match-beginning 0))
  2137. (setq type (if (match-end 2) (match-string 2 line) "internal"))
  2138. (setq path (match-string 3 line))
  2139. (setq desc1 (if (match-end 5) (match-string 5 line))
  2140. desc2 (if (match-end 2) (concat type ":" path) path)
  2141. descp (and desc1 (not (equal desc1 desc2)))
  2142. desc (or desc1 desc2))
  2143. ;; Make an image out of the description if that is so wanted
  2144. (when (and descp (org-file-image-p desc))
  2145. (save-match-data
  2146. (if (string-match "^file:" desc)
  2147. (setq desc (substring desc (match-end 0)))))
  2148. (setq desc (concat "<img src=\"" desc "\"/>")))
  2149. ;; FIXME: do we need to unescape here somewhere?
  2150. (cond
  2151. ((equal type "internal")
  2152. (setq rpl
  2153. (concat
  2154. "<a href=\"#"
  2155. (org-solidify-link-text
  2156. (save-match-data (org-link-unescape path)) target-alist)
  2157. "\">" desc "</a>")))
  2158. ((member type '("http" "https"))
  2159. ;; standard URL, just check if we need to inline an image
  2160. (if (and (or (eq t org-export-html-inline-images)
  2161. (and org-export-html-inline-images (not descp)))
  2162. (org-file-image-p path))
  2163. (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
  2164. (setq link (concat type ":" path))
  2165. (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
  2166. ((member type '("ftp" "mailto" "news"))
  2167. ;; standard URL
  2168. (setq link (concat type ":" path))
  2169. (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
  2170. ((string= type "file")
  2171. ;; FILE link
  2172. (let* ((filename path)
  2173. (abs-p (file-name-absolute-p filename))
  2174. thefile file-is-image-p search)
  2175. (save-match-data
  2176. (if (string-match "::\\(.*\\)" filename)
  2177. (setq search (match-string 1 filename)
  2178. filename (replace-match "" t nil filename)))
  2179. (setq valid
  2180. (if (functionp link-validate)
  2181. (funcall link-validate filename current-dir)
  2182. t))
  2183. (setq file-is-image-p (org-file-image-p filename))
  2184. (setq thefile (if abs-p (expand-file-name filename) filename))
  2185. (when (and org-export-html-link-org-files-as-html
  2186. (string-match "\\.org$" thefile))
  2187. (setq thefile (concat (substring thefile 0
  2188. (match-beginning 0))
  2189. "." html-extension))
  2190. (if (and search
  2191. ;; make sure this is can be used as target search
  2192. (not (string-match "^[0-9]*$" search))
  2193. (not (string-match "^\\*" search))
  2194. (not (string-match "^/.*/$" search)))
  2195. (setq thefile (concat thefile "#"
  2196. (org-solidify-link-text
  2197. (org-link-unescape search)))))
  2198. (when (string-match "^file:" desc)
  2199. (setq desc (replace-match "" t t desc))
  2200. (if (string-match "\\.org$" desc)
  2201. (setq desc (replace-match "" t t desc))))))
  2202. (setq rpl (if (and file-is-image-p
  2203. (or (eq t org-export-html-inline-images)
  2204. (and org-export-html-inline-images
  2205. (not descp))))
  2206. (concat "<img src=\"" thefile "\"/>")
  2207. (concat "<a href=\"" thefile "\">" desc "</a>")))
  2208. (if (not valid) (setq rpl desc))))
  2209. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  2210. (setq rpl
  2211. (save-match-data
  2212. (funcall fnc (org-link-unescape path) desc1 'html))))
  2213. (t
  2214. ;; just publish the path, as default
  2215. (setq rpl (concat "<i>&lt;" type ":"
  2216. (save-match-data (org-link-unescape path))
  2217. "&gt;</i>"))))
  2218. (setq line (replace-match rpl t t line)
  2219. start (+ start (length rpl))))
  2220. ;; TODO items
  2221. (if (and (string-match org-todo-line-regexp line)
  2222. (match-beginning 2))
  2223. (setq line
  2224. (concat (substring line 0 (match-beginning 2))
  2225. "<span class=\""
  2226. (if (member (match-string 2 line)
  2227. org-done-keywords)
  2228. "done" "todo")
  2229. "\">" (match-string 2 line)
  2230. "</span>" (substring line (match-end 2)))))
  2231. ;; Does this contain a reference to a footnote?
  2232. (when org-export-with-footnotes
  2233. (setq start 0)
  2234. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  2235. (if (get-text-property (match-beginning 2) 'org-protected line)
  2236. (setq start (match-end 2))
  2237. (let ((n (match-string 2 line)))
  2238. (setq line
  2239. (replace-match
  2240. (format
  2241. "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
  2242. (match-string 1 line) n n n)
  2243. t t line))))))
  2244. (cond
  2245. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  2246. ;; This is a headline
  2247. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  2248. txt (match-string 2 line))
  2249. (if (string-match quote-re0 txt)
  2250. (setq txt (replace-match "" t t txt)))
  2251. (if (<= level (max umax umax-toc))
  2252. (setq head-count (+ head-count 1)))
  2253. (when in-local-list
  2254. ;; Close any local lists before inserting a new header line
  2255. (while local-list-num
  2256. (org-close-li)
  2257. (insert (if (car local-list-num) "</ol>\n" "</ul>"))
  2258. (pop local-list-num))
  2259. (setq local-list-indent nil
  2260. in-local-list nil))
  2261. (setq first-heading-pos (or first-heading-pos (point)))
  2262. (org-html-level-start level txt umax
  2263. (and org-export-with-toc (<= level umax))
  2264. head-count)
  2265. ;; QUOTES
  2266. (when (string-match quote-re line)
  2267. (insert "<pre>")
  2268. (setq inquote t)))
  2269. ((and org-export-with-tables
  2270. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  2271. (if (not table-open)
  2272. ;; New table starts
  2273. (setq table-open t table-buffer nil table-orig-buffer nil))
  2274. ;; Accumulate lines
  2275. (setq table-buffer (cons line table-buffer)
  2276. table-orig-buffer (cons origline table-orig-buffer))
  2277. (when (or (not lines)
  2278. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  2279. (car lines))))
  2280. (setq table-open nil
  2281. table-buffer (nreverse table-buffer)
  2282. table-orig-buffer (nreverse table-orig-buffer))
  2283. (org-close-par-maybe)
  2284. (insert (org-format-table-html table-buffer table-orig-buffer))))
  2285. (t
  2286. ;; Normal lines
  2287. (when (string-match
  2288. (cond
  2289. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2290. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2291. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2292. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  2293. line)
  2294. (setq ind (org-get-string-indentation line)
  2295. start-is-num (match-beginning 4)
  2296. starter (if (match-beginning 2)
  2297. (substring (match-string 2 line) 0 -1))
  2298. line (substring line (match-beginning 5)))
  2299. (unless (string-match "[^ \t]" line)
  2300. ;; empty line. Pretend indentation is large.
  2301. (setq ind (if org-empty-line-terminates-plain-lists
  2302. 0
  2303. (1+ (or (car local-list-indent) 1)))))
  2304. (setq didclose nil)
  2305. (while (and in-local-list
  2306. (or (and (= ind (car local-list-indent))
  2307. (not starter))
  2308. (< ind (car local-list-indent))))
  2309. (setq didclose t)
  2310. (org-close-li)
  2311. (insert (if (car local-list-num) "</ol>\n" "</ul>"))
  2312. (pop local-list-num) (pop local-list-indent)
  2313. (setq in-local-list local-list-indent))
  2314. (cond
  2315. ((and starter
  2316. (or (not in-local-list)
  2317. (> ind (car local-list-indent))))
  2318. ;; Start new (level of) list
  2319. (org-close-par-maybe)
  2320. (insert (if start-is-num "<ol>\n<li>\n" "<ul>\n<li>\n"))
  2321. (push start-is-num local-list-num)
  2322. (push ind local-list-indent)
  2323. (setq in-local-list t))
  2324. (starter
  2325. ;; continue current list
  2326. (org-close-li)
  2327. (insert "<li>\n"))
  2328. (didclose
  2329. ;; we did close a list, normal text follows: need <p>
  2330. (org-open-par)))
  2331. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  2332. (setq line
  2333. (replace-match
  2334. (if (equal (match-string 1 line) "X")
  2335. "<b>[X]</b>"
  2336. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  2337. t t line))))
  2338. ;; Empty lines start a new paragraph. If hand-formatted lists
  2339. ;; are not fully interpreted, lines starting with "-", "+", "*"
  2340. ;; also start a new paragraph.
  2341. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  2342. ;; Is this the start of a footnote?
  2343. (when org-export-with-footnotes
  2344. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  2345. (org-close-par-maybe)
  2346. (let ((n (match-string 1 line)))
  2347. (setq line (replace-match
  2348. (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
  2349. ;; Check if the line break needs to be conserved
  2350. (cond
  2351. ((string-match "\\\\\\\\[ \t]*$" line)
  2352. (setq line (replace-match "<br/>" t t line)))
  2353. (org-export-preserve-breaks
  2354. (setq line (concat line "<br/>"))))
  2355. (insert line "\n")))))
  2356. ;; Properly close all local lists and other lists
  2357. (when inquote (insert "</pre>\n"))
  2358. (when in-local-list
  2359. ;; Close any local lists before inserting a new header line
  2360. (while local-list-num
  2361. (org-close-li)
  2362. (insert (if (car local-list-num) "</ol>\n" "</ul>\n"))
  2363. (pop local-list-num))
  2364. (setq local-list-indent nil
  2365. in-local-list nil))
  2366. (org-html-level-start 1 nil umax
  2367. (and org-export-with-toc (<= level umax))
  2368. head-count)
  2369. ;; the </div> to lose the last text-... div.
  2370. (insert "</div>\n")
  2371. (unless body-only
  2372. (when (plist-get opt-plist :auto-postamble)
  2373. (insert "<div id=\"postamble\">")
  2374. (when (and org-export-author-info author)
  2375. (insert "<p class=\"author\"> "
  2376. (nth 1 lang-words) ": " author "\n")
  2377. (when email
  2378. (if (listp (split-string email ",+ *"))
  2379. (mapc (lambda(e)
  2380. (insert "<a href=\"mailto:" e "\">&lt;"
  2381. e "&gt;</a>\n"))
  2382. (split-string email ",+ *"))
  2383. (insert "<a href=\"mailto:" email "\">&lt;"
  2384. email "&gt;</a>\n")))
  2385. (insert "</p>\n"))
  2386. (when (and date org-export-time-stamp-file)
  2387. (insert "<p class=\"date\"> "
  2388. (nth 2 lang-words) ": "
  2389. date "</p>\n"))
  2390. (insert "</div>"))
  2391. (if org-export-html-with-timestamp
  2392. (insert org-export-html-html-helper-timestamp))
  2393. (insert (or (plist-get opt-plist :postamble) ""))
  2394. (insert "</body>\n</html>\n"))
  2395. (normal-mode)
  2396. (if (eq major-mode default-major-mode) (html-mode))
  2397. ;; insert the table of contents
  2398. (goto-char (point-min))
  2399. (when thetoc
  2400. (if (or (re-search-forward
  2401. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  2402. (re-search-forward
  2403. "\\[TABLE-OF-CONTENTS\\]" nil t))
  2404. (progn
  2405. (goto-char (match-beginning 0))
  2406. (replace-match ""))
  2407. (goto-char first-heading-pos)
  2408. (when (looking-at "\\s-*</p>")
  2409. (goto-char (match-end 0))
  2410. (insert "\n")))
  2411. (insert "<div id=\"table-of-contents\">\n")
  2412. (mapc 'insert thetoc)
  2413. (insert "</div>\n"))
  2414. ;; remove empty paragraphs and lists
  2415. (goto-char (point-min))
  2416. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  2417. (replace-match ""))
  2418. (goto-char (point-min))
  2419. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  2420. (replace-match ""))
  2421. (goto-char (point-min))
  2422. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  2423. (replace-match ""))
  2424. ;; Convert whitespace place holders
  2425. (goto-char (point-min))
  2426. (let (beg end n)
  2427. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  2428. (setq n (get-text-property beg 'org-whitespace)
  2429. end (next-single-property-change beg 'org-whitespace))
  2430. (goto-char beg)
  2431. (delete-region beg end)
  2432. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  2433. (make-string n ?x)))))
  2434. (or to-buffer (save-buffer))
  2435. (goto-char (point-min))
  2436. (message "Exporting... done")
  2437. (if (eq to-buffer 'string)
  2438. (prog1 (buffer-substring (point-min) (point-max))
  2439. (kill-buffer (current-buffer)))
  2440. (current-buffer)))))
  2441. (defvar org-table-colgroup-info nil)
  2442. (defun org-format-table-ascii (lines)
  2443. "Format a table for ascii export."
  2444. (if (stringp lines)
  2445. (setq lines (org-split-string lines "\n")))
  2446. (if (not (string-match "^[ \t]*|" (car lines)))
  2447. ;; Table made by table.el - test for spanning
  2448. lines
  2449. ;; A normal org table
  2450. ;; Get rid of hlines at beginning and end
  2451. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2452. (setq lines (nreverse lines))
  2453. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2454. (setq lines (nreverse lines))
  2455. (when org-export-table-remove-special-lines
  2456. ;; Check if the table has a marking column. If yes remove the
  2457. ;; column and the special lines
  2458. (setq lines (org-table-clean-before-export lines)))
  2459. ;; Get rid of the vertical lines except for grouping
  2460. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  2461. rtn line vl1 start)
  2462. (while (setq line (pop lines))
  2463. (if (string-match org-table-hline-regexp line)
  2464. (and (string-match "|\\(.*\\)|" line)
  2465. (setq line (replace-match " \\1" t nil line)))
  2466. (setq start 0 vl1 vl)
  2467. (while (string-match "|" line start)
  2468. (setq start (match-end 0))
  2469. (or (pop vl1) (setq line (replace-match " " t t line)))))
  2470. (push line rtn))
  2471. (nreverse rtn))))
  2472. (defun org-colgroup-info-to-vline-list (info)
  2473. (let (vl new last)
  2474. (while info
  2475. (setq last new new (pop info))
  2476. (if (or (memq last '(:end :startend))
  2477. (memq new '(:start :startend)))
  2478. (push t vl)
  2479. (push nil vl)))
  2480. (setq vl (nreverse vl))
  2481. (and vl (setcar vl nil))
  2482. vl))
  2483. (defvar org-table-number-regexp) ; defined in org-table.el
  2484. (defun org-format-table-html (lines olines)
  2485. "Find out which HTML converter to use and return the HTML code."
  2486. (if (stringp lines)
  2487. (setq lines (org-split-string lines "\n")))
  2488. (if (string-match "^[ \t]*|" (car lines))
  2489. ;; A normal org table
  2490. (org-format-org-table-html lines)
  2491. ;; Table made by table.el - test for spanning
  2492. (let* ((hlines (delq nil (mapcar
  2493. (lambda (x)
  2494. (if (string-match "^[ \t]*\\+-" x) x
  2495. nil))
  2496. lines)))
  2497. (first (car hlines))
  2498. (ll (and (string-match "\\S-+" first)
  2499. (match-string 0 first)))
  2500. (re (concat "^[ \t]*" (regexp-quote ll)))
  2501. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  2502. hlines))))
  2503. (if (and (not spanning)
  2504. (not org-export-prefer-native-exporter-for-tables))
  2505. ;; We can use my own converter with HTML conversions
  2506. (org-format-table-table-html lines)
  2507. ;; Need to use the code generator in table.el, with the original text.
  2508. (org-format-table-table-html-using-table-generate-source olines)))))
  2509. (defvar org-table-number-fraction) ; defined in org-table.el
  2510. (defun org-format-org-table-html (lines &optional splice)
  2511. "Format a table into HTML."
  2512. (require 'org-table)
  2513. ;; Get rid of hlines at beginning and end
  2514. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2515. (setq lines (nreverse lines))
  2516. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2517. (setq lines (nreverse lines))
  2518. (when org-export-table-remove-special-lines
  2519. ;; Check if the table has a marking column. If yes remove the
  2520. ;; column and the special lines
  2521. (setq lines (org-table-clean-before-export lines)))
  2522. (let ((head (and org-export-highlight-first-table-line
  2523. (delq nil (mapcar
  2524. (lambda (x) (string-match "^[ \t]*|-" x))
  2525. (cdr lines)))))
  2526. (nlines 0) fnum i
  2527. tbopen line fields html gr colgropen)
  2528. (if splice (setq head nil))
  2529. (unless splice (push (if head "<thead>" "<tbody>") html))
  2530. (setq tbopen t)
  2531. (while (setq line (pop lines))
  2532. (catch 'next-line
  2533. (if (string-match "^[ \t]*|-" line)
  2534. (progn
  2535. (unless splice
  2536. (push (if head "</thead>" "</tbody>") html)
  2537. (if lines (push "<tbody>" html) (setq tbopen nil)))
  2538. (setq head nil) ;; head ends here, first time around
  2539. ;; ignore this line
  2540. (throw 'next-line t)))
  2541. ;; Break the line into fields
  2542. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  2543. (unless fnum (setq fnum (make-vector (length fields) 0)))
  2544. (setq nlines (1+ nlines) i -1)
  2545. (push (concat "<tr>"
  2546. (mapconcat
  2547. (lambda (x)
  2548. (setq i (1+ i))
  2549. (if (and (< i nlines)
  2550. (string-match org-table-number-regexp x))
  2551. (incf (aref fnum i)))
  2552. (if head
  2553. (concat (car org-export-table-header-tags) x
  2554. (cdr org-export-table-header-tags))
  2555. (concat (car org-export-table-data-tags) x
  2556. (cdr org-export-table-data-tags))))
  2557. fields "")
  2558. "</tr>")
  2559. html)))
  2560. (unless splice (if tbopen (push "</tbody>" html)))
  2561. (unless splice (push "</table>\n" html))
  2562. (setq html (nreverse html))
  2563. (unless splice
  2564. ;; Put in col tags with the alignment (unfortuntely often ignored...)
  2565. (push (mapconcat
  2566. (lambda (x)
  2567. (setq gr (pop org-table-colgroup-info))
  2568. (format "%s<col align=\"%s\"></col>%s"
  2569. (if (memq gr '(:start :startend))
  2570. (prog1
  2571. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  2572. (setq colgropen t))
  2573. "")
  2574. (if (> (/ (float x) nlines) org-table-number-fraction)
  2575. "right" "left")
  2576. (if (memq gr '(:end :startend))
  2577. (progn (setq colgropen nil) "</colgroup>")
  2578. "")))
  2579. fnum "")
  2580. html)
  2581. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  2582. (push html-table-tag html))
  2583. (concat (mapconcat 'identity html "\n") "\n")))
  2584. (defun org-table-clean-before-export (lines)
  2585. "Check if the table has a marking column.
  2586. If yes remove the column and the special lines."
  2587. (setq org-table-colgroup-info nil)
  2588. (if (memq nil
  2589. (mapcar
  2590. (lambda (x) (or (string-match "^[ \t]*|-" x)
  2591. (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
  2592. lines))
  2593. (progn
  2594. (setq org-table-clean-did-remove-column nil)
  2595. (delq nil
  2596. (mapcar
  2597. (lambda (x)
  2598. (cond
  2599. ((string-match "^[ \t]*| */ *|" x)
  2600. (setq org-table-colgroup-info
  2601. (mapcar (lambda (x)
  2602. (cond ((member x '("<" "&lt;")) :start)
  2603. ((member x '(">" "&gt;")) :end)
  2604. ((member x '("<>" "&lt;&gt;")) :startend)
  2605. (t nil)))
  2606. (org-split-string x "[ \t]*|[ \t]*")))
  2607. nil)
  2608. (t x)))
  2609. lines)))
  2610. (setq org-table-clean-did-remove-column t)
  2611. (delq nil
  2612. (mapcar
  2613. (lambda (x)
  2614. (cond
  2615. ((string-match "^[ \t]*| */ *|" x)
  2616. (setq org-table-colgroup-info
  2617. (mapcar (lambda (x)
  2618. (cond ((member x '("<" "&lt;")) :start)
  2619. ((member x '(">" "&gt;")) :end)
  2620. ((member x '("<>" "&lt;&gt;")) :startend)
  2621. (t nil)))
  2622. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  2623. nil)
  2624. ((string-match "^[ \t]*| *[!_^/] *|" x)
  2625. nil) ; ignore this line
  2626. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  2627. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  2628. ;; remove the first column
  2629. (replace-match "\\1|" t nil x))))
  2630. lines))))
  2631. (defun org-format-table-table-html (lines)
  2632. "Format a table generated by table.el into HTML.
  2633. This conversion does *not* use `table-generate-source' from table.el.
  2634. This has the advantage that Org-mode's HTML conversions can be used.
  2635. But it has the disadvantage, that no cell- or row-spanning is allowed."
  2636. (let (line field-buffer
  2637. (head org-export-highlight-first-table-line)
  2638. fields html empty)
  2639. (setq html (concat html-table-tag "\n"))
  2640. (while (setq line (pop lines))
  2641. (setq empty "&nbsp;")
  2642. (catch 'next-line
  2643. (if (string-match "^[ \t]*\\+-" line)
  2644. (progn
  2645. (if field-buffer
  2646. (progn
  2647. (setq
  2648. html
  2649. (concat
  2650. html
  2651. "<tr>"
  2652. (mapconcat
  2653. (lambda (x)
  2654. (if (equal x "") (setq x empty))
  2655. (if head
  2656. (concat (car org-export-table-header-tags) x
  2657. (cdr org-export-table-header-tags))
  2658. (concat (car org-export-table-data-tags) x
  2659. (cdr org-export-table-data-tags))))
  2660. field-buffer "\n")
  2661. "</tr>\n"))
  2662. (setq head nil)
  2663. (setq field-buffer nil)))
  2664. ;; Ignore this line
  2665. (throw 'next-line t)))
  2666. ;; Break the line into fields and store the fields
  2667. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  2668. (if field-buffer
  2669. (setq field-buffer (mapcar
  2670. (lambda (x)
  2671. (concat x "<br/>" (pop fields)))
  2672. field-buffer))
  2673. (setq field-buffer fields))))
  2674. (setq html (concat html "</table>\n"))
  2675. html))
  2676. (defun org-format-table-table-html-using-table-generate-source (lines)
  2677. "Format a table into html, using `table-generate-source' from table.el.
  2678. This has the advantage that cell- or row-spanning is allowed.
  2679. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  2680. (require 'table)
  2681. (with-current-buffer (get-buffer-create " org-tmp1 ")
  2682. (erase-buffer)
  2683. (insert (mapconcat 'identity lines "\n"))
  2684. (goto-char (point-min))
  2685. (if (not (re-search-forward "|[^+]" nil t))
  2686. (error "Error processing table"))
  2687. (table-recognize-table)
  2688. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  2689. (table-generate-source 'html " org-tmp2 ")
  2690. (set-buffer " org-tmp2 ")
  2691. (buffer-substring (point-min) (point-max))))
  2692. (defun org-html-handle-time-stamps (s)
  2693. "Format time stamps in string S, or remove them."
  2694. (catch 'exit
  2695. (let (r b)
  2696. (while (string-match org-maybe-keyword-time-regexp s)
  2697. (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
  2698. ;; never export CLOCK
  2699. (throw 'exit ""))
  2700. (or b (setq b (substring s 0 (match-beginning 0))))
  2701. (if (not org-export-with-timestamps)
  2702. (setq r (concat r (substring s 0 (match-beginning 0)))
  2703. s (substring s (match-end 0)))
  2704. (setq r (concat
  2705. r (substring s 0 (match-beginning 0))
  2706. (if (match-end 1)
  2707. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  2708. (match-string 1 s)))
  2709. (format " @<span class=\"timestamp\">%s@</span>"
  2710. (substring
  2711. (org-translate-time (match-string 3 s)) 1 -1)))
  2712. s (substring s (match-end 0)))))
  2713. ;; Line break if line started and ended with time stamp stuff
  2714. (if (not r)
  2715. s
  2716. (setq r (concat r s))
  2717. (unless (string-match "\\S-" (concat b s))
  2718. (setq r (concat r "@<br/>")))
  2719. r))))
  2720. (defun org-html-protect (s)
  2721. ;; convert & to &amp;, < to &lt; and > to &gt;
  2722. (let ((start 0))
  2723. (while (string-match "&" s start)
  2724. (setq s (replace-match "&amp;" t t s)
  2725. start (1+ (match-beginning 0))))
  2726. (while (string-match "<" s)
  2727. (setq s (replace-match "&lt;" t t s)))
  2728. (while (string-match ">" s)
  2729. (setq s (replace-match "&gt;" t t s))))
  2730. s)
  2731. (defun org-export-cleanup-toc-line (s)
  2732. "Remove tags and time staps from lines going into the toc."
  2733. (when (memq org-export-with-tags '(not-in-toc nil))
  2734. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  2735. (setq s (replace-match "" t t s))))
  2736. (when org-export-remove-timestamps-from-toc
  2737. (while (string-match org-maybe-keyword-time-regexp s)
  2738. (setq s (replace-match "" t t s))))
  2739. (while (string-match org-bracket-link-regexp s)
  2740. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  2741. t t s)))
  2742. s)
  2743. (defun org-html-expand (string)
  2744. "Prepare STRING for HTML export. Applies all active conversions.
  2745. If there are links in the string, don't modify these."
  2746. (let* ((re (concat org-bracket-link-regexp "\\|"
  2747. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  2748. m s l res)
  2749. (while (setq m (string-match re string))
  2750. (setq s (substring string 0 m)
  2751. l (match-string 0 string)
  2752. string (substring string (match-end 0)))
  2753. (push (org-html-do-expand s) res)
  2754. (push l res))
  2755. (push (org-html-do-expand string) res)
  2756. (apply 'concat (nreverse res))))
  2757. (defun org-html-do-expand (s)
  2758. "Apply all active conversions to translate special ASCII to HTML."
  2759. (setq s (org-html-protect s))
  2760. (if org-export-html-expand
  2761. (let ((start 0))
  2762. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  2763. (setq s (replace-match "<\\1>" t nil s)))))
  2764. (if org-export-with-emphasize
  2765. (setq s (org-export-html-convert-emphasize s)))
  2766. (if org-export-with-special-strings
  2767. (setq s (org-export-html-convert-special-strings s)))
  2768. (if org-export-with-sub-superscripts
  2769. (setq s (org-export-html-convert-sub-super s)))
  2770. (if org-export-with-TeX-macros
  2771. (let ((start 0) wd ass)
  2772. (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
  2773. (if (get-text-property (match-beginning 0) 'org-protected s)
  2774. (setq start (match-end 0))
  2775. (setq wd (match-string 1 s))
  2776. (if (setq ass (assoc wd org-html-entities))
  2777. (setq s (replace-match (or (cdr ass)
  2778. (concat "&" (car ass) ";"))
  2779. t t s))
  2780. (setq start (+ start (length wd))))))))
  2781. s)
  2782. (defun org-create-multibrace-regexp (left right n)
  2783. "Create a regular expression which will match a balanced sexp.
  2784. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  2785. as single character strings.
  2786. The regexp returned will match the entire expression including the
  2787. delimiters. It will also define a single group which contains the
  2788. match except for the outermost delimiters. The maximum depth of
  2789. stacked delimiters is N. Escaping delimiters is not possible."
  2790. (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
  2791. (or "\\|")
  2792. (re nothing)
  2793. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  2794. (while (> n 1)
  2795. (setq n (1- n)
  2796. re (concat re or next)
  2797. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  2798. (concat left "\\(" re "\\)" right)))
  2799. (defvar org-match-substring-regexp
  2800. (concat
  2801. "\\([^\\]\\)\\([_^]\\)\\("
  2802. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2803. "\\|"
  2804. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  2805. "\\|"
  2806. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  2807. "The regular expression matching a sub- or superscript.")
  2808. (defvar org-match-substring-with-braces-regexp
  2809. (concat
  2810. "\\([^\\]\\)\\([_^]\\)\\("
  2811. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2812. "\\)")
  2813. "The regular expression matching a sub- or superscript, forcing braces.")
  2814. (defconst org-export-html-special-string-regexps
  2815. '(("\\\\-" . "&shy;")
  2816. ("---\\([^-]\\)" . "&mdash;\\1")
  2817. ("--\\([^-]\\)" . "&ndash;\\1")
  2818. ("\\.\\.\\." . "&hellip;"))
  2819. "Regular expressions for special string conversion.")
  2820. (defun org-export-html-convert-special-strings (string)
  2821. "Convert special characters in STRING to HTML."
  2822. (let ((all org-export-html-special-string-regexps)
  2823. e a re rpl start)
  2824. (while (setq a (pop all))
  2825. (setq re (car a) rpl (cdr a) start 0)
  2826. (while (string-match re string start)
  2827. (if (get-text-property (match-beginning 0) 'org-protected string)
  2828. (setq start (match-end 0))
  2829. (setq string (replace-match rpl t nil string)))))
  2830. string))
  2831. (defun org-export-html-convert-sub-super (string)
  2832. "Convert sub- and superscripts in STRING to HTML."
  2833. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  2834. (while (string-match org-match-substring-regexp string s)
  2835. (cond
  2836. ((and requireb (match-end 8)) (setq s (match-end 2)))
  2837. ((get-text-property (match-beginning 2) 'org-protected string)
  2838. (setq s (match-end 2)))
  2839. (t
  2840. (setq s (match-end 1)
  2841. key (if (string= (match-string 2 string) "_") "sub" "sup")
  2842. c (or (match-string 8 string)
  2843. (match-string 6 string)
  2844. (match-string 5 string))
  2845. string (replace-match
  2846. (concat (match-string 1 string)
  2847. "<" key ">" c "</" key ">")
  2848. t t string)))))
  2849. (while (string-match "\\\\\\([_^]\\)" string)
  2850. (setq string (replace-match (match-string 1 string) t t string)))
  2851. string))
  2852. (defun org-export-html-convert-emphasize (string)
  2853. "Apply emphasis."
  2854. (let ((s 0) rpl)
  2855. (while (string-match org-emph-re string s)
  2856. (if (not (equal
  2857. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  2858. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  2859. (setq s (match-beginning 0)
  2860. rpl
  2861. (concat
  2862. (match-string 1 string)
  2863. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  2864. (match-string 4 string)
  2865. (nth 3 (assoc (match-string 3 string)
  2866. org-emphasis-alist))
  2867. (match-string 5 string))
  2868. string (replace-match rpl t t string)
  2869. s (+ s (- (length rpl) 2)))
  2870. (setq s (1+ s))))
  2871. string))
  2872. (defvar org-par-open nil)
  2873. (defun org-open-par ()
  2874. "Insert <p>, but first close previous paragraph if any."
  2875. (org-close-par-maybe)
  2876. (insert "\n<p>")
  2877. (setq org-par-open t))
  2878. (defun org-close-par-maybe ()
  2879. "Close paragraph if there is one open."
  2880. (when org-par-open
  2881. (insert "</p>")
  2882. (setq org-par-open nil)))
  2883. (defun org-close-li ()
  2884. "Close <li> if necessary."
  2885. (org-close-par-maybe)
  2886. (insert "</li>\n"))
  2887. (defvar body-only) ; dynamically scoped into this.
  2888. (defun org-html-level-start (level title umax with-toc head-count)
  2889. "Insert a new level in HTML export.
  2890. When TITLE is nil, just close all open levels."
  2891. (org-close-par-maybe)
  2892. (let ((l org-level-max) snumber)
  2893. (while (>= l level)
  2894. (if (aref org-levels-open (1- l))
  2895. (progn
  2896. (org-html-level-close l umax)
  2897. (aset org-levels-open (1- l) nil)))
  2898. (setq l (1- l)))
  2899. (when title
  2900. ;; If title is nil, this means this function is called to close
  2901. ;; all levels, so the rest is done only if title is given
  2902. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  2903. (setq title (replace-match
  2904. (if org-export-with-tags
  2905. (save-match-data
  2906. (concat
  2907. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  2908. (mapconcat 'identity (org-split-string
  2909. (match-string 1 title) ":")
  2910. "&nbsp;")
  2911. "</span>"))
  2912. "")
  2913. t t title)))
  2914. (if (> level umax)
  2915. (progn
  2916. (if (aref org-levels-open (1- level))
  2917. (progn
  2918. (org-close-li)
  2919. (insert "<li>" title "<br/>\n"))
  2920. (aset org-levels-open (1- level) t)
  2921. (org-close-par-maybe)
  2922. (insert "<ul>\n<li>" title "<br/>\n")))
  2923. (aset org-levels-open (1- level) t)
  2924. (setq snumber (org-section-number level))
  2925. (if (and org-export-with-section-numbers (not body-only))
  2926. (setq title (concat snumber " " title)))
  2927. (setq level (+ level org-export-html-toplevel-hlevel -1))
  2928. (unless (= head-count 1) (insert "\n</div>\n"))
  2929. (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s</h%d>\n<div id=\"text-%s\">\n"
  2930. snumber level level snumber title level snumber))
  2931. (org-open-par)))))
  2932. (defun org-html-level-close (level max-outline-level)
  2933. "Terminate one level in HTML export."
  2934. (if (<= level max-outline-level)
  2935. (insert "</div>\n")
  2936. (org-close-li)
  2937. (insert "</ul>\n")))
  2938. ;;; iCalendar export
  2939. ;;;###autoload
  2940. (defun org-export-icalendar-this-file ()
  2941. "Export current file as an iCalendar file.
  2942. The iCalendar file will be located in the same directory as the Org-mode
  2943. file, but with extension `.ics'."
  2944. (interactive)
  2945. (org-export-icalendar nil buffer-file-name))
  2946. ;;;###autoload
  2947. (defun org-export-icalendar-all-agenda-files ()
  2948. "Export all files in `org-agenda-files' to iCalendar .ics files.
  2949. Each iCalendar file will be located in the same directory as the Org-mode
  2950. file, but with extension `.ics'."
  2951. (interactive)
  2952. (apply 'org-export-icalendar nil (org-agenda-files t)))
  2953. ;;;###autoload
  2954. (defun org-export-icalendar-combine-agenda-files ()
  2955. "Export all files in `org-agenda-files' to a single combined iCalendar file.
  2956. The file is stored under the name `org-combined-agenda-icalendar-file'."
  2957. (interactive)
  2958. (apply 'org-export-icalendar t (org-agenda-files t)))
  2959. (defun org-export-icalendar (combine &rest files)
  2960. "Create iCalendar files for all elements of FILES.
  2961. If COMBINE is non-nil, combine all calendar entries into a single large
  2962. file and store it under the name `org-combined-agenda-icalendar-file'."
  2963. (save-excursion
  2964. (org-prepare-agenda-buffers files)
  2965. (let* ((dir (org-export-directory
  2966. :ical (list :publishing-directory
  2967. org-export-publishing-directory)))
  2968. file ical-file ical-buffer category started org-agenda-new-buffers)
  2969. (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
  2970. (when combine
  2971. (setq ical-file
  2972. (if (file-name-absolute-p org-combined-agenda-icalendar-file)
  2973. org-combined-agenda-icalendar-file
  2974. (expand-file-name org-combined-agenda-icalendar-file dir))
  2975. ical-buffer (org-get-agenda-file-buffer ical-file))
  2976. (set-buffer ical-buffer) (erase-buffer))
  2977. (while (setq file (pop files))
  2978. (catch 'nextfile
  2979. (org-check-agenda-file file)
  2980. (set-buffer (org-get-agenda-file-buffer file))
  2981. (unless combine
  2982. (setq ical-file (concat (file-name-as-directory dir)
  2983. (file-name-sans-extension
  2984. (file-name-nondirectory buffer-file-name))
  2985. ".ics"))
  2986. (setq ical-buffer (org-get-agenda-file-buffer ical-file))
  2987. (with-current-buffer ical-buffer (erase-buffer)))
  2988. (setq category (or org-category
  2989. (file-name-sans-extension
  2990. (file-name-nondirectory buffer-file-name))))
  2991. (if (symbolp category) (setq category (symbol-name category)))
  2992. (let ((standard-output ical-buffer))
  2993. (if combine
  2994. (and (not started) (setq started t)
  2995. (org-start-icalendar-file org-icalendar-combined-name))
  2996. (org-start-icalendar-file category))
  2997. (org-print-icalendar-entries combine)
  2998. (when (or (and combine (not files)) (not combine))
  2999. (org-finish-icalendar-file)
  3000. (set-buffer ical-buffer)
  3001. (save-buffer)
  3002. (run-hooks 'org-after-save-iCalendar-file-hook)))))
  3003. (org-release-buffers org-agenda-new-buffers))))
  3004. (defvar org-after-save-iCalendar-file-hook nil
  3005. "Hook run after an iCalendar file has been saved.
  3006. The iCalendar buffer is still current when this hook is run.
  3007. A good way to use this is to tell a desktop calenndar application to re-read
  3008. the iCalendar file.")
  3009. (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
  3010. (defun org-print-icalendar-entries (&optional combine)
  3011. "Print iCalendar entries for the current Org-mode file to `standard-output'.
  3012. When COMBINE is non nil, add the category to each line."
  3013. (require 'org-agenda)
  3014. (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
  3015. (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
  3016. (dts (org-ical-ts-to-string
  3017. (format-time-string (cdr org-time-stamp-formats) (current-time))
  3018. "DTSTART"))
  3019. hd ts ts2 state status (inc t) pos b sexp rrule
  3020. scheduledp deadlinep tmp pri category entry location summary desc
  3021. (sexp-buffer (get-buffer-create "*ical-tmp*")))
  3022. (org-refresh-category-properties)
  3023. (save-excursion
  3024. (goto-char (point-min))
  3025. (while (re-search-forward re1 nil t)
  3026. (catch :skip
  3027. (org-agenda-skip)
  3028. (when (boundp 'org-icalendar-verify-function)
  3029. (unless (funcall org-icalendar-verify-function)
  3030. (outline-next-heading)
  3031. (backward-char 1)
  3032. (throw :skip nil)))
  3033. (setq pos (match-beginning 0)
  3034. ts (match-string 0)
  3035. inc t
  3036. hd (condition-case nil (org-get-heading)
  3037. (error (throw :skip nil)))
  3038. summary (org-icalendar-cleanup-string
  3039. (org-entry-get nil "SUMMARY"))
  3040. desc (org-icalendar-cleanup-string
  3041. (or (org-entry-get nil "DESCRIPTION")
  3042. (and org-icalendar-include-body (org-get-entry)))
  3043. t org-icalendar-include-body)
  3044. location (org-icalendar-cleanup-string
  3045. (org-entry-get nil "LOCATION"))
  3046. category (org-get-category))
  3047. (if (looking-at re2)
  3048. (progn
  3049. (goto-char (match-end 0))
  3050. (setq ts2 (match-string 1) inc nil))
  3051. (setq tmp (buffer-substring (max (point-min)
  3052. (- pos org-ds-keyword-length))
  3053. pos)
  3054. ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
  3055. (progn
  3056. (setq inc nil)
  3057. (replace-match "\\1" t nil ts))
  3058. ts)
  3059. deadlinep (string-match org-deadline-regexp tmp)
  3060. scheduledp (string-match org-scheduled-regexp tmp)
  3061. ;; donep (org-entry-is-done-p)
  3062. ))
  3063. (if (or (string-match org-tr-regexp hd)
  3064. (string-match org-ts-regexp hd))
  3065. (setq hd (replace-match "" t t hd)))
  3066. (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
  3067. (setq rrule
  3068. (concat "\nRRULE:FREQ="
  3069. (cdr (assoc
  3070. (match-string 2 ts)
  3071. '(("d" . "DAILY")("w" . "WEEKLY")
  3072. ("m" . "MONTHLY")("y" . "YEARLY"))))
  3073. ";INTERVAL=" (match-string 1 ts)))
  3074. (setq rrule ""))
  3075. (setq summary (or summary hd))
  3076. (if (string-match org-bracket-link-regexp summary)
  3077. (setq summary
  3078. (replace-match (if (match-end 3)
  3079. (match-string 3 summary)
  3080. (match-string 1 summary))
  3081. t t summary)))
  3082. (if deadlinep (setq summary (concat "DL: " summary)))
  3083. (if scheduledp (setq summary (concat "S: " summary)))
  3084. (if (string-match "\\`<%%" ts)
  3085. (with-current-buffer sexp-buffer
  3086. (insert (substring ts 1 -1) " " summary "\n"))
  3087. (princ (format "BEGIN:VEVENT
  3088. %s
  3089. %s%s
  3090. SUMMARY:%s%s%s
  3091. CATEGORIES:%s
  3092. END:VEVENT\n"
  3093. (org-ical-ts-to-string ts "DTSTART")
  3094. (org-ical-ts-to-string ts2 "DTEND" inc)
  3095. rrule summary
  3096. (if (and desc (string-match "\\S-" desc))
  3097. (concat "\nDESCRIPTION: " desc) "")
  3098. (if (and location (string-match "\\S-" location))
  3099. (concat "\nLOCATION: " location) "")
  3100. category)))))
  3101. (when (and org-icalendar-include-sexps
  3102. (condition-case nil (require 'icalendar) (error nil))
  3103. (fboundp 'icalendar-export-region))
  3104. ;; Get all the literal sexps
  3105. (goto-char (point-min))
  3106. (while (re-search-forward "^&?%%(" nil t)
  3107. (catch :skip
  3108. (org-agenda-skip)
  3109. (setq b (match-beginning 0))
  3110. (goto-char (1- (match-end 0)))
  3111. (forward-sexp 1)
  3112. (end-of-line 1)
  3113. (setq sexp (buffer-substring b (point)))
  3114. (with-current-buffer sexp-buffer
  3115. (insert sexp "\n"))
  3116. (princ (org-diary-to-ical-string sexp-buffer)))))
  3117. (when org-icalendar-include-todo
  3118. (goto-char (point-min))
  3119. (while (re-search-forward org-todo-line-regexp nil t)
  3120. (catch :skip
  3121. (org-agenda-skip)
  3122. (when (boundp 'org-icalendar-verify-function)
  3123. (unless (funcall org-icalendar-verify-function)
  3124. (outline-next-heading)
  3125. (backward-char 1)
  3126. (throw :skip nil)))
  3127. (setq state (match-string 2))
  3128. (setq status (if (member state org-done-keywords)
  3129. "COMPLETED" "NEEDS-ACTION"))
  3130. (when (and state
  3131. (or (not (member state org-done-keywords))
  3132. (eq org-icalendar-include-todo 'all))
  3133. (not (member org-archive-tag (org-get-tags-at)))
  3134. )
  3135. (setq hd (match-string 3)
  3136. summary (org-icalendar-cleanup-string
  3137. (org-entry-get nil "SUMMARY"))
  3138. desc (org-icalendar-cleanup-string
  3139. (or (org-entry-get nil "DESCRIPTION")
  3140. (and org-icalendar-include-body (org-get-entry)))
  3141. t org-icalendar-include-body)
  3142. location (org-icalendar-cleanup-string
  3143. (org-entry-get nil "LOCATION")))
  3144. (if (string-match org-bracket-link-regexp hd)
  3145. (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
  3146. (match-string 1 hd))
  3147. t t hd)))
  3148. (if (string-match org-priority-regexp hd)
  3149. (setq pri (string-to-char (match-string 2 hd))
  3150. hd (concat (substring hd 0 (match-beginning 1))
  3151. (substring hd (match-end 1))))
  3152. (setq pri org-default-priority))
  3153. (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
  3154. (- org-lowest-priority org-highest-priority))))))
  3155. (princ (format "BEGIN:VTODO
  3156. %s
  3157. SUMMARY:%s%s%s
  3158. CATEGORIES:%s
  3159. SEQUENCE:1
  3160. PRIORITY:%d
  3161. STATUS:%s
  3162. END:VTODO\n"
  3163. dts
  3164. (or summary hd)
  3165. (if (and location (string-match "\\S-" location))
  3166. (concat "\nLOCATION: " location) "")
  3167. (if (and desc (string-match "\\S-" desc))
  3168. (concat "\nDESCRIPTION: " desc) "")
  3169. category pri status)))))))))
  3170. (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
  3171. "Take out stuff and quote what needs to be quoted.
  3172. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  3173. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  3174. characters."
  3175. (if (not s)
  3176. nil
  3177. (when is-body
  3178. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  3179. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  3180. (while (string-match re s) (setq s (replace-match "" t t s)))
  3181. (while (string-match re2 s) (setq s (replace-match "" t t s)))))
  3182. (let ((start 0))
  3183. (while (string-match "\\([,;\\]\\)" s start)
  3184. (setq start (+ (match-beginning 0) 2)
  3185. s (replace-match "\\\\\\1" nil nil s))))
  3186. (when is-body
  3187. (while (string-match "[ \t]*\n[ \t]*" s)
  3188. (setq s (replace-match "\\n" t t s))))
  3189. (setq s (org-trim s))
  3190. (if is-body
  3191. (if maxlength
  3192. (if (and (numberp maxlength)
  3193. (> (length s) maxlength))
  3194. (setq s (substring s 0 maxlength)))))
  3195. s))
  3196. (defun org-get-entry ()
  3197. "Clean-up description string."
  3198. (save-excursion
  3199. (org-back-to-heading t)
  3200. (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
  3201. (defun org-start-icalendar-file (name)
  3202. "Start an iCalendar file by inserting the header."
  3203. (let ((user user-full-name)
  3204. (name (or name "unknown"))
  3205. (timezone (cadr (current-time-zone))))
  3206. (princ
  3207. (format "BEGIN:VCALENDAR
  3208. VERSION:2.0
  3209. X-WR-CALNAME:%s
  3210. PRODID:-//%s//Emacs with Org-mode//EN
  3211. X-WR-TIMEZONE:%s
  3212. CALSCALE:GREGORIAN\n" name user timezone))))
  3213. (defun org-finish-icalendar-file ()
  3214. "Finish an iCalendar file by inserting the END statement."
  3215. (princ "END:VCALENDAR\n"))
  3216. (defun org-ical-ts-to-string (s keyword &optional inc)
  3217. "Take a time string S and convert it to iCalendar format.
  3218. KEYWORD is added in front, to make a complete line like DTSTART....
  3219. When INC is non-nil, increase the hour by two (if time string contains
  3220. a time), or the day by one (if it does not contain a time)."
  3221. (let ((t1 (org-parse-time-string s 'nodefault))
  3222. t2 fmt have-time time)
  3223. (if (and (car t1) (nth 1 t1) (nth 2 t1))
  3224. (setq t2 t1 have-time t)
  3225. (setq t2 (org-parse-time-string s)))
  3226. (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
  3227. (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
  3228. (when inc
  3229. (if have-time
  3230. (if org-agenda-default-appointment-duration
  3231. (setq mi (+ org-agenda-default-appointment-duration mi))
  3232. (setq h (+ 2 h)))
  3233. (setq d (1+ d))))
  3234. (setq time (encode-time s mi h d m y)))
  3235. (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
  3236. (concat keyword (format-time-string fmt time))))
  3237. ;;; XOXO export
  3238. (defun org-export-as-xoxo-insert-into (buffer &rest output)
  3239. (with-current-buffer buffer
  3240. (apply 'insert output)))
  3241. (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
  3242. ;;;###autoload
  3243. (defun org-export-as-xoxo (&optional buffer)
  3244. "Export the org buffer as XOXO.
  3245. The XOXO buffer is named *xoxo-<source buffer name>*"
  3246. (interactive (list (current-buffer)))
  3247. ;; A quickie abstraction
  3248. ;; Output everything as XOXO
  3249. (with-current-buffer (get-buffer buffer)
  3250. (let* ((pos (point))
  3251. (opt-plist (org-combine-plists (org-default-export-plist)
  3252. (org-infile-export-plist)))
  3253. (filename (concat (file-name-as-directory
  3254. (org-export-directory :xoxo opt-plist))
  3255. (file-name-sans-extension
  3256. (file-name-nondirectory buffer-file-name))
  3257. ".html"))
  3258. (out (find-file-noselect filename))
  3259. (last-level 1)
  3260. (hanging-li nil))
  3261. (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
  3262. ;; Check the output buffer is empty.
  3263. (with-current-buffer out (erase-buffer))
  3264. ;; Kick off the output
  3265. (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
  3266. (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
  3267. (let* ((hd (match-string-no-properties 1))
  3268. (level (length hd))
  3269. (text (concat
  3270. (match-string-no-properties 2)
  3271. (save-excursion
  3272. (goto-char (match-end 0))
  3273. (let ((str ""))
  3274. (catch 'loop
  3275. (while 't
  3276. (forward-line)
  3277. (if (looking-at "^[ \t]\\(.*\\)")
  3278. (setq str (concat str (match-string-no-properties 1)))
  3279. (throw 'loop str)))))))))
  3280. ;; Handle level rendering
  3281. (cond
  3282. ((> level last-level)
  3283. (org-export-as-xoxo-insert-into out "\n<ol>\n"))
  3284. ((< level last-level)
  3285. (dotimes (- (- last-level level) 1)
  3286. (if hanging-li
  3287. (org-export-as-xoxo-insert-into out "</li>\n"))
  3288. (org-export-as-xoxo-insert-into out "</ol>\n"))
  3289. (when hanging-li
  3290. (org-export-as-xoxo-insert-into out "</li>\n")
  3291. (setq hanging-li nil)))
  3292. ((equal level last-level)
  3293. (if hanging-li
  3294. (org-export-as-xoxo-insert-into out "</li>\n")))
  3295. )
  3296. (setq last-level level)
  3297. ;; And output the new li
  3298. (setq hanging-li 't)
  3299. (if (equal ?+ (elt text 0))
  3300. (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
  3301. (org-export-as-xoxo-insert-into out "<li>" text))))
  3302. ;; Finally finish off the ol
  3303. (dotimes (- last-level 1)
  3304. (if hanging-li
  3305. (org-export-as-xoxo-insert-into out "</li>\n"))
  3306. (org-export-as-xoxo-insert-into out "</ol>\n"))
  3307. (goto-char pos)
  3308. ;; Finish the buffer off and clean it up.
  3309. (switch-to-buffer-other-window out)
  3310. (indent-region (point-min) (point-max) nil)
  3311. (save-buffer)
  3312. (goto-char (point-min))
  3313. )))
  3314. (provide 'org-exp)
  3315. ;;; org-exp.el ends here