org-exp.el 187 KB

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