org-exp.el 132 KB

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