org-exp.el 158 KB

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