org-exp.el 159 KB

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