org-exp.el 178 KB

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