org-exp.el 160 KB

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