org-exp.el 175 KB

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