org-exp.el 149 KB

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