org-exp.el 152 KB

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