org-exp.el 157 KB

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