org-exp.el 184 KB

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