org-exp.el 152 KB

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