org-exp.el 162 KB

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