org-exp.el 133 KB

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