org-exp.el 168 KB

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