org-exp.el 159 KB

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