org-exp.el 123 KB

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