org-exp.el 178 KB

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