org-exp.el 164 KB

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