org-exp.el 124 KB

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