org-exp.el 138 KB

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