org-exp.el 129 KB

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