org-exp.el 159 KB

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