org-exp.el 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730
  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.13
  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 "\\(^#.*\n\\)^\\*+[ \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. ;; Remove forced line breaks
  2203. (if (string-match "\\\\\\\\[ \t]*$" line)
  2204. (setq line (replace-match "" t t line)))
  2205. (if (and org-export-with-fixed-width
  2206. (string-match "^\\([ \t]*\\)\\(:\\)" line))
  2207. (setq line (replace-match "\\1" nil nil line)))
  2208. (insert line "\n"))))
  2209. (normal-mode)
  2210. ;; insert the table of contents
  2211. (when thetoc
  2212. (goto-char (point-min))
  2213. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  2214. (progn
  2215. (goto-char (match-beginning 0))
  2216. (replace-match ""))
  2217. (goto-char first-heading-pos))
  2218. (mapc 'insert thetoc)
  2219. (or (looking-at "[ \t]*\n[ \t]*\n")
  2220. (insert "\n\n")))
  2221. ;; Convert whitespace place holders
  2222. (goto-char (point-min))
  2223. (let (beg end)
  2224. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  2225. (setq end (next-single-property-change beg 'org-whitespace))
  2226. (goto-char beg)
  2227. (delete-region beg end)
  2228. (insert (make-string (- end beg) ?\ ))))
  2229. (save-buffer)
  2230. ;; remove display and invisible chars
  2231. (let (beg end)
  2232. (goto-char (point-min))
  2233. (while (setq beg (next-single-property-change (point) 'display))
  2234. (setq end (next-single-property-change beg 'display))
  2235. (delete-region beg end)
  2236. (goto-char beg)
  2237. (insert "=>"))
  2238. (goto-char (point-min))
  2239. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  2240. (setq end (next-single-property-change beg 'org-cwidth))
  2241. (delete-region beg end)
  2242. (goto-char beg)))
  2243. (goto-char (point-min))))
  2244. (defun org-export-ascii-preprocess ()
  2245. "Do extra work for ASCII export"
  2246. (goto-char (point-min))
  2247. (while (re-search-forward org-verbatim-re nil t)
  2248. (goto-char (match-end 2))
  2249. (backward-delete-char 1) (insert "'")
  2250. (goto-char (match-beginning 2))
  2251. (delete-char 1) (insert "`")
  2252. (goto-char (match-end 2))))
  2253. (defun org-search-todo-below (line lines level)
  2254. "Search the subtree below LINE for any TODO entries."
  2255. (let ((rest (cdr (memq line lines)))
  2256. (re org-todo-line-regexp)
  2257. line lv todo)
  2258. (catch 'exit
  2259. (while (setq line (pop rest))
  2260. (if (string-match re line)
  2261. (progn
  2262. (setq lv (- (match-end 1) (match-beginning 1))
  2263. todo (and (match-beginning 2)
  2264. (not (member (match-string 2 line)
  2265. org-done-keywords))))
  2266. ; TODO, not DONE
  2267. (if (<= lv level) (throw 'exit nil))
  2268. (if todo (throw 'exit t))))))))
  2269. (defun org-html-expand-for-ascii (line)
  2270. "Handle quoted HTML for ASCII export."
  2271. (if org-export-html-expand
  2272. (while (string-match "@<[^<>\n]*>" line)
  2273. ;; We just remove the tags for now.
  2274. (setq line (replace-match "" nil nil line))))
  2275. line)
  2276. (defun org-insert-centered (s &optional underline)
  2277. "Insert the string S centered and underline it with character UNDERLINE."
  2278. (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
  2279. (insert (make-string ind ?\ ) s "\n")
  2280. (if underline
  2281. (insert (make-string ind ?\ )
  2282. (make-string (string-width s) underline)
  2283. "\n"))))
  2284. (defun org-ascii-level-start (level title umax &optional lines)
  2285. "Insert a new level in ASCII export."
  2286. (let (char (n (- level umax 1)) (ind 0))
  2287. (if (> level umax)
  2288. (progn
  2289. (insert (make-string (* 2 n) ?\ )
  2290. (char-to-string (nth (% n (length org-export-ascii-bullets))
  2291. org-export-ascii-bullets))
  2292. " " title "\n")
  2293. ;; find the indentation of the next non-empty line
  2294. (catch 'stop
  2295. (while lines
  2296. (if (string-match "^\\* " (car lines)) (throw 'stop nil))
  2297. (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
  2298. (throw 'stop (setq ind (org-get-indentation (car lines)))))
  2299. (pop lines)))
  2300. (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
  2301. (if (or (not (equal (char-before) ?\n))
  2302. (not (equal (char-before (1- (point))) ?\n)))
  2303. (insert "\n"))
  2304. (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
  2305. (unless org-export-with-tags
  2306. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  2307. (setq title (replace-match "" t t title))))
  2308. (if org-export-with-section-numbers
  2309. (setq title (concat (org-section-number level) " " title)))
  2310. (insert title "\n" (make-string (string-width title) char) "\n")
  2311. (setq org-ascii-current-indentation '(0 . 0)))))
  2312. ;;;###autoload
  2313. (defun org-export-visible (type arg)
  2314. "Create a copy of the visible part of the current buffer, and export it.
  2315. The copy is created in a temporary buffer and removed after use.
  2316. TYPE is the final key (as a string) that also select the export command in
  2317. the `C-c C-e' export dispatcher.
  2318. As a special case, if the you type SPC at the prompt, the temporary
  2319. org-mode file will not be removed but presented to you so that you can
  2320. continue to use it. The prefix arg ARG is passed through to the exporting
  2321. command."
  2322. (interactive
  2323. (list (progn
  2324. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
  2325. (read-char-exclusive))
  2326. current-prefix-arg))
  2327. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
  2328. (error "Invalid export key"))
  2329. (let* ((binding (cdr (assoc type
  2330. '((?a . org-export-as-ascii)
  2331. (?\C-a . org-export-as-ascii)
  2332. (?b . org-export-as-html-and-open)
  2333. (?\C-b . org-export-as-html-and-open)
  2334. (?h . org-export-as-html)
  2335. (?H . org-export-as-html-to-buffer)
  2336. (?R . org-export-region-as-html)
  2337. (?x . org-export-as-xoxo)))))
  2338. (keepp (equal type ?\ ))
  2339. (file buffer-file-name)
  2340. (buffer (get-buffer-create "*Org Export Visible*"))
  2341. s e)
  2342. ;; Need to hack the drawers here.
  2343. (save-excursion
  2344. (goto-char (point-min))
  2345. (while (re-search-forward org-drawer-regexp nil t)
  2346. (goto-char (match-beginning 1))
  2347. (or (org-invisible-p) (org-flag-drawer nil))))
  2348. (with-current-buffer buffer (erase-buffer))
  2349. (save-excursion
  2350. (setq s (goto-char (point-min)))
  2351. (while (not (= (point) (point-max)))
  2352. (goto-char (org-find-invisible))
  2353. (append-to-buffer buffer s (point))
  2354. (setq s (goto-char (org-find-visible))))
  2355. (org-cycle-hide-drawers 'all)
  2356. (goto-char (point-min))
  2357. (unless keepp
  2358. ;; Copy all comment lines to the end, to make sure #+ settings are
  2359. ;; still available for the second export step. Kind of a hack, but
  2360. ;; does do the trick.
  2361. (if (looking-at "#[^\r\n]*")
  2362. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  2363. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  2364. (append-to-buffer buffer (1+ (match-beginning 0))
  2365. (min (point-max) (1+ (match-end 0))))))
  2366. (set-buffer buffer)
  2367. (let ((buffer-file-name file)
  2368. (org-inhibit-startup t))
  2369. (org-mode)
  2370. (show-all)
  2371. (unless keepp (funcall binding arg))))
  2372. (if (not keepp)
  2373. (kill-buffer buffer)
  2374. (switch-to-buffer-other-window buffer)
  2375. (goto-char (point-min)))))
  2376. (defun org-find-visible ()
  2377. (let ((s (point)))
  2378. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2379. (get-char-property s 'invisible)))
  2380. s))
  2381. (defun org-find-invisible ()
  2382. (let ((s (point)))
  2383. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2384. (not (get-char-property s 'invisible))))
  2385. s))
  2386. ;;; HTML export
  2387. (defvar org-archive-location) ;; gets loades with the org-archive require.
  2388. (defun org-get-current-options ()
  2389. "Return a string with current options as keyword options.
  2390. Does include HTML export options as well as TODO and CATEGORY stuff."
  2391. (require 'org-archive)
  2392. (format
  2393. "#+TITLE: %s
  2394. #+AUTHOR: %s
  2395. #+EMAIL: %s
  2396. #+DATE: %s
  2397. #+LANGUAGE: %s
  2398. #+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
  2399. %s
  2400. #+EXPORT_SELECT_TAGS: %s
  2401. #+EXPORT_EXCLUDE_TAGS: %s
  2402. #+LINK_UP: %s
  2403. #+LINK_HOME: %s
  2404. #+CATEGORY: %s
  2405. #+SEQ_TODO: %s
  2406. #+TYP_TODO: %s
  2407. #+PRIORITIES: %c %c %c
  2408. #+DRAWERS: %s
  2409. #+STARTUP: %s %s %s %s %s
  2410. #+TAGS: %s
  2411. #+FILETAGS: %s
  2412. #+ARCHIVE: %s
  2413. #+LINK: %s
  2414. "
  2415. (buffer-name) (user-full-name) user-mail-address
  2416. (format-time-string (substring (car org-time-stamp-formats) 1 -1))
  2417. org-export-default-language
  2418. org-export-headline-levels
  2419. org-export-with-section-numbers
  2420. org-export-with-toc
  2421. org-export-preserve-breaks
  2422. org-export-html-expand
  2423. org-export-with-fixed-width
  2424. org-export-with-tables
  2425. org-export-with-sub-superscripts
  2426. org-export-with-special-strings
  2427. org-export-with-footnotes
  2428. org-export-with-emphasize
  2429. org-export-with-TeX-macros
  2430. org-export-with-LaTeX-fragments
  2431. org-export-skip-text-before-1st-heading
  2432. org-export-with-drawers
  2433. org-export-with-tags
  2434. (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
  2435. (mapconcat 'identity org-export-select-tags " ")
  2436. (mapconcat 'identity org-export-exclude-tags " ")
  2437. org-export-html-link-up
  2438. org-export-html-link-home
  2439. (file-name-nondirectory buffer-file-name)
  2440. "TODO FEEDBACK VERIFY DONE"
  2441. "Me Jason Marie DONE"
  2442. org-highest-priority org-lowest-priority org-default-priority
  2443. (mapconcat 'identity org-drawers " ")
  2444. (cdr (assoc org-startup-folded
  2445. '((nil . "showall") (t . "overview") (content . "content"))))
  2446. (if org-odd-levels-only "odd" "oddeven")
  2447. (if org-hide-leading-stars "hidestars" "showstars")
  2448. (if org-startup-align-all-tables "align" "noalign")
  2449. (cond ((eq org-log-done t) "logdone")
  2450. ((equal org-log-done 'note) "lognotedone")
  2451. ((not org-log-done) "nologdone"))
  2452. (or (mapconcat (lambda (x)
  2453. (cond
  2454. ((equal '(:startgroup) x) "{")
  2455. ((equal '(:endgroup) x) "}")
  2456. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  2457. (t (car x))))
  2458. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  2459. (mapconcat 'identity org-file-tags " ")
  2460. org-archive-location
  2461. "org file:~/org/%s.org"
  2462. ))
  2463. (defun org-export-html-preprocess (parameters)
  2464. ;; Convert LaTeX fragments to images
  2465. (when (plist-get parameters :LaTeX-fragments)
  2466. (org-format-latex
  2467. (concat "ltxpng/" (file-name-sans-extension
  2468. (file-name-nondirectory
  2469. org-current-export-file)))
  2470. org-current-export-dir nil "Creating LaTeX image %s"))
  2471. (message "Exporting..."))
  2472. ;;;###autoload
  2473. (defun org-insert-export-options-template ()
  2474. "Insert into the buffer a template with information for exporting."
  2475. (interactive)
  2476. (if (not (bolp)) (newline))
  2477. (let ((s (org-get-current-options)))
  2478. (and (string-match "#\\+CATEGORY" s)
  2479. (setq s (substring s 0 (match-beginning 0))))
  2480. (insert s)))
  2481. ;;;###autoload
  2482. (defun org-export-as-html-and-open (arg)
  2483. "Export the outline as HTML and immediately open it with a browser.
  2484. If there is an active region, export only the region.
  2485. The prefix ARG specifies how many levels of the outline should become
  2486. headlines. The default is 3. Lower levels will become bulleted lists."
  2487. (interactive "P")
  2488. (org-export-as-html arg 'hidden)
  2489. (org-open-file buffer-file-name))
  2490. ;;;###autoload
  2491. (defun org-export-as-html-batch ()
  2492. "Call `org-export-as-html', may be used in batch processing as
  2493. emacs --batch
  2494. --load=$HOME/lib/emacs/org.el
  2495. --eval \"(setq org-export-headline-levels 2)\"
  2496. --visit=MyFile --funcall org-export-as-html-batch"
  2497. (org-export-as-html org-export-headline-levels 'hidden))
  2498. ;;;###autoload
  2499. (defun org-export-as-html-to-buffer (arg)
  2500. "Call `org-exort-as-html` with output to a temporary buffer.
  2501. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  2502. (interactive "P")
  2503. (org-export-as-html arg nil nil "*Org HTML Export*")
  2504. (switch-to-buffer-other-window "*Org HTML Export*"))
  2505. ;;;###autoload
  2506. (defun org-replace-region-by-html (beg end)
  2507. "Assume the current region has org-mode syntax, and convert it to HTML.
  2508. This can be used in any buffer. For example, you could write an
  2509. itemized list in org-mode syntax in an HTML buffer and then use this
  2510. command to convert it."
  2511. (interactive "r")
  2512. (let (reg html buf pop-up-frames)
  2513. (save-window-excursion
  2514. (if (org-mode-p)
  2515. (setq html (org-export-region-as-html
  2516. beg end t 'string))
  2517. (setq reg (buffer-substring beg end)
  2518. buf (get-buffer-create "*Org tmp*"))
  2519. (with-current-buffer buf
  2520. (erase-buffer)
  2521. (insert reg)
  2522. (org-mode)
  2523. (setq html (org-export-region-as-html
  2524. (point-min) (point-max) t 'string)))
  2525. (kill-buffer buf)))
  2526. (delete-region beg end)
  2527. (insert html)))
  2528. ;;;###autoload
  2529. (defun org-export-region-as-html (beg end &optional body-only buffer)
  2530. "Convert region from BEG to END in org-mode buffer to HTML.
  2531. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  2532. contents, and only produce the region of converted text, useful for
  2533. cut-and-paste operations.
  2534. If BUFFER is a buffer or a string, use/create that buffer as a target
  2535. of the converted HTML. If BUFFER is the symbol `string', return the
  2536. produced HTML as a string and leave not buffer behind. For example,
  2537. a Lisp program could call this function in the following way:
  2538. (setq html (org-export-region-as-html beg end t 'string))
  2539. When called interactively, the output buffer is selected, and shown
  2540. in a window. A non-interactive call will only return the buffer."
  2541. (interactive "r\nP")
  2542. (when (interactive-p)
  2543. (setq buffer "*Org HTML Export*"))
  2544. (let ((transient-mark-mode t) (zmacs-regions t)
  2545. ext-plist rtn)
  2546. (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
  2547. (goto-char end)
  2548. (set-mark (point)) ;; to activate the region
  2549. (goto-char beg)
  2550. (setq rtn (org-export-as-html
  2551. nil nil ext-plist
  2552. buffer body-only))
  2553. (if (fboundp 'deactivate-mark) (deactivate-mark))
  2554. (if (and (interactive-p) (bufferp rtn))
  2555. (switch-to-buffer-other-window rtn)
  2556. rtn)))
  2557. (defvar html-table-tag nil) ; dynamically scoped into this.
  2558. (defvar org-par-open nil)
  2559. ;;;###autoload
  2560. (defun org-export-as-html (arg &optional hidden ext-plist
  2561. to-buffer body-only pub-dir)
  2562. "Export the outline as a pretty HTML file.
  2563. If there is an active region, export only the region. The prefix
  2564. ARG specifies how many levels of the outline should become
  2565. headlines. The default is 3. Lower levels will become bulleted
  2566. lists. When HIDDEN is non-nil, don't display the HTML buffer.
  2567. EXT-PLIST is a property list with external parameters overriding
  2568. org-mode's default settings, but still inferior to file-local
  2569. settings. When TO-BUFFER is non-nil, create a buffer with that
  2570. name and export to that buffer. If TO-BUFFER is the symbol
  2571. `string', don't leave any buffer behind but just return the
  2572. resulting HTML as a string. When BODY-ONLY is set, don't produce
  2573. the file header and footer, simply return the content of
  2574. <body>...</body>, without even the body tags themselves. When
  2575. PUB-DIR is set, use this as the publishing directory."
  2576. (interactive "P")
  2577. ;; Make sure we have a file name when we need it.
  2578. (when (and (not (or to-buffer body-only))
  2579. (not buffer-file-name))
  2580. (if (buffer-base-buffer)
  2581. (org-set-local 'buffer-file-name
  2582. (with-current-buffer (buffer-base-buffer)
  2583. buffer-file-name))
  2584. (error "Need a file name to be able to export.")))
  2585. (message "Exporting...")
  2586. (setq-default org-todo-line-regexp org-todo-line-regexp)
  2587. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  2588. (setq-default org-done-keywords org-done-keywords)
  2589. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  2590. (let* ((opt-plist
  2591. (org-export-process-option-filters
  2592. (org-combine-plists (org-default-export-plist)
  2593. ext-plist
  2594. (org-infile-export-plist))))
  2595. (style (concat (if (plist-get opt-plist :style-include-default)
  2596. org-export-html-style-default)
  2597. (plist-get opt-plist :style)
  2598. (plist-get opt-plist :style-extra)))
  2599. (html-extension (plist-get opt-plist :html-extension))
  2600. (link-validate (plist-get opt-plist :link-validation-function))
  2601. valid thetoc have-headings first-heading-pos
  2602. (odd org-odd-levels-only)
  2603. (region-p (org-region-active-p))
  2604. (rbeg (and region-p (region-beginning)))
  2605. (rend (and region-p (region-end)))
  2606. (subtree-p
  2607. (if (plist-get opt-plist :ignore-subree-p)
  2608. nil
  2609. (when region-p
  2610. (save-excursion
  2611. (goto-char rbeg)
  2612. (and (org-at-heading-p)
  2613. (>= (org-end-of-subtree t t) rend))))))
  2614. (opt-plist (if subtree-p
  2615. (org-export-add-subtree-options opt-plist rbeg)
  2616. opt-plist))
  2617. ;; The following two are dynamically scoped into other
  2618. ;; routines below.
  2619. (org-current-export-dir
  2620. (or pub-dir (org-export-directory :html opt-plist)))
  2621. (org-current-export-file buffer-file-name)
  2622. (level 0) (line "") (origline "") txt todo
  2623. (umax nil)
  2624. (umax-toc nil)
  2625. (filename (if to-buffer nil
  2626. (expand-file-name
  2627. (concat
  2628. (file-name-sans-extension
  2629. (or (and subtree-p
  2630. (org-entry-get (region-beginning)
  2631. "EXPORT_FILE_NAME" t))
  2632. (file-name-nondirectory buffer-file-name)))
  2633. "." html-extension)
  2634. (file-name-as-directory
  2635. (or pub-dir (org-export-directory :html opt-plist))))))
  2636. (current-dir (if buffer-file-name
  2637. (file-name-directory buffer-file-name)
  2638. default-directory))
  2639. (buffer (if to-buffer
  2640. (cond
  2641. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  2642. (t (get-buffer-create to-buffer)))
  2643. (find-file-noselect filename)))
  2644. (org-levels-open (make-vector org-level-max nil))
  2645. (date (plist-get opt-plist :date))
  2646. (author (plist-get opt-plist :author))
  2647. (title (or (and subtree-p (org-export-get-title-from-subtree))
  2648. (plist-get opt-plist :title)
  2649. (and (not
  2650. (plist-get opt-plist :skip-before-1st-heading))
  2651. (org-export-grab-title-from-buffer))
  2652. (and buffer-file-name
  2653. (file-name-sans-extension
  2654. (file-name-nondirectory buffer-file-name)))
  2655. "UNTITLED"))
  2656. (html-table-tag (plist-get opt-plist :html-table-tag))
  2657. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  2658. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  2659. (inquote nil)
  2660. (infixed nil)
  2661. (inverse nil)
  2662. (in-local-list nil)
  2663. (local-list-type nil)
  2664. (local-list-indent nil)
  2665. (llt org-plain-list-ordered-item-terminator)
  2666. (email (plist-get opt-plist :email))
  2667. (language (plist-get opt-plist :language))
  2668. (lang-words nil)
  2669. (head-count 0) cnt
  2670. (start 0)
  2671. (coding-system (and (boundp 'buffer-file-coding-system)
  2672. buffer-file-coding-system))
  2673. (coding-system-for-write (or org-export-html-coding-system
  2674. coding-system))
  2675. (save-buffer-coding-system (or org-export-html-coding-system
  2676. coding-system))
  2677. (charset (and coding-system-for-write
  2678. (fboundp 'coding-system-get)
  2679. (coding-system-get coding-system-for-write
  2680. 'mime-charset)))
  2681. (region
  2682. (buffer-substring
  2683. (if region-p (region-beginning) (point-min))
  2684. (if region-p (region-end) (point-max))))
  2685. (lines
  2686. (org-split-string
  2687. (org-export-preprocess-string
  2688. region
  2689. :emph-multiline t
  2690. :for-html t
  2691. :skip-before-1st-heading
  2692. (plist-get opt-plist :skip-before-1st-heading)
  2693. :drawers (plist-get opt-plist :drawers)
  2694. :archived-trees
  2695. (plist-get opt-plist :archived-trees)
  2696. :select-tags (plist-get opt-plist :select-tags)
  2697. :exclude-tags (plist-get opt-plist :exclude-tags)
  2698. :add-text
  2699. (plist-get opt-plist :text)
  2700. :LaTeX-fragments
  2701. (plist-get opt-plist :LaTeX-fragments))
  2702. "[\r\n]"))
  2703. table-open type
  2704. table-buffer table-orig-buffer
  2705. ind item-type starter didclose
  2706. rpl path attr desc descp desc1 desc2 link
  2707. snumber fnc item-tag
  2708. footnotes
  2709. )
  2710. (let ((inhibit-read-only t))
  2711. (org-unmodified
  2712. (remove-text-properties (point-min) (point-max)
  2713. '(:org-license-to-kill t))))
  2714. (message "Exporting...")
  2715. (setq org-min-level (org-get-min-level lines))
  2716. (setq org-last-level org-min-level)
  2717. (org-init-section-numbers)
  2718. (cond
  2719. ((and date (string-match "%" date))
  2720. (setq date (format-time-string date)))
  2721. (date)
  2722. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  2723. ;; Get the language-dependent settings
  2724. (setq lang-words (or (assoc language org-export-language-setup)
  2725. (assoc "en" org-export-language-setup)))
  2726. ;; Switch to the output buffer
  2727. (set-buffer buffer)
  2728. (let ((inhibit-read-only t)) (erase-buffer))
  2729. (fundamental-mode)
  2730. (and (fboundp 'set-buffer-file-coding-system)
  2731. (set-buffer-file-coding-system coding-system-for-write))
  2732. (let ((case-fold-search nil)
  2733. (org-odd-levels-only odd))
  2734. ;; create local variables for all options, to make sure all called
  2735. ;; functions get the correct information
  2736. (mapc (lambda (x)
  2737. (set (make-local-variable (cdr x))
  2738. (plist-get opt-plist (car x))))
  2739. org-export-plist-vars)
  2740. (setq umax (if arg (prefix-numeric-value arg)
  2741. org-export-headline-levels))
  2742. (setq umax-toc (if (integerp org-export-with-toc)
  2743. (min org-export-with-toc umax)
  2744. umax))
  2745. (unless body-only
  2746. ;; File header
  2747. (insert (format
  2748. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  2749. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  2750. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  2751. lang=\"%s\" xml:lang=\"%s\">
  2752. <head>
  2753. <title>%s</title>
  2754. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  2755. <meta name=\"generator\" content=\"Org-mode\"/>
  2756. <meta name=\"generated\" content=\"%s\"/>
  2757. <meta name=\"author\" content=\"%s\"/>
  2758. %s
  2759. </head><body>
  2760. "
  2761. language language (org-html-expand title)
  2762. (or charset "iso-8859-1") date author style))
  2763. (insert (or (plist-get opt-plist :preamble) ""))
  2764. (when (plist-get opt-plist :auto-preamble)
  2765. (if title (insert (format org-export-html-title-format
  2766. (org-html-expand title))))))
  2767. (if (and org-export-with-toc (not body-only))
  2768. (progn
  2769. (push (format "<h%d>%s</h%d>\n"
  2770. org-export-html-toplevel-hlevel
  2771. (nth 3 lang-words)
  2772. org-export-html-toplevel-hlevel)
  2773. thetoc)
  2774. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  2775. (push "<ul>\n<li>" thetoc)
  2776. (setq lines
  2777. (mapcar '(lambda (line)
  2778. (if (string-match org-todo-line-regexp line)
  2779. ;; This is a headline
  2780. (progn
  2781. (setq have-headings t)
  2782. (setq level (- (match-end 1) (match-beginning 1))
  2783. level (org-tr-level level)
  2784. txt (save-match-data
  2785. (org-html-expand
  2786. (org-export-cleanup-toc-line
  2787. (match-string 3 line))))
  2788. todo
  2789. (or (and org-export-mark-todo-in-toc
  2790. (match-beginning 2)
  2791. (not (member (match-string 2 line)
  2792. org-done-keywords)))
  2793. ; TODO, not DONE
  2794. (and org-export-mark-todo-in-toc
  2795. (= level umax-toc)
  2796. (org-search-todo-below
  2797. line lines level))))
  2798. (if (string-match
  2799. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  2800. (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  2801. (if (string-match quote-re0 txt)
  2802. (setq txt (replace-match "" t t txt)))
  2803. (setq snumber (org-section-number level))
  2804. (if org-export-with-section-numbers
  2805. (setq txt (concat snumber " " txt)))
  2806. (if (<= level (max umax umax-toc))
  2807. (setq head-count (+ head-count 1)))
  2808. (if (<= level umax-toc)
  2809. (progn
  2810. (if (> level org-last-level)
  2811. (progn
  2812. (setq cnt (- level org-last-level))
  2813. (while (>= (setq cnt (1- cnt)) 0)
  2814. (push "\n<ul>\n<li>" thetoc))
  2815. (push "\n" thetoc)))
  2816. (if (< level org-last-level)
  2817. (progn
  2818. (setq cnt (- org-last-level level))
  2819. (while (>= (setq cnt (1- cnt)) 0)
  2820. (push "</li>\n</ul>" thetoc))
  2821. (push "\n" thetoc)))
  2822. ;; Check for targets
  2823. (while (string-match org-any-target-regexp line)
  2824. (setq line (replace-match
  2825. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2826. t t line)))
  2827. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  2828. (setq txt (replace-match "" t t txt)))
  2829. (push
  2830. (format
  2831. (if todo
  2832. "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
  2833. "</li>\n<li><a href=\"#sec-%s\">%s</a>")
  2834. snumber txt) thetoc)
  2835. (setq org-last-level level))
  2836. )))
  2837. line)
  2838. lines))
  2839. (while (> org-last-level (1- org-min-level))
  2840. (setq org-last-level (1- org-last-level))
  2841. (push "</li>\n</ul>\n" thetoc))
  2842. (push "</div>\n" thetoc)
  2843. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  2844. (setq head-count 0)
  2845. (org-init-section-numbers)
  2846. (org-open-par)
  2847. (while (setq line (pop lines) origline line)
  2848. (catch 'nextline
  2849. ;; end of quote section?
  2850. (when (and inquote (string-match "^\\*+ " line))
  2851. (insert "</pre>\n")
  2852. (setq inquote nil))
  2853. ;; inside a quote section?
  2854. (when inquote
  2855. (insert (org-html-protect line) "\n")
  2856. (throw 'nextline nil))
  2857. ;; Fixed-width, verbatim lines (examples)
  2858. (when (and org-export-with-fixed-width
  2859. (string-match "^[ \t]*:\\(.*\\)" line))
  2860. (when (not infixed)
  2861. (setq infixed t)
  2862. (org-close-par-maybe)
  2863. (insert "<pre class=\"example\">\n"))
  2864. (insert (org-html-protect (match-string 1 line)) "\n")
  2865. (when (or (not lines)
  2866. (not (string-match "^[ \t]*\\(:.*\\)"
  2867. (car lines))))
  2868. (setq infixed nil)
  2869. (insert "</pre>\n"))
  2870. (throw 'nextline nil))
  2871. ;; Protected HTML
  2872. (when (get-text-property 0 'org-protected line)
  2873. (let (par)
  2874. (when (re-search-backward
  2875. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  2876. (setq par (match-string 1))
  2877. (replace-match "\\2\n"))
  2878. (insert line "\n")
  2879. (while (and lines
  2880. (not (string-match "^[ \t]*:" (car lines)))
  2881. (or (= (length (car lines)) 0)
  2882. (get-text-property 0 'org-protected (car lines))))
  2883. (insert (pop lines) "\n"))
  2884. (and par (insert "<p>\n")))
  2885. (throw 'nextline nil))
  2886. ;; Horizontal line
  2887. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  2888. (if org-par-open
  2889. (insert "\n</p>\n<hr/>\n<p>\n")
  2890. (insert "\n<hr/>\n"))
  2891. (throw 'nextline nil))
  2892. ;; Blockquotes and verse
  2893. (when (equal "ORG-BLOCKQUOTE-START" line)
  2894. (insert "<blockquote>\n<p>\n")
  2895. (throw 'nextline nil))
  2896. (when (equal "ORG-BLOCKQUOTE-END" line)
  2897. (insert "</p>\n</blockquote>\n")
  2898. (throw 'nextline nil))
  2899. (when (equal "ORG-VERSE-START" line)
  2900. (insert "\n<p class=\"verse\">\n")
  2901. (setq inverse t)
  2902. (throw 'nextline nil))
  2903. (when (equal "ORG-VERSE-END" line)
  2904. (insert "</p>\n")
  2905. (setq inverse nil)
  2906. (throw 'nextline nil))
  2907. (when inverse
  2908. (let ((i (org-get-string-indentation line)))
  2909. (if (> i 0)
  2910. (setq line (concat (mapconcat 'identity
  2911. (make-list (* 2 i) "\\nbsp") "")
  2912. " " (org-trim line))))
  2913. (setq line (concat line " \\\\"))))
  2914. ;; make targets to anchors
  2915. (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
  2916. (cond
  2917. ((match-end 2)
  2918. (setq line (replace-match
  2919. (format
  2920. "@<a name=\"%s\" id=\"%s\">@</a>"
  2921. (org-solidify-link-text (match-string 1 line))
  2922. (org-solidify-link-text (match-string 1 line)))
  2923. t t line)))
  2924. ((and org-export-with-toc (equal (string-to-char line) ?*))
  2925. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  2926. (setq line (replace-match
  2927. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2928. ; (concat "@<i>" (match-string 1 line) "@</i> ")
  2929. t t line)))
  2930. (t
  2931. (setq line (replace-match
  2932. (concat "@<a name=\""
  2933. (org-solidify-link-text (match-string 1 line))
  2934. "\" class=\"target\">" (match-string 1 line) "@</a> ")
  2935. t t line)))))
  2936. (setq line (org-html-handle-time-stamps line))
  2937. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  2938. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  2939. ;; Also handle sub_superscripts and checkboxes
  2940. (or (string-match org-table-hline-regexp line)
  2941. (setq line (org-html-expand line)))
  2942. ;; Format the links
  2943. (setq start 0)
  2944. (while (string-match org-bracket-link-analytic-regexp line start)
  2945. (setq start (match-beginning 0))
  2946. (setq path (save-match-data (org-link-unescape
  2947. (match-string 3 line))))
  2948. (setq type (cond
  2949. ((match-end 2) (match-string 2 line))
  2950. ((save-match-data
  2951. (or (file-name-absolute-p path)
  2952. (string-match "^\\.\\.?/" path)))
  2953. "file")
  2954. (t "internal")))
  2955. (setq path (org-extract-attributes path))
  2956. (setq attr (org-attributes-to-string
  2957. (get-text-property 0 'org-attributes path)))
  2958. (setq desc1 (if (match-end 5) (match-string 5 line))
  2959. desc2 (if (match-end 2) (concat type ":" path) path)
  2960. descp (and desc1 (not (equal desc1 desc2)))
  2961. desc (or desc1 desc2))
  2962. ;; Make an image out of the description if that is so wanted
  2963. (when (and descp (org-file-image-p desc))
  2964. (save-match-data
  2965. (if (string-match "^file:" desc)
  2966. (setq desc (substring desc (match-end 0)))))
  2967. (setq desc (org-add-props
  2968. (concat "<img src=\"" desc "\"/>")
  2969. '(org-protected t))))
  2970. ;; FIXME: do we need to unescape here somewhere?
  2971. (cond
  2972. ((equal type "internal")
  2973. (setq rpl
  2974. (concat
  2975. "<a href=\"#"
  2976. (org-solidify-link-text
  2977. (save-match-data (org-link-unescape path)) nil)
  2978. "\"" attr ">"
  2979. (org-export-html-format-desc desc)
  2980. "</a>")))
  2981. ((member type '("http" "https"))
  2982. ;; standard URL, just check if we need to inline an image
  2983. (if (and (or (eq t org-export-html-inline-images)
  2984. (and org-export-html-inline-images (not descp)))
  2985. (org-file-image-p path))
  2986. (setq rpl (concat "<img src=\"" type ":" path "\""
  2987. (if (string-match "\\<alt=" attr)
  2988. attr (concat attr " alt=\"" path "\""))
  2989. "/>"))
  2990. (setq link (concat type ":" path))
  2991. (setq rpl (concat "<a href=\""
  2992. (org-export-html-format-href link)
  2993. "\"" attr ">"
  2994. (org-export-html-format-desc desc)
  2995. "</a>"))))
  2996. ((member type '("ftp" "mailto" "news"))
  2997. ;; standard URL
  2998. (setq link (concat type ":" path))
  2999. (setq rpl (concat "<a href=\""
  3000. (org-export-html-format-href link)
  3001. "\"" attr ">"
  3002. (org-export-html-format-desc desc)
  3003. "</a>")))
  3004. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  3005. ;; The link protocol has a function for format the link
  3006. (setq rpl
  3007. (save-match-data
  3008. (funcall fnc (org-link-unescape path) desc1 'html))))
  3009. ((string= type "file")
  3010. ;; FILE link
  3011. (let* ((filename path)
  3012. (abs-p (file-name-absolute-p filename))
  3013. thefile file-is-image-p search)
  3014. (save-match-data
  3015. (if (string-match "::\\(.*\\)" filename)
  3016. (setq search (match-string 1 filename)
  3017. filename (replace-match "" t nil filename)))
  3018. (setq valid
  3019. (if (functionp link-validate)
  3020. (funcall link-validate filename current-dir)
  3021. t))
  3022. (setq file-is-image-p (org-file-image-p filename))
  3023. (setq thefile (if abs-p (expand-file-name filename) filename))
  3024. (when (and org-export-html-link-org-files-as-html
  3025. (string-match "\\.org$" thefile))
  3026. (setq thefile (concat (substring thefile 0
  3027. (match-beginning 0))
  3028. "." html-extension))
  3029. (if (and search
  3030. ;; make sure this is can be used as target search
  3031. (not (string-match "^[0-9]*$" search))
  3032. (not (string-match "^\\*" search))
  3033. (not (string-match "^/.*/$" search)))
  3034. (setq thefile (concat thefile "#"
  3035. (org-solidify-link-text
  3036. (org-link-unescape search)))))
  3037. (when (string-match "^file:" desc)
  3038. (setq desc (replace-match "" t t desc))
  3039. (if (string-match "\\.org$" desc)
  3040. (setq desc (replace-match "" t t desc))))))
  3041. (setq rpl (if (and file-is-image-p
  3042. (or (eq t org-export-html-inline-images)
  3043. (and org-export-html-inline-images
  3044. (not descp))))
  3045. (concat "<img src=\"" thefile "\""
  3046. (if (string-match "alt=" attr)
  3047. attr
  3048. (concat attr " alt=\""
  3049. thefile "\"")) "/>")
  3050. (concat "<a href=\"" thefile "\"" attr ">"
  3051. (org-export-html-format-desc desc)
  3052. "</a>")))
  3053. (if (not valid) (setq rpl desc))))
  3054. (t
  3055. ;; just publish the path, as default
  3056. (setq rpl (concat "<i>&lt;" type ":"
  3057. (save-match-data (org-link-unescape path))
  3058. "&gt;</i>"))))
  3059. (setq line (replace-match rpl t t line)
  3060. start (+ start (length rpl))))
  3061. ;; TODO items
  3062. (if (and (string-match org-todo-line-regexp line)
  3063. (match-beginning 2))
  3064. (setq line
  3065. (concat (substring line 0 (match-beginning 2))
  3066. "<span class=\""
  3067. (if (member (match-string 2 line)
  3068. org-done-keywords)
  3069. "done" "todo")
  3070. "\">" (match-string 2 line)
  3071. "</span>" (substring line (match-end 2)))))
  3072. ;; Does this contain a reference to a footnote?
  3073. (when org-export-with-footnotes
  3074. (setq start 0)
  3075. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  3076. (if (get-text-property (match-beginning 2) 'org-protected line)
  3077. (setq start (match-end 2))
  3078. (let ((n (match-string 2 line)))
  3079. (setq line
  3080. (replace-match
  3081. (format
  3082. "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
  3083. (match-string 1 line) n n n)
  3084. t t line))))))
  3085. (cond
  3086. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  3087. ;; This is a headline
  3088. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  3089. txt (match-string 2 line))
  3090. (if (string-match quote-re0 txt)
  3091. (setq txt (replace-match "" t t txt)))
  3092. (if (<= level (max umax umax-toc))
  3093. (setq head-count (+ head-count 1)))
  3094. (when in-local-list
  3095. ;; Close any local lists before inserting a new header line
  3096. (while local-list-type
  3097. (org-close-li (car local-list-type))
  3098. (insert (format "</%sl>\n" (car local-list-type)))
  3099. (pop local-list-type))
  3100. (setq local-list-indent nil
  3101. in-local-list nil))
  3102. (setq first-heading-pos (or first-heading-pos (point)))
  3103. (org-html-level-start level txt umax
  3104. (and org-export-with-toc (<= level umax))
  3105. head-count)
  3106. ;; QUOTES
  3107. (when (string-match quote-re line)
  3108. (org-close-par-maybe)
  3109. (insert "<pre>")
  3110. (setq inquote t)))
  3111. ((and org-export-with-tables
  3112. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  3113. (if (not table-open)
  3114. ;; New table starts
  3115. (setq table-open t table-buffer nil table-orig-buffer nil))
  3116. ;; Accumulate lines
  3117. (setq table-buffer (cons line table-buffer)
  3118. table-orig-buffer (cons origline table-orig-buffer))
  3119. (when (or (not lines)
  3120. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  3121. (car lines))))
  3122. (setq table-open nil
  3123. table-buffer (nreverse table-buffer)
  3124. table-orig-buffer (nreverse table-orig-buffer))
  3125. (org-close-par-maybe)
  3126. (insert (org-format-table-html table-buffer table-orig-buffer))))
  3127. (t
  3128. ;; Normal lines
  3129. (when (string-match
  3130. (cond
  3131. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  3132. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  3133. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  3134. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  3135. line)
  3136. (setq ind (org-get-string-indentation line)
  3137. item-type (if (match-beginning 4) "o" "u")
  3138. starter (if (match-beginning 2)
  3139. (substring (match-string 2 line) 0 -1))
  3140. line (substring line (match-beginning 5))
  3141. item-tag nil)
  3142. (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
  3143. (setq item-type "d"
  3144. item-tag (match-string 1 line)
  3145. line (substring line (match-end 0))))
  3146. (when (and (not (equal item-type "d"))
  3147. (not (string-match "[^ \t]" line)))
  3148. ;; empty line. Pretend indentation is large.
  3149. (setq ind (if org-empty-line-terminates-plain-lists
  3150. 0
  3151. (1+ (or (car local-list-indent) 1)))))
  3152. (setq didclose nil)
  3153. (while (and in-local-list
  3154. (or (and (= ind (car local-list-indent))
  3155. (not starter))
  3156. (< ind (car local-list-indent))))
  3157. (setq didclose t)
  3158. (org-close-li (car local-list-type))
  3159. (insert (format "</%sl>\n" (car local-list-type)))
  3160. (pop local-list-type) (pop local-list-indent)
  3161. (setq in-local-list local-list-indent))
  3162. (cond
  3163. ((and starter
  3164. (or (not in-local-list)
  3165. (> ind (car local-list-indent))))
  3166. ;; Start new (level of) list
  3167. (org-close-par-maybe)
  3168. (insert (cond
  3169. ((equal item-type "u") "<ul>\n<li>\n")
  3170. ((equal item-type "o") "<ol>\n<li>\n")
  3171. ((equal item-type "d")
  3172. (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
  3173. (push item-type local-list-type)
  3174. (push ind local-list-indent)
  3175. (setq in-local-list t))
  3176. (starter
  3177. ;; continue current list
  3178. (org-close-li (car local-list-type))
  3179. (insert (cond
  3180. ((equal (car local-list-type) "d")
  3181. (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
  3182. (t "<li>\n"))))
  3183. (didclose
  3184. ;; we did close a list, normal text follows: need <p>
  3185. (org-open-par)))
  3186. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  3187. (setq line
  3188. (replace-match
  3189. (if (equal (match-string 1 line) "X")
  3190. "<b>[X]</b>"
  3191. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  3192. t t line))))
  3193. ;; Empty lines start a new paragraph. If hand-formatted lists
  3194. ;; are not fully interpreted, lines starting with "-", "+", "*"
  3195. ;; also start a new paragraph.
  3196. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  3197. ;; Is this the start of a footnote?
  3198. (when org-export-with-footnotes
  3199. (when (and (boundp 'footnote-section-tag-regexp)
  3200. (string-match (concat "^" footnote-section-tag-regexp)
  3201. line))
  3202. ;; ignore this line
  3203. (throw 'nextline nil))
  3204. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  3205. (org-close-par-maybe)
  3206. (let ((n (match-string 1 line)))
  3207. (setq org-par-open t
  3208. line (replace-match
  3209. (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
  3210. ;; Check if the line break needs to be conserved
  3211. (cond
  3212. ((string-match "\\\\\\\\[ \t]*$" line)
  3213. (setq line (replace-match "<br/>" t t line)))
  3214. (org-export-preserve-breaks
  3215. (setq line (concat line "<br/>"))))
  3216. (insert line "\n")))))
  3217. ;; Properly close all local lists and other lists
  3218. (when inquote
  3219. (insert "</pre>\n")
  3220. (org-open-par))
  3221. (when in-local-list
  3222. ;; Close any local lists before inserting a new header line
  3223. (while local-list-type
  3224. (org-close-li (car local-list-type))
  3225. (insert (format "</%sl>\n" (car local-list-type)))
  3226. (pop local-list-type))
  3227. (setq local-list-indent nil
  3228. in-local-list nil))
  3229. (org-html-level-start 1 nil umax
  3230. (and org-export-with-toc (<= level umax))
  3231. head-count)
  3232. ;; the </div> to close the last text-... div.
  3233. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  3234. (save-excursion
  3235. (goto-char (point-min))
  3236. (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
  3237. (push (match-string 0) footnotes)
  3238. (replace-match "" t t)))
  3239. (when footnotes
  3240. (insert (format org-export-html-footnotes-section
  3241. (or (nth 4 lang-words) "Footnotes")
  3242. (mapconcat 'identity (nreverse footnotes) "\n"))
  3243. "\n"))
  3244. (unless body-only
  3245. (when (plist-get opt-plist :auto-postamble)
  3246. (insert "<div id=\"postamble\">")
  3247. (when (and org-export-author-info author)
  3248. (insert "<p class=\"author\"> "
  3249. (nth 1 lang-words) ": " author "\n")
  3250. (when email
  3251. (if (listp (split-string email ",+ *"))
  3252. (mapc (lambda(e)
  3253. (insert "<a href=\"mailto:" e "\">&lt;"
  3254. e "&gt;</a>\n"))
  3255. (split-string email ",+ *"))
  3256. (insert "<a href=\"mailto:" email "\">&lt;"
  3257. email "&gt;</a>\n")))
  3258. (insert "</p>\n"))
  3259. (when (and date org-export-time-stamp-file)
  3260. (insert "<p class=\"date\"> "
  3261. (nth 2 lang-words) ": "
  3262. date "</p>\n"))
  3263. (when org-export-creator-info
  3264. (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
  3265. org-version emacs-major-version)))
  3266. (insert "</div>"))
  3267. (if org-export-html-with-timestamp
  3268. (insert org-export-html-html-helper-timestamp))
  3269. (insert (or (plist-get opt-plist :postamble) ""))
  3270. (insert "</body>\n</html>\n"))
  3271. (unless (plist-get opt-plist :buffer-will-be-killed)
  3272. (normal-mode)
  3273. (if (eq major-mode default-major-mode) (html-mode)))
  3274. ;; insert the table of contents
  3275. (goto-char (point-min))
  3276. (when thetoc
  3277. (if (or (re-search-forward
  3278. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  3279. (re-search-forward
  3280. "\\[TABLE-OF-CONTENTS\\]" nil t))
  3281. (progn
  3282. (goto-char (match-beginning 0))
  3283. (replace-match ""))
  3284. (goto-char first-heading-pos)
  3285. (when (looking-at "\\s-*</p>")
  3286. (goto-char (match-end 0))
  3287. (insert "\n")))
  3288. (insert "<div id=\"table-of-contents\">\n")
  3289. (mapc 'insert thetoc)
  3290. (insert "</div>\n"))
  3291. ;; remove empty paragraphs and lists
  3292. (goto-char (point-min))
  3293. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  3294. (replace-match ""))
  3295. (goto-char (point-min))
  3296. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  3297. (replace-match ""))
  3298. (goto-char (point-min))
  3299. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  3300. (replace-match ""))
  3301. ;; Convert whitespace place holders
  3302. (goto-char (point-min))
  3303. (let (beg end n)
  3304. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  3305. (setq n (get-text-property beg 'org-whitespace)
  3306. end (next-single-property-change beg 'org-whitespace))
  3307. (goto-char beg)
  3308. (delete-region beg end)
  3309. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  3310. (make-string n ?x)))))
  3311. (or to-buffer (save-buffer))
  3312. (goto-char (point-min))
  3313. (message "Exporting... done")
  3314. (if (eq to-buffer 'string)
  3315. (prog1 (buffer-substring (point-min) (point-max))
  3316. (kill-buffer (current-buffer)))
  3317. (current-buffer)))))
  3318. (defun org-export-html-format-href (s)
  3319. "Make sure the S is valid as a href reference in an XHTML document."
  3320. (save-match-data
  3321. (let ((start 0))
  3322. (while (string-match "&" s start)
  3323. (setq start (+ (match-beginning 0) 3)
  3324. s (replace-match "&amp;" t t s)))))
  3325. s)
  3326. (defun org-export-html-format-desc (s)
  3327. "Make sure the S is valid as a description in a link."
  3328. (if (and s (not (get-text-property 1 'org-protected s)))
  3329. (save-match-data
  3330. (org-html-do-expand s))
  3331. s))
  3332. (defvar org-table-colgroup-info nil)
  3333. (defun org-format-table-ascii (lines)
  3334. "Format a table for ascii export."
  3335. (if (stringp lines)
  3336. (setq lines (org-split-string lines "\n")))
  3337. (if (not (string-match "^[ \t]*|" (car lines)))
  3338. ;; Table made by table.el - test for spanning
  3339. lines
  3340. ;; A normal org table
  3341. ;; Get rid of hlines at beginning and end
  3342. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3343. (setq lines (nreverse lines))
  3344. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3345. (setq lines (nreverse lines))
  3346. (when org-export-table-remove-special-lines
  3347. ;; Check if the table has a marking column. If yes remove the
  3348. ;; column and the special lines
  3349. (setq lines (org-table-clean-before-export lines)))
  3350. ;; Get rid of the vertical lines except for grouping
  3351. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  3352. rtn line vl1 start)
  3353. (while (setq line (pop lines))
  3354. (if (string-match org-table-hline-regexp line)
  3355. (and (string-match "|\\(.*\\)|" line)
  3356. (setq line (replace-match " \\1" t nil line)))
  3357. (setq start 0 vl1 vl)
  3358. (while (string-match "|" line start)
  3359. (setq start (match-end 0))
  3360. (or (pop vl1) (setq line (replace-match " " t t line)))))
  3361. (push line rtn))
  3362. (nreverse rtn))))
  3363. (defun org-colgroup-info-to-vline-list (info)
  3364. (let (vl new last)
  3365. (while info
  3366. (setq last new new (pop info))
  3367. (if (or (memq last '(:end :startend))
  3368. (memq new '(:start :startend)))
  3369. (push t vl)
  3370. (push nil vl)))
  3371. (setq vl (nreverse vl))
  3372. (and vl (setcar vl nil))
  3373. vl))
  3374. (defvar org-table-number-regexp) ; defined in org-table.el
  3375. (defun org-format-table-html (lines olines)
  3376. "Find out which HTML converter to use and return the HTML code."
  3377. (if (stringp lines)
  3378. (setq lines (org-split-string lines "\n")))
  3379. (if (string-match "^[ \t]*|" (car lines))
  3380. ;; A normal org table
  3381. (org-format-org-table-html lines)
  3382. ;; Table made by table.el - test for spanning
  3383. (let* ((hlines (delq nil (mapcar
  3384. (lambda (x)
  3385. (if (string-match "^[ \t]*\\+-" x) x
  3386. nil))
  3387. lines)))
  3388. (first (car hlines))
  3389. (ll (and (string-match "\\S-+" first)
  3390. (match-string 0 first)))
  3391. (re (concat "^[ \t]*" (regexp-quote ll)))
  3392. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  3393. hlines))))
  3394. (if (and (not spanning)
  3395. (not org-export-prefer-native-exporter-for-tables))
  3396. ;; We can use my own converter with HTML conversions
  3397. (org-format-table-table-html lines)
  3398. ;; Need to use the code generator in table.el, with the original text.
  3399. (org-format-table-table-html-using-table-generate-source olines)))))
  3400. (defvar org-table-number-fraction) ; defined in org-table.el
  3401. (defun org-format-org-table-html (lines &optional splice)
  3402. "Format a table into HTML."
  3403. (require 'org-table)
  3404. ;; Get rid of hlines at beginning and end
  3405. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3406. (setq lines (nreverse lines))
  3407. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3408. (setq lines (nreverse lines))
  3409. (when org-export-table-remove-special-lines
  3410. ;; Check if the table has a marking column. If yes remove the
  3411. ;; column and the special lines
  3412. (setq lines (org-table-clean-before-export lines)))
  3413. (let ((head (and org-export-highlight-first-table-line
  3414. (delq nil (mapcar
  3415. (lambda (x) (string-match "^[ \t]*|-" x))
  3416. (cdr lines)))))
  3417. (nlines 0) fnum i
  3418. tbopen line fields html gr colgropen)
  3419. (if splice (setq head nil))
  3420. (unless splice (push (if head "<thead>" "<tbody>") html))
  3421. (setq tbopen t)
  3422. (while (setq line (pop lines))
  3423. (catch 'next-line
  3424. (if (string-match "^[ \t]*|-" line)
  3425. (progn
  3426. (unless splice
  3427. (push (if head "</thead>" "</tbody>") html)
  3428. (if lines (push "<tbody>" html) (setq tbopen nil)))
  3429. (setq head nil) ;; head ends here, first time around
  3430. ;; ignore this line
  3431. (throw 'next-line t)))
  3432. ;; Break the line into fields
  3433. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  3434. (unless fnum (setq fnum (make-vector (length fields) 0)))
  3435. (setq nlines (1+ nlines) i -1)
  3436. (push (concat "<tr>"
  3437. (mapconcat
  3438. (lambda (x)
  3439. (setq i (1+ i))
  3440. (if (and (< i nlines)
  3441. (string-match org-table-number-regexp x))
  3442. (incf (aref fnum i)))
  3443. (if head
  3444. (concat (car org-export-table-header-tags) x
  3445. (cdr org-export-table-header-tags))
  3446. (concat (car org-export-table-data-tags) x
  3447. (cdr org-export-table-data-tags))))
  3448. fields "")
  3449. "</tr>")
  3450. html)))
  3451. (unless splice (if tbopen (push "</tbody>" html)))
  3452. (unless splice (push "</table>\n" html))
  3453. (setq html (nreverse html))
  3454. (unless splice
  3455. ;; Put in col tags with the alignment (unfortuntely often ignored...)
  3456. (push (mapconcat
  3457. (lambda (x)
  3458. (setq gr (pop org-table-colgroup-info))
  3459. (format "%s<col align=\"%s\"></col>%s"
  3460. (if (memq gr '(:start :startend))
  3461. (prog1
  3462. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  3463. (setq colgropen t))
  3464. "")
  3465. (if (> (/ (float x) nlines) org-table-number-fraction)
  3466. "right" "left")
  3467. (if (memq gr '(:end :startend))
  3468. (progn (setq colgropen nil) "</colgroup>")
  3469. "")))
  3470. fnum "")
  3471. html)
  3472. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  3473. (push html-table-tag html))
  3474. (concat (mapconcat 'identity html "\n") "\n")))
  3475. (defun org-table-clean-before-export (lines)
  3476. "Check if the table has a marking column.
  3477. If yes remove the column and the special lines."
  3478. (setq org-table-colgroup-info nil)
  3479. (if (memq nil
  3480. (mapcar
  3481. (lambda (x) (or (string-match "^[ \t]*|-" x)
  3482. (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
  3483. lines))
  3484. (progn
  3485. (setq org-table-clean-did-remove-column nil)
  3486. (delq nil
  3487. (mapcar
  3488. (lambda (x)
  3489. (cond
  3490. ((string-match "^[ \t]*| */ *|" x)
  3491. (setq org-table-colgroup-info
  3492. (mapcar (lambda (x)
  3493. (cond ((member x '("<" "&lt;")) :start)
  3494. ((member x '(">" "&gt;")) :end)
  3495. ((member x '("<>" "&lt;&gt;")) :startend)
  3496. (t nil)))
  3497. (org-split-string x "[ \t]*|[ \t]*")))
  3498. nil)
  3499. (t x)))
  3500. lines)))
  3501. (setq org-table-clean-did-remove-column t)
  3502. (delq nil
  3503. (mapcar
  3504. (lambda (x)
  3505. (cond
  3506. ((string-match "^[ \t]*| */ *|" x)
  3507. (setq org-table-colgroup-info
  3508. (mapcar (lambda (x)
  3509. (cond ((member x '("<" "&lt;")) :start)
  3510. ((member x '(">" "&gt;")) :end)
  3511. ((member x '("<>" "&lt;&gt;")) :startend)
  3512. (t nil)))
  3513. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  3514. nil)
  3515. ((string-match "^[ \t]*| *[!_^/] *|" x)
  3516. nil) ; ignore this line
  3517. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  3518. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  3519. ;; remove the first column
  3520. (replace-match "\\1|" t nil x))))
  3521. lines))))
  3522. (defun org-format-table-table-html (lines)
  3523. "Format a table generated by table.el into HTML.
  3524. This conversion does *not* use `table-generate-source' from table.el.
  3525. This has the advantage that Org-mode's HTML conversions can be used.
  3526. But it has the disadvantage, that no cell- or row-spanning is allowed."
  3527. (let (line field-buffer
  3528. (head org-export-highlight-first-table-line)
  3529. fields html empty)
  3530. (setq html (concat html-table-tag "\n"))
  3531. (while (setq line (pop lines))
  3532. (setq empty "&nbsp;")
  3533. (catch 'next-line
  3534. (if (string-match "^[ \t]*\\+-" line)
  3535. (progn
  3536. (if field-buffer
  3537. (progn
  3538. (setq
  3539. html
  3540. (concat
  3541. html
  3542. "<tr>"
  3543. (mapconcat
  3544. (lambda (x)
  3545. (if (equal x "") (setq x empty))
  3546. (if head
  3547. (concat (car org-export-table-header-tags) x
  3548. (cdr org-export-table-header-tags))
  3549. (concat (car org-export-table-data-tags) x
  3550. (cdr org-export-table-data-tags))))
  3551. field-buffer "\n")
  3552. "</tr>\n"))
  3553. (setq head nil)
  3554. (setq field-buffer nil)))
  3555. ;; Ignore this line
  3556. (throw 'next-line t)))
  3557. ;; Break the line into fields and store the fields
  3558. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  3559. (if field-buffer
  3560. (setq field-buffer (mapcar
  3561. (lambda (x)
  3562. (concat x "<br/>" (pop fields)))
  3563. field-buffer))
  3564. (setq field-buffer fields))))
  3565. (setq html (concat html "</table>\n"))
  3566. html))
  3567. (defun org-format-table-table-html-using-table-generate-source (lines)
  3568. "Format a table into html, using `table-generate-source' from table.el.
  3569. This has the advantage that cell- or row-spanning is allowed.
  3570. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  3571. (require 'table)
  3572. (with-current-buffer (get-buffer-create " org-tmp1 ")
  3573. (erase-buffer)
  3574. (insert (mapconcat 'identity lines "\n"))
  3575. (goto-char (point-min))
  3576. (if (not (re-search-forward "|[^+]" nil t))
  3577. (error "Error processing table"))
  3578. (table-recognize-table)
  3579. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  3580. (table-generate-source 'html " org-tmp2 ")
  3581. (set-buffer " org-tmp2 ")
  3582. (buffer-substring (point-min) (point-max))))
  3583. (defun org-export-splice-style (style extra)
  3584. "Splice EXTRA into STYLE, just before \"</style>\"."
  3585. (if (and (stringp extra)
  3586. (string-match "\\S-" extra)
  3587. (string-match "</style>" style))
  3588. (concat (substring style 0 (match-beginning 0))
  3589. "\n" extra "\n"
  3590. (substring style (match-beginning 0)))
  3591. style))
  3592. (defun org-html-handle-time-stamps (s)
  3593. "Format time stamps in string S, or remove them."
  3594. (catch 'exit
  3595. (let (r b)
  3596. (while (string-match org-maybe-keyword-time-regexp s)
  3597. (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
  3598. ;; never export CLOCK
  3599. (throw 'exit ""))
  3600. (or b (setq b (substring s 0 (match-beginning 0))))
  3601. (if (not org-export-with-timestamps)
  3602. (setq r (concat r (substring s 0 (match-beginning 0)))
  3603. s (substring s (match-end 0)))
  3604. (setq r (concat
  3605. r (substring s 0 (match-beginning 0))
  3606. (if (match-end 1)
  3607. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  3608. (match-string 1 s)))
  3609. (format " @<span class=\"timestamp\">%s@</span>"
  3610. (substring
  3611. (org-translate-time (match-string 3 s)) 1 -1)))
  3612. s (substring s (match-end 0)))))
  3613. ;; Line break if line started and ended with time stamp stuff
  3614. (if (not r)
  3615. s
  3616. (setq r (concat r s))
  3617. (unless (string-match "\\S-" (concat b s))
  3618. (setq r (concat r "@<br/>")))
  3619. r))))
  3620. (defun org-export-htmlize-region-for-paste (beg end)
  3621. "Convert the region to HTML, using htmlize.el.
  3622. This is much like `htmlize-region-for-paste', only that it uses
  3623. the settings define in the org-... variables."
  3624. (let* ((htmlize-output-type org-export-htmlize-output-type)
  3625. (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
  3626. (htmlbuf (htmlize-region beg end)))
  3627. (unwind-protect
  3628. (with-current-buffer htmlbuf
  3629. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  3630. (plist-get htmlize-buffer-places 'content-end)))
  3631. (kill-buffer htmlbuf))))
  3632. ;;;###autoload
  3633. (defun org-export-htmlize-generate-css ()
  3634. "Create the CSS for all font definitions in the current Emacs session.
  3635. Use this to create face definitions in your CSS style file that can then
  3636. be used by code snippets transformed by htmlize.
  3637. This command just produces a buffer that contains class definitions for all
  3638. faces used in the current Emacs session. You can copy and paste the ones you
  3639. need into your CSS file.
  3640. If you then set `org-export-htmlize-output-type' to `css', calls to
  3641. the function `org-export-htmlize-region-for-paste' will produce code
  3642. that uses these same face definitions."
  3643. (interactive)
  3644. (require 'htmlize)
  3645. (and (get-buffer "*html*") (kill-buffer "*html*"))
  3646. (with-temp-buffer
  3647. (let ((fl (face-list))
  3648. (htmlize-css-name-prefix "org-")
  3649. (htmlize-output-type 'css)
  3650. f i)
  3651. (while (setq f (pop fl)
  3652. i (and f (face-attribute f :inherit)))
  3653. (when (and (symbolp f) (or (not i) (not (listp i))))
  3654. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  3655. (htmlize-region (point-min) (point-max))))
  3656. (switch-to-buffer "*html*")
  3657. (goto-char (point-min))
  3658. (if (re-search-forward "<style" nil t)
  3659. (delete-region (point-min) (match-beginning 0)))
  3660. (if (re-search-forward "</style>" nil t)
  3661. (delete-region (1+ (match-end 0)) (point-max)))
  3662. (beginning-of-line 1)
  3663. (if (looking-at " +") (replace-match ""))
  3664. (goto-char (point-min)))
  3665. (defun org-html-protect (s)
  3666. ;; convert & to &amp;, < to &lt; and > to &gt;
  3667. (let ((start 0))
  3668. (while (string-match "&" s start)
  3669. (setq s (replace-match "&amp;" t t s)
  3670. start (1+ (match-beginning 0))))
  3671. (while (string-match "<" s)
  3672. (setq s (replace-match "&lt;" t t s)))
  3673. (while (string-match ">" s)
  3674. (setq s (replace-match "&gt;" t t s)))
  3675. ; (while (string-match "\"" s)
  3676. ; (setq s (replace-match "&quot;" t t s)))
  3677. )
  3678. s)
  3679. (defun org-export-cleanup-toc-line (s)
  3680. "Remove tags and time staps from lines going into the toc."
  3681. (when (memq org-export-with-tags '(not-in-toc nil))
  3682. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  3683. (setq s (replace-match "" t t s))))
  3684. (when org-export-remove-timestamps-from-toc
  3685. (while (string-match org-maybe-keyword-time-regexp s)
  3686. (setq s (replace-match "" t t s))))
  3687. (while (string-match org-bracket-link-regexp s)
  3688. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  3689. t t s)))
  3690. s)
  3691. (defun org-html-expand (string)
  3692. "Prepare STRING for HTML export. Applies all active conversions.
  3693. If there are links in the string, don't modify these."
  3694. (let* ((re (concat org-bracket-link-regexp "\\|"
  3695. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  3696. m s l res)
  3697. (while (setq m (string-match re string))
  3698. (setq s (substring string 0 m)
  3699. l (match-string 0 string)
  3700. string (substring string (match-end 0)))
  3701. (push (org-html-do-expand s) res)
  3702. (push l res))
  3703. (push (org-html-do-expand string) res)
  3704. (apply 'concat (nreverse res))))
  3705. (defun org-html-do-expand (s)
  3706. "Apply all active conversions to translate special ASCII to HTML."
  3707. (setq s (org-html-protect s))
  3708. (if org-export-html-expand
  3709. (let ((start 0))
  3710. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  3711. (setq s (replace-match "<\\1>" t nil s)))))
  3712. (if org-export-with-emphasize
  3713. (setq s (org-export-html-convert-emphasize s)))
  3714. (if org-export-with-special-strings
  3715. (setq s (org-export-html-convert-special-strings s)))
  3716. (if org-export-with-sub-superscripts
  3717. (setq s (org-export-html-convert-sub-super s)))
  3718. (if org-export-with-TeX-macros
  3719. (let ((start 0) wd ass)
  3720. (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
  3721. s start))
  3722. (if (get-text-property (match-beginning 0) 'org-protected s)
  3723. (setq start (match-end 0))
  3724. (setq wd (match-string 1 s))
  3725. (if (setq ass (assoc wd org-html-entities))
  3726. (setq s (replace-match (or (cdr ass)
  3727. (concat "&" (car ass) ";"))
  3728. t t s))
  3729. (setq start (+ start (length wd))))))))
  3730. s)
  3731. (defun org-create-multibrace-regexp (left right n)
  3732. "Create a regular expression which will match a balanced sexp.
  3733. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  3734. as single character strings.
  3735. The regexp returned will match the entire expression including the
  3736. delimiters. It will also define a single group which contains the
  3737. match except for the outermost delimiters. The maximum depth of
  3738. stacked delimiters is N. Escaping delimiters is not possible."
  3739. (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
  3740. (or "\\|")
  3741. (re nothing)
  3742. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  3743. (while (> n 1)
  3744. (setq n (1- n)
  3745. re (concat re or next)
  3746. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  3747. (concat left "\\(" re "\\)" right)))
  3748. (defvar org-match-substring-regexp
  3749. (concat
  3750. "\\([^\\]\\)\\([_^]\\)\\("
  3751. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  3752. "\\|"
  3753. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  3754. "\\|"
  3755. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  3756. "The regular expression matching a sub- or superscript.")
  3757. (defvar org-match-substring-with-braces-regexp
  3758. (concat
  3759. "\\([^\\]\\)\\([_^]\\)\\("
  3760. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  3761. "\\)")
  3762. "The regular expression matching a sub- or superscript, forcing braces.")
  3763. (defconst org-export-html-special-string-regexps
  3764. '(("\\\\-" . "&shy;")
  3765. ("---\\([^-]\\)" . "&mdash;\\1")
  3766. ("--\\([^-]\\)" . "&ndash;\\1")
  3767. ("\\.\\.\\." . "&hellip;"))
  3768. "Regular expressions for special string conversion.")
  3769. (defun org-export-html-convert-special-strings (string)
  3770. "Convert special characters in STRING to HTML."
  3771. (let ((all org-export-html-special-string-regexps)
  3772. e a re rpl start)
  3773. (while (setq a (pop all))
  3774. (setq re (car a) rpl (cdr a) start 0)
  3775. (while (string-match re string start)
  3776. (if (get-text-property (match-beginning 0) 'org-protected string)
  3777. (setq start (match-end 0))
  3778. (setq string (replace-match rpl t nil string)))))
  3779. string))
  3780. (defun org-export-html-convert-sub-super (string)
  3781. "Convert sub- and superscripts in STRING to HTML."
  3782. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  3783. (while (string-match org-match-substring-regexp string s)
  3784. (cond
  3785. ((and requireb (match-end 8)) (setq s (match-end 2)))
  3786. ((get-text-property (match-beginning 2) 'org-protected string)
  3787. (setq s (match-end 2)))
  3788. (t
  3789. (setq s (match-end 1)
  3790. key (if (string= (match-string 2 string) "_") "sub" "sup")
  3791. c (or (match-string 8 string)
  3792. (match-string 6 string)
  3793. (match-string 5 string))
  3794. string (replace-match
  3795. (concat (match-string 1 string)
  3796. "<" key ">" c "</" key ">")
  3797. t t string)))))
  3798. (while (string-match "\\\\\\([_^]\\)" string)
  3799. (setq string (replace-match (match-string 1 string) t t string)))
  3800. string))
  3801. (defun org-export-html-convert-emphasize (string)
  3802. "Apply emphasis."
  3803. (let ((s 0) rpl)
  3804. (while (string-match org-emph-re string s)
  3805. (if (not (equal
  3806. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  3807. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  3808. (setq s (match-beginning 0)
  3809. rpl
  3810. (concat
  3811. (match-string 1 string)
  3812. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  3813. (match-string 4 string)
  3814. (nth 3 (assoc (match-string 3 string)
  3815. org-emphasis-alist))
  3816. (match-string 5 string))
  3817. string (replace-match rpl t t string)
  3818. s (+ s (- (length rpl) 2)))
  3819. (setq s (1+ s))))
  3820. string))
  3821. (defun org-open-par ()
  3822. "Insert <p>, but first close previous paragraph if any."
  3823. (org-close-par-maybe)
  3824. (insert "\n<p>")
  3825. (setq org-par-open t))
  3826. (defun org-close-par-maybe ()
  3827. "Close paragraph if there is one open."
  3828. (when org-par-open
  3829. (insert "</p>")
  3830. (setq org-par-open nil)))
  3831. (defun org-close-li (&optional type)
  3832. "Close <li> if necessary."
  3833. (org-close-par-maybe)
  3834. (insert (if (equal type "d") "</dd>\n" "</li>\n")))
  3835. (defvar body-only) ; dynamically scoped into this.
  3836. (defun org-html-level-start (level title umax with-toc head-count)
  3837. "Insert a new level in HTML export.
  3838. When TITLE is nil, just close all open levels."
  3839. (org-close-par-maybe)
  3840. (let* ((target (and title (org-get-text-property-any 0 'target title)))
  3841. (extra-targets
  3842. (mapconcat (lambda (x)
  3843. (format "<a name=\"%s\" id=\"%s\"></a>"
  3844. x x))
  3845. (cdr (assoc target org-export-target-aliases))
  3846. ""))
  3847. (l org-level-max)
  3848. snumber)
  3849. (while (>= l level)
  3850. (if (aref org-levels-open (1- l))
  3851. (progn
  3852. (org-html-level-close l umax)
  3853. (aset org-levels-open (1- l) nil)))
  3854. (setq l (1- l)))
  3855. (when title
  3856. ;; If title is nil, this means this function is called to close
  3857. ;; all levels, so the rest is done only if title is given
  3858. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  3859. (setq title (replace-match
  3860. (if org-export-with-tags
  3861. (save-match-data
  3862. (concat
  3863. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  3864. (mapconcat 'identity (org-split-string
  3865. (match-string 1 title) ":")
  3866. "&nbsp;")
  3867. "</span>"))
  3868. "")
  3869. t t title)))
  3870. (if (> level umax)
  3871. (progn
  3872. (if (aref org-levels-open (1- level))
  3873. (progn
  3874. (org-close-li)
  3875. (if target
  3876. (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
  3877. (insert "<li>" title "<br/>\n")))
  3878. (aset org-levels-open (1- level) t)
  3879. (org-close-par-maybe)
  3880. (if target
  3881. (insert (format "<ul>\n<li id=\"%s\">" target)
  3882. extra-targets title "<br/>\n")
  3883. (insert "<ul>\n<li>" title "<br/>\n"))))
  3884. (aset org-levels-open (1- level) t)
  3885. (setq snumber (org-section-number level))
  3886. (if (and org-export-with-section-numbers (not body-only))
  3887. (setq title (concat snumber " " title)))
  3888. (setq level (+ level org-export-html-toplevel-hlevel -1))
  3889. (unless (= head-count 1) (insert "\n</div>\n"))
  3890. (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"
  3891. snumber level level snumber extra-targets title level snumber))
  3892. (org-open-par)))))
  3893. (defun org-get-text-property-any (pos prop &optional object)
  3894. (or (get-text-property pos prop object)
  3895. (and (setq pos (next-single-property-change pos prop object))
  3896. (get-text-property pos prop object))))
  3897. (defun org-html-level-close (level max-outline-level)
  3898. "Terminate one level in HTML export."
  3899. (if (<= level max-outline-level)
  3900. (insert "</div>\n")
  3901. (org-close-li)
  3902. (insert "</ul>\n")))
  3903. ;;; iCalendar export
  3904. ;;;###autoload
  3905. (defun org-export-icalendar-this-file ()
  3906. "Export current file as an iCalendar file.
  3907. The iCalendar file will be located in the same directory as the Org-mode
  3908. file, but with extension `.ics'."
  3909. (interactive)
  3910. (org-export-icalendar nil buffer-file-name))
  3911. ;;;###autoload
  3912. (defun org-export-icalendar-all-agenda-files ()
  3913. "Export all files in `org-agenda-files' to iCalendar .ics files.
  3914. Each iCalendar file will be located in the same directory as the Org-mode
  3915. file, but with extension `.ics'."
  3916. (interactive)
  3917. (apply 'org-export-icalendar nil (org-agenda-files t)))
  3918. ;;;###autoload
  3919. (defun org-export-icalendar-combine-agenda-files ()
  3920. "Export all files in `org-agenda-files' to a single combined iCalendar file.
  3921. The file is stored under the name `org-combined-agenda-icalendar-file'."
  3922. (interactive)
  3923. (apply 'org-export-icalendar t (org-agenda-files t)))
  3924. (defun org-export-icalendar (combine &rest files)
  3925. "Create iCalendar files for all elements of FILES.
  3926. If COMBINE is non-nil, combine all calendar entries into a single large
  3927. file and store it under the name `org-combined-agenda-icalendar-file'."
  3928. (save-excursion
  3929. (org-prepare-agenda-buffers files)
  3930. (let* ((dir (org-export-directory
  3931. :ical (list :publishing-directory
  3932. org-export-publishing-directory)))
  3933. file ical-file ical-buffer category started org-agenda-new-buffers)
  3934. (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
  3935. (when combine
  3936. (setq ical-file
  3937. (if (file-name-absolute-p org-combined-agenda-icalendar-file)
  3938. org-combined-agenda-icalendar-file
  3939. (expand-file-name org-combined-agenda-icalendar-file dir))
  3940. ical-buffer (org-get-agenda-file-buffer ical-file))
  3941. (set-buffer ical-buffer) (erase-buffer))
  3942. (while (setq file (pop files))
  3943. (catch 'nextfile
  3944. (org-check-agenda-file file)
  3945. (set-buffer (org-get-agenda-file-buffer file))
  3946. (unless combine
  3947. (setq ical-file (concat (file-name-as-directory dir)
  3948. (file-name-sans-extension
  3949. (file-name-nondirectory buffer-file-name))
  3950. ".ics"))
  3951. (setq ical-buffer (org-get-agenda-file-buffer ical-file))
  3952. (with-current-buffer ical-buffer (erase-buffer)))
  3953. (setq category (or org-category
  3954. (file-name-sans-extension
  3955. (file-name-nondirectory buffer-file-name))))
  3956. (if (symbolp category) (setq category (symbol-name category)))
  3957. (let ((standard-output ical-buffer))
  3958. (if combine
  3959. (and (not started) (setq started t)
  3960. (org-start-icalendar-file org-icalendar-combined-name))
  3961. (org-start-icalendar-file category))
  3962. (org-print-icalendar-entries combine)
  3963. (when (or (and combine (not files)) (not combine))
  3964. (org-finish-icalendar-file)
  3965. (set-buffer ical-buffer)
  3966. (run-hooks 'org-before-save-iCalendar-file-hook)
  3967. (save-buffer)
  3968. (run-hooks 'org-after-save-iCalendar-file-hook)
  3969. (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
  3970. ))))
  3971. (org-release-buffers org-agenda-new-buffers))))
  3972. (defvar org-before-save-iCalendar-file-hook nil
  3973. "Hook run before an iCalendar file has been saved.
  3974. This can be used to modify the result of the export.")
  3975. (defvar org-after-save-iCalendar-file-hook nil
  3976. "Hook run after an iCalendar file has been saved.
  3977. The iCalendar buffer is still current when this hook is run.
  3978. A good way to use this is to tell a desktop calenndar application to re-read
  3979. the iCalendar file.")
  3980. (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
  3981. (defun org-print-icalendar-entries (&optional combine)
  3982. "Print iCalendar entries for the current Org-mode file to `standard-output'.
  3983. When COMBINE is non nil, add the category to each line."
  3984. (require 'org-agenda)
  3985. (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
  3986. (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
  3987. (dts (org-ical-ts-to-string
  3988. (format-time-string (cdr org-time-stamp-formats) (current-time))
  3989. "DTSTART"))
  3990. hd ts ts2 state status (inc t) pos b sexp rrule
  3991. scheduledp deadlinep todo prefix due start
  3992. tmp pri categories entry location summary desc uid
  3993. (sexp-buffer (get-buffer-create "*ical-tmp*")))
  3994. (org-refresh-category-properties)
  3995. (save-excursion
  3996. (goto-char (point-min))
  3997. (while (re-search-forward re1 nil t)
  3998. (catch :skip
  3999. (org-agenda-skip)
  4000. (when (boundp 'org-icalendar-verify-function)
  4001. (unless (funcall org-icalendar-verify-function)
  4002. (outline-next-heading)
  4003. (backward-char 1)
  4004. (throw :skip nil)))
  4005. (setq pos (match-beginning 0)
  4006. ts (match-string 0)
  4007. inc t
  4008. hd (condition-case nil
  4009. (org-icalendar-cleanup-string
  4010. (org-get-heading))
  4011. (error (throw :skip nil)))
  4012. summary (org-icalendar-cleanup-string
  4013. (org-entry-get nil "SUMMARY"))
  4014. desc (org-icalendar-cleanup-string
  4015. (or (org-entry-get nil "DESCRIPTION")
  4016. (and org-icalendar-include-body (org-get-entry)))
  4017. t org-icalendar-include-body)
  4018. location (org-icalendar-cleanup-string
  4019. (org-entry-get nil "LOCATION"))
  4020. uid (if org-icalendar-store-UID
  4021. (org-id-get-create)
  4022. (or (org-id-get) (org-id-new)))
  4023. categories (org-export-get-categories)
  4024. deadlinep nil scheduledp nil)
  4025. (if (looking-at re2)
  4026. (progn
  4027. (goto-char (match-end 0))
  4028. (setq ts2 (match-string 1)
  4029. inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
  4030. (setq tmp (buffer-substring (max (point-min)
  4031. (- pos org-ds-keyword-length))
  4032. pos)
  4033. ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
  4034. (progn
  4035. (setq inc nil)
  4036. (replace-match "\\1" t nil ts))
  4037. ts)
  4038. deadlinep (string-match org-deadline-regexp tmp)
  4039. scheduledp (string-match org-scheduled-regexp tmp)
  4040. todo (org-get-todo-state)
  4041. ;; donep (org-entry-is-done-p)
  4042. ))
  4043. (when (and
  4044. deadlinep
  4045. (if todo
  4046. (not (memq 'event-if-todo org-icalendar-use-deadline))
  4047. (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
  4048. (throw :skip t))
  4049. (when (and
  4050. scheduledp
  4051. (if todo
  4052. (not (memq 'event-if-todo org-icalendar-use-scheduled))
  4053. (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
  4054. (throw :skip t))
  4055. (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
  4056. (if (or (string-match org-tr-regexp hd)
  4057. (string-match org-ts-regexp hd))
  4058. (setq hd (replace-match "" t t hd)))
  4059. (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
  4060. (setq rrule
  4061. (concat "\nRRULE:FREQ="
  4062. (cdr (assoc
  4063. (match-string 2 ts)
  4064. '(("d" . "DAILY")("w" . "WEEKLY")
  4065. ("m" . "MONTHLY")("y" . "YEARLY"))))
  4066. ";INTERVAL=" (match-string 1 ts)))
  4067. (setq rrule ""))
  4068. (setq summary (or summary hd))
  4069. (if (string-match org-bracket-link-regexp summary)
  4070. (setq summary
  4071. (replace-match (if (match-end 3)
  4072. (match-string 3 summary)
  4073. (match-string 1 summary))
  4074. t t summary)))
  4075. (if deadlinep (setq summary (concat "DL: " summary)))
  4076. (if scheduledp (setq summary (concat "S: " summary)))
  4077. (if (string-match "\\`<%%" ts)
  4078. (with-current-buffer sexp-buffer
  4079. (insert (substring ts 1 -1) " " summary "\n"))
  4080. (princ (format "BEGIN:VEVENT
  4081. UID: %s
  4082. %s
  4083. %s%s
  4084. SUMMARY:%s%s%s
  4085. CATEGORIES:%s
  4086. END:VEVENT\n"
  4087. (concat prefix uid)
  4088. (org-ical-ts-to-string ts "DTSTART")
  4089. (org-ical-ts-to-string ts2 "DTEND" inc)
  4090. rrule summary
  4091. (if (and desc (string-match "\\S-" desc))
  4092. (concat "\nDESCRIPTION: " desc) "")
  4093. (if (and location (string-match "\\S-" location))
  4094. (concat "\nLOCATION: " location) "")
  4095. categories)))))
  4096. (when (and org-icalendar-include-sexps
  4097. (condition-case nil (require 'icalendar) (error nil))
  4098. (fboundp 'icalendar-export-region))
  4099. ;; Get all the literal sexps
  4100. (goto-char (point-min))
  4101. (while (re-search-forward "^&?%%(" nil t)
  4102. (catch :skip
  4103. (org-agenda-skip)
  4104. (setq b (match-beginning 0))
  4105. (goto-char (1- (match-end 0)))
  4106. (forward-sexp 1)
  4107. (end-of-line 1)
  4108. (setq sexp (buffer-substring b (point)))
  4109. (with-current-buffer sexp-buffer
  4110. (insert sexp "\n"))))
  4111. (princ (org-diary-to-ical-string sexp-buffer))
  4112. (kill-buffer sexp-buffer))
  4113. (when org-icalendar-include-todo
  4114. (setq prefix "TODO-")
  4115. (goto-char (point-min))
  4116. (while (re-search-forward org-todo-line-regexp nil t)
  4117. (catch :skip
  4118. (org-agenda-skip)
  4119. (when (boundp 'org-icalendar-verify-function)
  4120. (unless (funcall org-icalendar-verify-function)
  4121. (outline-next-heading)
  4122. (backward-char 1)
  4123. (throw :skip nil)))
  4124. (setq state (match-string 2))
  4125. (setq status (if (member state org-done-keywords)
  4126. "COMPLETED" "NEEDS-ACTION"))
  4127. (when (and state
  4128. (or (not (member state org-done-keywords))
  4129. (eq org-icalendar-include-todo 'all))
  4130. (not (member org-archive-tag (org-get-tags-at)))
  4131. )
  4132. (setq hd (match-string 3)
  4133. summary (org-icalendar-cleanup-string
  4134. (org-entry-get nil "SUMMARY"))
  4135. desc (org-icalendar-cleanup-string
  4136. (or (org-entry-get nil "DESCRIPTION")
  4137. (and org-icalendar-include-body (org-get-entry)))
  4138. t org-icalendar-include-body)
  4139. location (org-icalendar-cleanup-string
  4140. (org-entry-get nil "LOCATION"))
  4141. due (and (member 'todo-due org-icalendar-use-deadline)
  4142. (org-entry-get nil "DEADLINE"))
  4143. start (and (member 'todo-start org-icalendar-use-scheduled)
  4144. (org-entry-get nil "SCHEDULED"))
  4145. categories (org-export-get-categories)
  4146. uid (if org-icalendar-store-UID
  4147. (org-id-get-create)
  4148. (or (org-id-get) (org-id-new))))
  4149. (and due (setq due (org-ical-ts-to-string due "DUE")))
  4150. (and start (setq start (org-ical-ts-to-string start "DTSTART")))
  4151. (if (string-match org-bracket-link-regexp hd)
  4152. (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
  4153. (match-string 1 hd))
  4154. t t hd)))
  4155. (if (string-match org-priority-regexp hd)
  4156. (setq pri (string-to-char (match-string 2 hd))
  4157. hd (concat (substring hd 0 (match-beginning 1))
  4158. (substring hd (match-end 1))))
  4159. (setq pri org-default-priority))
  4160. (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
  4161. (- org-lowest-priority org-highest-priority))))))
  4162. (princ (format "BEGIN:VTODO
  4163. UID: %s
  4164. %s
  4165. SUMMARY:%s%s%s%s
  4166. CATEGORIES:%s
  4167. SEQUENCE:1
  4168. PRIORITY:%d
  4169. STATUS:%s
  4170. END:VTODO\n"
  4171. (concat prefix uid)
  4172. (or start dts)
  4173. (or summary hd)
  4174. (if (and location (string-match "\\S-" location))
  4175. (concat "\nLOCATION: " location) "")
  4176. (if (and desc (string-match "\\S-" desc))
  4177. (concat "\nDESCRIPTION: " desc) "")
  4178. (if due (concat "\n" due) "")
  4179. categories
  4180. pri status)))))))))
  4181. (defun org-export-get-categories ()
  4182. "Get categories according to `org-icalendar-categories'."
  4183. (let ((cs org-icalendar-categories) c rtn tmp)
  4184. (while (setq c (pop cs))
  4185. (cond
  4186. ((eq c 'category) (push (org-get-category) rtn))
  4187. ((eq c 'todo-state)
  4188. (setq tmp (org-get-todo-state))
  4189. (and tmp (push tmp rtn)))
  4190. ((eq c 'local-tags)
  4191. (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
  4192. ((eq c 'all-tags)
  4193. (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
  4194. (mapconcat 'identity (nreverse rtn) ",")))
  4195. (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
  4196. "Take out stuff and quote what needs to be quoted.
  4197. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  4198. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  4199. characters."
  4200. (if (not s)
  4201. nil
  4202. (when is-body
  4203. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  4204. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  4205. (while (string-match re s) (setq s (replace-match "" t t s)))
  4206. (while (string-match re2 s) (setq s (replace-match "" t t s)))))
  4207. (let ((start 0))
  4208. (while (string-match "\\([,;]\\)" s start)
  4209. (setq start (+ (match-beginning 0) 2)
  4210. s (replace-match "\\\\\\1" nil nil s))))
  4211. (setq s (org-trim s))
  4212. (when is-body
  4213. (while (string-match "[ \t]*\n[ \t]*" s)
  4214. (setq s (replace-match "\\n" t t s))))
  4215. (if is-body
  4216. (if maxlength
  4217. (if (and (numberp maxlength)
  4218. (> (length s) maxlength))
  4219. (setq s (substring s 0 maxlength)))))
  4220. s))
  4221. (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
  4222. "Take out stuff and quote what needs to be quoted.
  4223. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  4224. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  4225. characters.
  4226. This seems to be more like RFC 2455, but it causes problems, so it is
  4227. not used right now."
  4228. (if (not s)
  4229. nil
  4230. (if is-body
  4231. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  4232. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  4233. (while (string-match re s) (setq s (replace-match "" t t s)))
  4234. (while (string-match re2 s) (setq s (replace-match "" t t s)))
  4235. (setq s (org-trim s))
  4236. (while (string-match "[ \t]*\n[ \t]*" s)
  4237. (setq s (replace-match "\\n" t t s)))
  4238. (if maxlength
  4239. (if (and (numberp maxlength)
  4240. (> (length s) maxlength))
  4241. (setq s (substring s 0 maxlength)))))
  4242. (setq s (org-trim s)))
  4243. (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
  4244. (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
  4245. s))
  4246. (defun org-get-entry ()
  4247. "Clean-up description string."
  4248. (save-excursion
  4249. (org-back-to-heading t)
  4250. (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
  4251. (defun org-start-icalendar-file (name)
  4252. "Start an iCalendar file by inserting the header."
  4253. (let ((user user-full-name)
  4254. (name (or name "unknown"))
  4255. (timezone (cadr (current-time-zone))))
  4256. (princ
  4257. (format "BEGIN:VCALENDAR
  4258. VERSION:2.0
  4259. X-WR-CALNAME:%s
  4260. PRODID:-//%s//Emacs with Org-mode//EN
  4261. X-WR-TIMEZONE:%s
  4262. CALSCALE:GREGORIAN\n" name user timezone))))
  4263. (defun org-finish-icalendar-file ()
  4264. "Finish an iCalendar file by inserting the END statement."
  4265. (princ "END:VCALENDAR\n"))
  4266. (defun org-ical-ts-to-string (s keyword &optional inc)
  4267. "Take a time string S and convert it to iCalendar format.
  4268. KEYWORD is added in front, to make a complete line like DTSTART....
  4269. When INC is non-nil, increase the hour by two (if time string contains
  4270. a time), or the day by one (if it does not contain a time)."
  4271. (let ((t1 (org-parse-time-string s 'nodefault))
  4272. t2 fmt have-time time)
  4273. (if (and (car t1) (nth 1 t1) (nth 2 t1))
  4274. (setq t2 t1 have-time t)
  4275. (setq t2 (org-parse-time-string s)))
  4276. (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
  4277. (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
  4278. (when inc
  4279. (if have-time
  4280. (if org-agenda-default-appointment-duration
  4281. (setq mi (+ org-agenda-default-appointment-duration mi))
  4282. (setq h (+ 2 h)))
  4283. (setq d (1+ d))))
  4284. (setq time (encode-time s mi h d m y)))
  4285. (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
  4286. (concat keyword (format-time-string fmt time))))
  4287. ;;; XOXO export
  4288. (defun org-export-as-xoxo-insert-into (buffer &rest output)
  4289. (with-current-buffer buffer
  4290. (apply 'insert output)))
  4291. (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
  4292. ;;;###autoload
  4293. (defun org-export-as-xoxo (&optional buffer)
  4294. "Export the org buffer as XOXO.
  4295. The XOXO buffer is named *xoxo-<source buffer name>*"
  4296. (interactive (list (current-buffer)))
  4297. ;; A quickie abstraction
  4298. ;; Output everything as XOXO
  4299. (with-current-buffer (get-buffer buffer)
  4300. (let* ((pos (point))
  4301. (opt-plist (org-combine-plists (org-default-export-plist)
  4302. (org-infile-export-plist)))
  4303. (filename (concat (file-name-as-directory
  4304. (org-export-directory :xoxo opt-plist))
  4305. (file-name-sans-extension
  4306. (file-name-nondirectory buffer-file-name))
  4307. ".html"))
  4308. (out (find-file-noselect filename))
  4309. (last-level 1)
  4310. (hanging-li nil))
  4311. (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
  4312. ;; Check the output buffer is empty.
  4313. (with-current-buffer out (erase-buffer))
  4314. ;; Kick off the output
  4315. (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
  4316. (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
  4317. (let* ((hd (match-string-no-properties 1))
  4318. (level (length hd))
  4319. (text (concat
  4320. (match-string-no-properties 2)
  4321. (save-excursion
  4322. (goto-char (match-end 0))
  4323. (let ((str ""))
  4324. (catch 'loop
  4325. (while 't
  4326. (forward-line)
  4327. (if (looking-at "^[ \t]\\(.*\\)")
  4328. (setq str (concat str (match-string-no-properties 1)))
  4329. (throw 'loop str)))))))))
  4330. ;; Handle level rendering
  4331. (cond
  4332. ((> level last-level)
  4333. (org-export-as-xoxo-insert-into out "\n<ol>\n"))
  4334. ((< level last-level)
  4335. (dotimes (- (- last-level level) 1)
  4336. (if hanging-li
  4337. (org-export-as-xoxo-insert-into out "</li>\n"))
  4338. (org-export-as-xoxo-insert-into out "</ol>\n"))
  4339. (when hanging-li
  4340. (org-export-as-xoxo-insert-into out "</li>\n")
  4341. (setq hanging-li nil)))
  4342. ((equal level last-level)
  4343. (if hanging-li
  4344. (org-export-as-xoxo-insert-into out "</li>\n")))
  4345. )
  4346. (setq last-level level)
  4347. ;; And output the new li
  4348. (setq hanging-li 't)
  4349. (if (equal ?+ (elt text 0))
  4350. (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
  4351. (org-export-as-xoxo-insert-into out "<li>" text))))
  4352. ;; Finally finish off the ol
  4353. (dotimes (- last-level 1)
  4354. (if hanging-li
  4355. (org-export-as-xoxo-insert-into out "</li>\n"))
  4356. (org-export-as-xoxo-insert-into out "</ol>\n"))
  4357. (goto-char pos)
  4358. ;; Finish the buffer off and clean it up.
  4359. (switch-to-buffer-other-window out)
  4360. (indent-region (point-min) (point-max) nil)
  4361. (save-buffer)
  4362. (goto-char (point-min))
  4363. )))
  4364. (provide 'org-exp)
  4365. ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
  4366. ;;; org-exp.el ends here