org-exp.el 139 KB

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