org-exp.el 162 KB

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