org-exp.el 171 KB

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