org-exp.el 185 KB

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