org-exp.el 153 KB

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