org-exp.el 159 KB

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