org-exp.el 175 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059
  1. ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 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.17trans
  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. ;; Remove timestamps, if the user has requested so
  1382. (org-export-remove-clock-lines)
  1383. (unless (plist-get parameters :timestamps)
  1384. (org-export-remove-timestamps))
  1385. ;; Find targets in comments and move them out of comments,
  1386. ;; but mark them as targets that should be invisible
  1387. (setq target-alist (org-export-handle-invisible-targets target-alist))
  1388. ;; Protect short examples
  1389. (org-export-protect-colon-examples)
  1390. ;; Protect backend specific stuff, throw away the others.
  1391. (org-export-select-backend-specific-text backend)
  1392. ;; Protect quoted subtrees
  1393. (org-export-protect-quoted-subtrees)
  1394. ;; Protect verbatim elements
  1395. (org-export-protect-verbatim)
  1396. ;; Blockquotes and verse
  1397. (org-export-mark-blockquote-and-verse)
  1398. ;; Attach captions to the correct object
  1399. (setq target-alist (org-export-attach-captions-and-attributes
  1400. backend target-alist))
  1401. ;; Find matches for radio targets and turn them into internal links
  1402. (org-export-mark-radio-links)
  1403. ;; Find all links that contain a newline and put them into a single line
  1404. (org-export-concatenate-multiline-links)
  1405. ;; Normalize links: Convert angle and plain links into bracket links
  1406. ;; and expand link abbreviations
  1407. (org-export-normalize-links)
  1408. ;; Find all internal links. If they have a fuzzy match (i.e. not
  1409. ;; a *dedicated* target match, let the link point to the
  1410. ;; corresponding section.
  1411. (org-export-target-internal-links target-alist)
  1412. ;; Find multiline emphasis and put them into single line
  1413. (when (plist-get parameters :emph-multiline)
  1414. (org-export-concatenate-multiline-emphasis))
  1415. ;; Remove special table lines
  1416. (when org-export-table-remove-special-lines
  1417. (org-export-remove-special-table-lines))
  1418. ;; Another hook
  1419. (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
  1420. ;; Specific LaTeX stuff
  1421. (when latexp
  1422. (require 'org-export-latex nil)
  1423. (org-export-latex-preprocess))
  1424. ;; Specific ASCII stuff
  1425. (when asciip
  1426. (org-export-ascii-preprocess))
  1427. ;; Specific HTML stuff
  1428. (when htmlp
  1429. (org-export-html-preprocess parameters))
  1430. ;; Remove or replace comments
  1431. (org-export-handle-comments (plist-get parameters :comments))
  1432. ;; Run the final hook
  1433. (run-hooks 'org-export-preprocess-final-hook)
  1434. (setq rtn (buffer-string)))
  1435. (kill-buffer " org-mode-tmp")
  1436. rtn))
  1437. (defun org-export-kill-licensed-text ()
  1438. "Remove all text that is marked with a :org-license-to-kill property."
  1439. (let (p q)
  1440. (while (setq p (text-property-any (point-min) (point-max)
  1441. :org-license-to-kill t))
  1442. (delete-region
  1443. p (or (next-single-property-change p :org-license-to-kill)
  1444. (point-max))))))
  1445. (defun org-export-define-heading-targets (target-alist)
  1446. "Find all headings and define the targets for them.
  1447. The new targets are added to TARGET-ALIST, which is also returned."
  1448. (goto-char (point-min))
  1449. (org-init-section-numbers)
  1450. (let ((re (concat "^" org-outline-regexp
  1451. "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
  1452. level target)
  1453. (while (re-search-forward re nil t)
  1454. (if (match-end 1)
  1455. (push (cons (org-match-string-no-properties 1)
  1456. target) target-alist)
  1457. (setq level (org-reduced-level
  1458. (save-excursion (goto-char (point-at-bol))
  1459. (org-outline-level))))
  1460. (setq target (org-solidify-link-text
  1461. (format "sec-%s" (org-section-number level))))
  1462. (push (cons target target) target-alist)
  1463. (add-text-properties
  1464. (point-at-bol) (point-at-eol)
  1465. (list 'target target)))))
  1466. target-alist)
  1467. (defun org-export-handle-invisible-targets (target-alist)
  1468. "Find targets in comments and move them out of comments.
  1469. Mark them as invisible targets."
  1470. (let (target tmp a)
  1471. (goto-char (point-min))
  1472. (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
  1473. ;; Check if the line before or after is a headline with a target
  1474. (if (setq target (or (get-text-property (point-at-bol 0) 'target)
  1475. (get-text-property (point-at-bol 2) 'target)))
  1476. (progn
  1477. ;; use the existing target in a neighboring line
  1478. (setq tmp (match-string 2))
  1479. (replace-match "")
  1480. (and (looking-at "\n") (delete-char 1))
  1481. (push (cons (setq tmp (org-solidify-link-text tmp)) target)
  1482. target-alist)
  1483. (setq a (or (assoc target org-export-target-aliases)
  1484. (progn
  1485. (push (list target) org-export-target-aliases)
  1486. (car org-export-target-aliases))))
  1487. (push tmp (cdr a)))
  1488. ;; Make an invisible target
  1489. (replace-match "\\1(INVISIBLE)"))))
  1490. target-alist)
  1491. (defun org-export-target-internal-links (target-alist)
  1492. "Find all internal links and assign targets to them.
  1493. If a link has a fuzzy match (i.e. not a *dedicated* target match),
  1494. let the link point to the corresponding section.
  1495. This function also handles the id links, if they have a match in
  1496. the current file."
  1497. (goto-char (point-min))
  1498. (while (re-search-forward org-bracket-link-regexp nil t)
  1499. (org-if-unprotected
  1500. (let* ((md (match-data))
  1501. (desc (match-end 2))
  1502. (link (org-link-unescape (match-string 1)))
  1503. (slink (org-solidify-link-text link))
  1504. found props pos cref
  1505. (target
  1506. (cond
  1507. ((cdr (assoc slink target-alist)))
  1508. ((and (string-match "^id:" link)
  1509. (cdr (assoc (substring link 3) target-alist))))
  1510. ((string-match "^(\\(.*\\))$" link)
  1511. (setq cref (match-string 1 link))
  1512. (concat "coderef:" cref))
  1513. ((string-match org-link-types-re link) nil)
  1514. ((or (file-name-absolute-p link)
  1515. (string-match "^\\." link))
  1516. nil)
  1517. (t
  1518. (save-excursion
  1519. (setq found (condition-case nil (org-link-search link)
  1520. (error nil)))
  1521. (when (and found
  1522. (or (org-on-heading-p)
  1523. (not (eq found 'dedicated))))
  1524. (or (get-text-property (point) 'target)
  1525. (get-text-property
  1526. (max (point-min)
  1527. (1- (or (previous-single-property-change
  1528. (point) 'target) 0)))
  1529. 'target))))))))
  1530. (when target
  1531. (set-match-data md)
  1532. (goto-char (match-beginning 1))
  1533. (setq props (text-properties-at (point)))
  1534. (delete-region (match-beginning 1) (match-end 1))
  1535. (setq pos (point))
  1536. (insert target)
  1537. (unless desc (insert "][" link))
  1538. (add-text-properties pos (point) props))))))
  1539. (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
  1540. "Remove drawers, or extract the content.
  1541. ALL-DRAWERS is a list of all drawer names valid in the current buffer.
  1542. EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
  1543. whose content to keep."
  1544. (unless (eq t exp-drawers)
  1545. (goto-char (point-min))
  1546. (let ((re (concat "^[ \t]*:\\("
  1547. (mapconcat
  1548. 'identity
  1549. (org-delete-all exp-drawers
  1550. (copy-sequence all-drawers))
  1551. "\\|")
  1552. "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
  1553. (while (re-search-forward re nil t)
  1554. (replace-match "")))))
  1555. (defun org-export-handle-export-tags (select-tags exclude-tags)
  1556. "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
  1557. Both arguments are lists of tags.
  1558. If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
  1559. will be removed.
  1560. After that, all subtrees that are marked by EXCLUDE-TAGS will be
  1561. removed as well."
  1562. (remove-text-properties (point-min) (point-max) '(:org-delete t))
  1563. (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
  1564. select-tags "\\|")
  1565. "\\):"))
  1566. (re-excl (concat ":\\(" (mapconcat 'regexp-quote
  1567. exclude-tags "\\|")
  1568. "\\):"))
  1569. beg end cont)
  1570. (goto-char (point-min))
  1571. (when (and select-tags
  1572. (re-search-forward
  1573. (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
  1574. ;; At least one tree is marked for export, this means
  1575. ;; all the unmarked stuff needs to go.
  1576. ;; Dig out the trees that should be exported
  1577. (goto-char (point-min))
  1578. (outline-next-heading)
  1579. (setq beg (point))
  1580. (put-text-property beg (point-max) :org-delete t)
  1581. (while (re-search-forward re-sel nil t)
  1582. (when (org-on-heading-p)
  1583. (org-back-to-heading)
  1584. (remove-text-properties
  1585. (max (1- (point)) (point-min))
  1586. (setq cont (save-excursion (org-end-of-subtree t t)))
  1587. '(:org-delete t))
  1588. (while (and (org-up-heading-safe)
  1589. (get-text-property (point) :org-delete))
  1590. (remove-text-properties (max (1- (point)) (point-min))
  1591. (point-at-eol) '(:org-delete t)))
  1592. (goto-char cont))))
  1593. ;; Remove the trees explicitly marked for noexport
  1594. (when exclude-tags
  1595. (goto-char (point-min))
  1596. (while (re-search-forward re-excl nil t)
  1597. (when (org-at-heading-p)
  1598. (org-back-to-heading t)
  1599. (setq beg (point))
  1600. (org-end-of-subtree t)
  1601. (delete-region beg (point)))))
  1602. ;; Remove everything that is now still marked for deletion
  1603. (goto-char (point-min))
  1604. (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
  1605. (setq end (or (next-single-property-change beg :org-delete)
  1606. (point-max)))
  1607. (delete-region beg end))))
  1608. (defun org-export-remove-archived-trees (export-archived-trees)
  1609. "Remove archived trees.
  1610. When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
  1611. When it is t, the entire archived tree will be exported.
  1612. When it is nil the entire tree including the headline will be removed
  1613. from the buffer."
  1614. (let ((re-archive (concat ":" org-archive-tag ":"))
  1615. a b)
  1616. (when (not (eq export-archived-trees t))
  1617. (goto-char (point-min))
  1618. (while (re-search-forward re-archive nil t)
  1619. (if (not (org-on-heading-p t))
  1620. (org-end-of-subtree t)
  1621. (beginning-of-line 1)
  1622. (setq a (if export-archived-trees
  1623. (1+ (point-at-eol)) (point))
  1624. b (org-end-of-subtree t))
  1625. (if (> b a) (delete-region a b)))))))
  1626. (defun org-export-remove-headline-metadata (opts)
  1627. "Remove meta data from the headline, according to user options."
  1628. (let ((re org-complex-heading-regexp)
  1629. (todo (plist-get opts :todo-keywords))
  1630. (tags (plist-get opts :tags))
  1631. (pri (plist-get opts :priority))
  1632. (elts '(1 2 3 4 5))
  1633. rpl props)
  1634. (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
  1635. (when (or (not todo) (not tags) (not pri))
  1636. (goto-char (point-min))
  1637. (while (re-search-forward re nil t)
  1638. (org-if-unprotected
  1639. (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
  1640. elts " "))
  1641. (replace-match rpl t t))))))
  1642. (defun org-export-remove-timestamps ()
  1643. "Remove timestamps and keywords for export."
  1644. (while (re-search-forward org-maybe-keyword-time-regexp nil t)
  1645. (org-if-unprotected
  1646. (replace-match "")
  1647. (beginning-of-line 1)
  1648. (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
  1649. (replace-match "")))))
  1650. (defun org-export-remove-clock-lines ()
  1651. "Remove timestamps and keywords for export."
  1652. (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
  1653. (while (re-search-forward re nil t)
  1654. (org-if-unprotected
  1655. (replace-match "")))))
  1656. (defun org-export-protect-quoted-subtrees ()
  1657. "Mark quoted subtrees with the protection property."
  1658. (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
  1659. (goto-char (point-min))
  1660. (while (re-search-forward re-quote nil t)
  1661. (goto-char (match-beginning 0))
  1662. (end-of-line 1)
  1663. (add-text-properties (point) (org-end-of-subtree t)
  1664. '(org-protected t)))))
  1665. (defun org-export-protect-verbatim ()
  1666. "Mark verbatim snippets with the protection property."
  1667. (goto-char (point-min))
  1668. (while (re-search-forward org-verbatim-re nil t)
  1669. (add-text-properties (match-beginning 4) (match-end 4)
  1670. '(org-protected t))
  1671. (goto-char (1+ (match-end 4)))))
  1672. (defun org-export-protect-colon-examples ()
  1673. "Protect lines starting with a colon."
  1674. (goto-char (point-min))
  1675. (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
  1676. (add-text-properties (match-beginning 0) (match-end 0)
  1677. '(org-protected t))))
  1678. (defun org-export-select-backend-specific-text (backend)
  1679. (let ((formatters
  1680. '((html "HTML" "BEGIN_HTML" "END_HTML")
  1681. (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
  1682. (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1683. (case-fold-search t)
  1684. fmt)
  1685. (while formatters
  1686. (setq fmt (pop formatters))
  1687. (when (eq (car fmt) backend)
  1688. ;; This is selected code, put it into the file for real
  1689. (goto-char (point-min))
  1690. (while (re-search-forward (concat "^#\\+" (cadr fmt)
  1691. ":[ \t]*\\(.*\\)") nil t)
  1692. (replace-match "\\1" t)
  1693. (add-text-properties
  1694. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1695. '(org-protected t))))
  1696. (goto-char (point-min))
  1697. (while (re-search-forward
  1698. (concat "^#\\+"
  1699. (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
  1700. (cadddr fmt) "\\>.*\n?") nil t)
  1701. (if (eq (car fmt) backend)
  1702. ;; yes, keep this
  1703. (add-text-properties (match-beginning 1) (1+ (match-end 1))
  1704. '(org-protected t))
  1705. ;; No, this is for a different backend, kill it
  1706. (delete-region (match-beginning 0) (match-end 0)))))))
  1707. (defun org-export-mark-blockquote-and-verse ()
  1708. "Mark block quote and verse environments with special cookies.
  1709. These special cookies will later be interpreted by the backend."
  1710. ;; Blockquotes
  1711. (goto-char (point-min))
  1712. (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
  1713. nil t)
  1714. (replace-match (if (equal (downcase (match-string 1)) "end")
  1715. "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
  1716. t t))
  1717. ;; Verse
  1718. (goto-char (point-min))
  1719. (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
  1720. (replace-match (if (equal (downcase (match-string 1)) "end")
  1721. "ORG-VERSE-END" "ORG-VERSE-START")
  1722. t t)))
  1723. (defun org-export-attach-captions-and-attributes (backend target-alist)
  1724. "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
  1725. If the next thing following is a table, add the text properties to the first
  1726. table line. If it is a link, add it to the line containing the link."
  1727. (goto-char (point-min))
  1728. (remove-text-properties (point-min) (point-max)
  1729. '(org-caption nil org-attributes nil))
  1730. (let ((case-fold-search t)
  1731. (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
  1732. "\\|"
  1733. "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
  1734. "\\|"
  1735. "^#\\+label:[ \t]+\\(.*\\)"
  1736. "\\|"
  1737. "^[ \t]*|[^-]"
  1738. "\\|"
  1739. "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
  1740. cap attr label)
  1741. (while (re-search-forward re nil t)
  1742. (cond
  1743. ((match-end 1)
  1744. (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
  1745. ((match-end 2)
  1746. (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
  1747. ((match-end 3)
  1748. (setq label (org-trim (match-string 3))))
  1749. (t
  1750. (add-text-properties (point-at-bol) (point-at-eol)
  1751. (list 'org-caption cap
  1752. 'org-attributes attr
  1753. 'org-label label))
  1754. (if label (push (cons label label) target-alist))
  1755. (setq cap nil attr nil label nil)))))
  1756. target-alist)
  1757. (defun org-export-remove-comment-blocks-and-subtrees ()
  1758. "Remove the comment environment, and also commented subtrees."
  1759. (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  1760. (case-fold-search nil))
  1761. ;; Remove comment environment
  1762. (goto-char (point-min))
  1763. (while (re-search-forward
  1764. "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
  1765. (replace-match "" t t))
  1766. ;; Remove subtrees that are commented
  1767. (goto-char (point-min))
  1768. (while (re-search-forward re-commented nil t)
  1769. (goto-char (match-beginning 0))
  1770. (delete-region (point) (org-end-of-subtree t)))))
  1771. (defun org-export-handle-comments (commentsp)
  1772. "Remove comments, or convert to backend-specific format.
  1773. COMMENTSP can be a format string for publishing comments.
  1774. When it is nil, all comments will be removed."
  1775. (let ((re "^#\\(.*\n?\\)")
  1776. pos)
  1777. (goto-char (point-min))
  1778. (while (or (looking-at re)
  1779. (re-search-forward re nil t))
  1780. (setq pos (match-beginning 0))
  1781. (if commentsp
  1782. (progn (add-text-properties
  1783. (match-beginning 0) (match-end 0) '(org-protected t))
  1784. (replace-match (format commentsp (match-string 1)) t t))
  1785. (goto-char (1+ pos))
  1786. (org-if-unprotected
  1787. (replace-match "")
  1788. (goto-char (max (point-min) (1- pos))))))))
  1789. (defun org-export-mark-radio-links ()
  1790. "Find all matches for radio targets and turn them into internal links."
  1791. (let ((re-radio (and org-target-link-regexp
  1792. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
  1793. (goto-char (point-min))
  1794. (when re-radio
  1795. (while (re-search-forward re-radio nil t)
  1796. (org-if-unprotected
  1797. (replace-match "\\1[[\\2]]"))))))
  1798. (defun org-export-remove-special-table-lines ()
  1799. "Remove tables lines that are used for internal purposes."
  1800. (goto-char (point-min))
  1801. (while (re-search-forward "^[ \t]*|" nil t)
  1802. (beginning-of-line 1)
  1803. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1804. (and (looking-at ".*?| *<[0-9]+> *|")
  1805. (not (looking-at ".*?| *[^ <|]"))))
  1806. (delete-region (max (point-min) (1- (point-at-bol)))
  1807. (point-at-eol))
  1808. (end-of-line 1))))
  1809. (defun org-export-normalize-links ()
  1810. "Convert all links to bracket links, and expand link abbreviations."
  1811. (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  1812. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
  1813. (goto-char (point-min))
  1814. (while (re-search-forward re-plain-link nil t)
  1815. (goto-char (1- (match-end 0)))
  1816. (org-if-unprotected
  1817. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1818. ":" (match-string 3) "]]")))
  1819. ;; added 'org-link face to links
  1820. (put-text-property 0 (length s) 'face 'org-link s)
  1821. (replace-match s t t))))
  1822. (goto-char (point-min))
  1823. (while (re-search-forward re-angle-link nil t)
  1824. (goto-char (1- (match-end 0)))
  1825. (org-if-unprotected
  1826. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1827. ":" (match-string 3) "]]")))
  1828. (put-text-property 0 (length s) 'face 'org-link s)
  1829. (replace-match s t t))))
  1830. (goto-char (point-min))
  1831. (while (re-search-forward org-bracket-link-regexp nil t)
  1832. (goto-char (1- (match-end 0)))
  1833. (org-if-unprotected
  1834. (let* ((xx (save-match-data
  1835. (org-translate-link
  1836. (org-link-expand-abbrev (match-string 1)))))
  1837. (s (concat
  1838. "[[" xx "]"
  1839. (if (match-end 3)
  1840. (match-string 2)
  1841. (concat "[" (org-add-props
  1842. (copy-sequence xx)
  1843. '(org-protected t))
  1844. "]"))
  1845. "]")))
  1846. (put-text-property 0 (length s) 'face 'org-link s)
  1847. (replace-match s t t))))))
  1848. (defun org-export-concatenate-multiline-links ()
  1849. "Find multi-line links and put it all into a single line.
  1850. This is to make sure that the line-processing export backends
  1851. can work correctly."
  1852. (goto-char (point-min))
  1853. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1854. (org-if-unprotected
  1855. (replace-match "\\1 \\3")
  1856. (goto-char (match-beginning 0)))))
  1857. (defun org-export-concatenate-multiline-emphasis ()
  1858. "Find multi-line emphasis and put it all into a single line.
  1859. This is to make sure that the line-processing export backends
  1860. can work correctly."
  1861. (goto-char (point-min))
  1862. (while (re-search-forward org-emph-re nil t)
  1863. (if (not (= (char-after (match-beginning 3))
  1864. (char-after (match-beginning 4))))
  1865. (org-if-unprotected
  1866. (subst-char-in-region (match-beginning 0) (match-end 0)
  1867. ?\n ?\ t)
  1868. (goto-char (1- (match-end 0))))
  1869. (goto-char (1+ (match-beginning 0))))))
  1870. (defun org-export-grab-title-from-buffer ()
  1871. "Get a title for the current document, from looking at the buffer."
  1872. (let ((inhibit-read-only t))
  1873. (save-excursion
  1874. (goto-char (point-min))
  1875. (let ((end (if (looking-at org-outline-regexp)
  1876. (point)
  1877. (save-excursion (outline-next-heading) (point)))))
  1878. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1879. ;; Mark the line so that it will not be exported as normal text.
  1880. (org-unmodified
  1881. (add-text-properties (match-beginning 0) (match-end 0)
  1882. (list :org-license-to-kill t)))
  1883. ;; Return the title string
  1884. (org-trim (match-string 0)))))))
  1885. (defun org-export-get-title-from-subtree ()
  1886. "Return subtree title and exclude it from export."
  1887. (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
  1888. (save-excursion
  1889. (goto-char rbeg)
  1890. (when (and (org-at-heading-p)
  1891. (>= (org-end-of-subtree t t) rend))
  1892. ;; This is a subtree, we take the title from the first heading
  1893. (goto-char rbeg)
  1894. (looking-at org-todo-line-regexp)
  1895. (setq title (match-string 3))
  1896. (org-unmodified
  1897. (add-text-properties (point) (1+ (point-at-eol))
  1898. (list :org-license-to-kill t)))
  1899. (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
  1900. title))
  1901. (defun org-solidify-link-text (s &optional alist)
  1902. "Take link text and make a safe target out of it."
  1903. (save-match-data
  1904. (let* ((rtn
  1905. (mapconcat
  1906. 'identity
  1907. (org-split-string s "[ \t\r\n]+") "=="))
  1908. (a (assoc rtn alist)))
  1909. (or (cdr a) rtn))))
  1910. (defun org-get-min-level (lines)
  1911. "Get the minimum level in LINES."
  1912. (let ((re "^\\(\\*+\\) ") l min)
  1913. (catch 'exit
  1914. (while (setq l (pop lines))
  1915. (if (string-match re l)
  1916. (throw 'exit (org-tr-level (length (match-string 1 l))))))
  1917. 1)))
  1918. ;; Variable holding the vector with section numbers
  1919. (defvar org-section-numbers (make-vector org-level-max 0))
  1920. (defun org-init-section-numbers ()
  1921. "Initialize the vector for the section numbers."
  1922. (let* ((level -1)
  1923. (numbers (nreverse (org-split-string "" "\\.")))
  1924. (depth (1- (length org-section-numbers)))
  1925. (i depth) number-string)
  1926. (while (>= i 0)
  1927. (if (> i level)
  1928. (aset org-section-numbers i 0)
  1929. (setq number-string (or (car numbers) "0"))
  1930. (if (string-match "\\`[A-Z]\\'" number-string)
  1931. (aset org-section-numbers i
  1932. (- (string-to-char number-string) ?A -1))
  1933. (aset org-section-numbers i (string-to-number number-string)))
  1934. (pop numbers))
  1935. (setq i (1- i)))))
  1936. (defun org-section-number (&optional level)
  1937. "Return a string with the current section number.
  1938. When LEVEL is non-nil, increase section numbers on that level."
  1939. (let* ((depth (1- (length org-section-numbers)))
  1940. (string "")
  1941. (fmts (car org-export-section-number-format))
  1942. (term (cdr org-export-section-number-format))
  1943. (sep "")
  1944. ctype fmt idx n)
  1945. (when level
  1946. (when (> level -1)
  1947. (aset org-section-numbers
  1948. level (1+ (aref org-section-numbers level))))
  1949. (setq idx (1+ level))
  1950. (while (<= idx depth)
  1951. (if (not (= idx 1))
  1952. (aset org-section-numbers idx 0))
  1953. (setq idx (1+ idx))))
  1954. (setq idx 0)
  1955. (while (<= idx depth)
  1956. (when (> (aref org-section-numbers idx) 0)
  1957. (setq fmt (or (pop fmts) fmt)
  1958. ctype (car fmt)
  1959. n (aref org-section-numbers idx)
  1960. string (if (> n 0)
  1961. (concat string sep (org-number-to-counter n ctype))
  1962. (concat string ".0"))
  1963. sep (nth 1 fmt)))
  1964. (setq idx (1+ idx)))
  1965. (save-match-data
  1966. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1967. (setq string (replace-match "" t nil string)))
  1968. (if (string-match "\\(\\.0\\)+\\'" string)
  1969. (setq string (replace-match "" t nil string))))
  1970. (concat string term)))
  1971. (defun org-number-to-counter (n type)
  1972. "Concert number N to a string counter, according to TYPE.
  1973. TYPE must be a string, any of:
  1974. 1 number
  1975. A A,B,....
  1976. a a,b,....
  1977. I upper case roman numeral
  1978. i lower case roman numeral"
  1979. (cond
  1980. ((equal type "1") (number-to-string n))
  1981. ((equal type "A") (char-to-string (+ ?A n -1)))
  1982. ((equal type "a") (char-to-string (+ ?a n -1)))
  1983. ((equal type "I") (org-number-to-roman n))
  1984. ((equal type "i") (downcase (org-number-to-roman n)))
  1985. (t (error "Invalid counter type `%s'" type))))
  1986. (defun org-number-to-roman (n)
  1987. "Convert integer N into a roman numeral."
  1988. (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
  1989. ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
  1990. ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
  1991. ( 1 . "I")))
  1992. (res ""))
  1993. (if (<= n 0)
  1994. (number-to-string n)
  1995. (while roman
  1996. (if (>= n (caar roman))
  1997. (setq n (- n (caar roman))
  1998. res (concat res (cdar roman)))
  1999. (pop roman)))
  2000. res)))
  2001. (org-number-to-roman 1961)
  2002. ;;; Include files
  2003. (defun org-export-handle-include-files ()
  2004. "Include the contents of include files, with proper formatting."
  2005. (let ((case-fold-search t)
  2006. params file markup lang start end prefix prefix1 switches)
  2007. (goto-char (point-min))
  2008. (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
  2009. (setq params (read (concat "(" (match-string 1) ")"))
  2010. prefix (org-get-and-remove-property 'params :prefix)
  2011. prefix1 (org-get-and-remove-property 'params :prefix1)
  2012. file (org-symname-or-string (pop params))
  2013. markup (org-symname-or-string (pop params))
  2014. lang (and (member markup '("src" "SRC"))
  2015. (org-symname-or-string (pop params)))
  2016. switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
  2017. (delete-region (match-beginning 0) (match-end 0))
  2018. (if (or (not file)
  2019. (not (file-exists-p file))
  2020. (not (file-readable-p file)))
  2021. (insert (format "CANNOT INCLUDE FILE %s" file))
  2022. (when markup
  2023. (if (equal (downcase markup) "src")
  2024. (setq start (format "#+begin_src %s %s\n"
  2025. (or lang "fundamental")
  2026. (or switches ""))
  2027. end "#+end_src")
  2028. (setq start (format "#+begin_%s %s\n" markup switches)
  2029. end (format "#+end_%s" markup))))
  2030. (insert (or start ""))
  2031. (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
  2032. (or (bolp) (newline))
  2033. (insert (or end ""))))))
  2034. (defun org-get-file-contents (file &optional prefix prefix1)
  2035. "Get the contents of FILE and return them as a string.
  2036. If PREFIX is a string, prepend it to each line. If PREFIX1
  2037. is a string, prepend it to the first line instead of PREFIX."
  2038. (with-temp-buffer
  2039. (insert-file-contents file)
  2040. (when (or prefix prefix1)
  2041. (goto-char (point-min))
  2042. (while (not (eobp))
  2043. (insert (or prefix1 prefix))
  2044. (setq prefix1 nil)
  2045. (beginning-of-line 2)))
  2046. (buffer-string)))
  2047. (defun org-get-and-remove-property (listvar prop)
  2048. "Check if the value of LISTVAR contains PROP as a property.
  2049. If yes, return the value of that property (i.e. the element following
  2050. in the list) and remove property and value from the list in LISTVAR."
  2051. (let ((list (symbol-value listvar)) m v)
  2052. (when (setq m (member prop list))
  2053. (setq v (nth 1 m))
  2054. (if (equal (car list) prop)
  2055. (set listvar (cddr list))
  2056. (setcdr (nthcdr (- (length list) (length m) 1) list)
  2057. (cddr m))
  2058. (set listvar list)))
  2059. v))
  2060. (defun org-symname-or-string (s)
  2061. (if (symbolp s)
  2062. (if s (symbol-name s) s)
  2063. s))
  2064. ;;; Fontification and line numbers for code examples
  2065. (defvar org-export-last-code-line-counter-value 0)
  2066. (defun org-export-replace-src-segments-and-examples (backend)
  2067. "Replace source code segments with special code for export."
  2068. (setq org-export-last-code-line-counter-value 0)
  2069. (let ((case-fold-search t)
  2070. lang code trans opts)
  2071. (goto-char (point-min))
  2072. (while (re-search-forward
  2073. "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
  2074. nil t)
  2075. (if (match-end 1)
  2076. ;; src segments
  2077. (setq lang (match-string 2)
  2078. opts (match-string 3)
  2079. code (match-string 4))
  2080. (setq lang nil
  2081. opts (match-string 6)
  2082. code (match-string 7)))
  2083. (setq trans (org-export-format-source-code-or-example
  2084. backend lang code opts))
  2085. (replace-match trans t t))))
  2086. (defvar htmlp) ;; dynamically scoped
  2087. (defvar latexp) ;; dynamically scoped
  2088. (defun org-export-format-source-code-or-example (backend
  2089. lang code &optional opts)
  2090. "Format CODE from language LANG and return it formatted for export.
  2091. If LANG is nil, do not add any fontification.
  2092. OPTS contains formatting optons, like `-n' for triggering numbering lines,
  2093. and `+n' for continuing previous numering.
  2094. Code formatting according to language currently only works for HTML.
  2095. Numbering lines works for all three major backends (html, latex, and ascii)."
  2096. (save-match-data
  2097. (let (num cont rtn named rpllbl keepp fmt)
  2098. (setq opts (or opts "")
  2099. num (string-match "[-+]n\\>" opts)
  2100. cont (string-match "\\+n\\>" opts)
  2101. rpllbl (string-match "-r\\>" opts)
  2102. keepp (string-match "-k\\>" opts)
  2103. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  2104. (match-string 1 opts)))
  2105. (if keepp (setq rpllbl 'keep))
  2106. (setq rtn code)
  2107. (when (equal lang "org")
  2108. (setq rtn (with-temp-buffer
  2109. (insert rtn)
  2110. ;; Free up the protected lines
  2111. (goto-char (point-min))
  2112. (while (re-search-forward "^," nil t)
  2113. (replace-match "")
  2114. (end-of-line 1))
  2115. (buffer-string))))
  2116. ;; Now backend-specific coding
  2117. (cond
  2118. ((eq backend 'html)
  2119. ;; We are exporting to HTML
  2120. (when lang
  2121. (require 'htmlize nil t)
  2122. (when (not (fboundp 'htmlize-region-for-paste))
  2123. ;; we do not have htmlize.el, or an old version of it
  2124. (message
  2125. "htmlize.el 1.34 or later is needed for source code formatting")))
  2126. (if lang
  2127. (let* ((mode (and lang (intern (concat lang "-mode"))))
  2128. (org-inhibit-startup t)
  2129. (org-startup-folded nil))
  2130. (setq rtn
  2131. (with-temp-buffer
  2132. (insert rtn)
  2133. (if (functionp mode)
  2134. (funcall mode)
  2135. (fundamental-mode))
  2136. (font-lock-fontify-buffer)
  2137. (org-export-htmlize-region-for-paste
  2138. (point-min) (point-max))))
  2139. (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
  2140. (setq rtn (replace-match
  2141. (format "<pre class=\"src src-%s\">\n" lang)
  2142. t t rtn))))
  2143. (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n")))
  2144. (setq rtn (org-export-number-lines rtn 'html 1 1 num cont rpllbl fmt))
  2145. (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
  2146. ((eq backend 'latex)
  2147. (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
  2148. (concat "\n#+BEGIN_LaTeX\n"
  2149. (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
  2150. '(org-protected t))
  2151. "#+END_LaTeX\n\n"))
  2152. ((eq backend 'ascii)
  2153. ;; This is not HTML or LaTeX, so just make it an example.
  2154. (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
  2155. (concat "#+BEGIN_ASCII\n"
  2156. (org-add-props
  2157. (concat
  2158. (mapconcat
  2159. (lambda (l) (concat " " l))
  2160. (org-split-string rtn "\n")
  2161. "\n")
  2162. "\n")
  2163. '(org-protected t))
  2164. "#+END_ASCII\n"))))))
  2165. (defun org-export-number-lines (text backend
  2166. &optional skip1 skip2 number cont
  2167. replace-labels label-format)
  2168. (if (and (not number) (not (eq replace-labels 'keep)))
  2169. (setq replace-labels nil)) ;; must use names if no numbers
  2170. (setq skip1 (or skip1 0) skip2 (or skip2 0))
  2171. (if (not cont) (setq org-export-last-code-line-counter-value 0))
  2172. (with-temp-buffer
  2173. (insert text)
  2174. (goto-char (point-max))
  2175. (skip-chars-backward " \t\n\r")
  2176. (delete-region (point) (point-max))
  2177. (beginning-of-line (- 1 skip2))
  2178. (let* ((last (org-current-line))
  2179. (n org-export-last-code-line-counter-value)
  2180. (nmax (+ n (- last skip1)))
  2181. (fmt (format "%%%dd: " (length (number-to-string nmax))))
  2182. (fm
  2183. (cond
  2184. ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
  2185. fmt))
  2186. ((eq backend 'ascii) fmt)
  2187. ((eq backend 'latex) fmt)
  2188. (t "")))
  2189. (label-format (or label-format org-coderef-label-format))
  2190. (label-pre (if (string-match "%s" label-format)
  2191. (substring label-format 0 (match-beginning 0))
  2192. label-format))
  2193. (label-post (if (string-match "%s" label-format)
  2194. (substring label-format (match-end 0))
  2195. ""))
  2196. (lbl-re
  2197. (concat
  2198. ".*?\\S-.*?\\([ \t]*\\("
  2199. (regexp-quote label-pre)
  2200. "\\([-a-zA-Z0-9_]+\\)"
  2201. (regexp-quote label-post)
  2202. "\\)\\)"))
  2203. ref)
  2204. (goto-line (1+ skip1))
  2205. (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
  2206. (if number
  2207. (insert (format fm (incf n)))
  2208. (forward-char 1))
  2209. (when (and (not (eq replace-labels 'keep))
  2210. (looking-at lbl-re))
  2211. (setq ref (match-string 3))
  2212. (if replace-labels
  2213. (progn
  2214. (delete-region (match-beginning 1) (match-end 1))
  2215. (push (cons ref n) org-export-code-refs))
  2216. (goto-char (match-beginning 2))
  2217. (delete-region (match-beginning 2) (match-end 2))
  2218. (insert "(" ref ")")
  2219. (push (cons ref (concat "(" ref ")")) org-export-code-refs))
  2220. (when (eq backend 'html)
  2221. (save-excursion
  2222. (beginning-of-line 1)
  2223. (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
  2224. ref))
  2225. (end-of-line 1)
  2226. (insert "</span>")))))
  2227. (setq org-export-last-code-line-counter-value n)
  2228. (goto-char (point-max))
  2229. (newline)
  2230. (buffer-string))))
  2231. ;;; ASCII export
  2232. (defvar org-last-level nil) ; dynamically scoped variable
  2233. (defvar org-min-level nil) ; dynamically scoped variable
  2234. (defvar org-levels-open nil) ; dynamically scoped parameter
  2235. (defvar org-ascii-current-indentation nil) ; For communication
  2236. ;;;###autoload
  2237. (defun org-export-as-ascii (arg)
  2238. "Export the outline as a pretty ASCII file.
  2239. If there is an active region, export only the region.
  2240. The prefix ARG specifies how many levels of the outline should become
  2241. underlined headlines. The default is 3."
  2242. (interactive "P")
  2243. (setq-default org-todo-line-regexp org-todo-line-regexp)
  2244. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  2245. (org-infile-export-plist)))
  2246. (region-p (org-region-active-p))
  2247. (rbeg (and region-p (region-beginning)))
  2248. (rend (and region-p (region-end)))
  2249. (subtree-p
  2250. (when region-p
  2251. (save-excursion
  2252. (goto-char rbeg)
  2253. (and (org-at-heading-p)
  2254. (>= (org-end-of-subtree t t) rend)))))
  2255. (opt-plist (if subtree-p
  2256. (org-export-add-subtree-options opt-plist rbeg)
  2257. opt-plist))
  2258. (custom-times org-display-custom-times)
  2259. (org-ascii-current-indentation '(0 . 0))
  2260. (level 0) line txt
  2261. (umax nil)
  2262. (umax-toc nil)
  2263. (case-fold-search nil)
  2264. (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2265. (filename (concat (file-name-as-directory
  2266. (org-export-directory :ascii opt-plist))
  2267. (file-name-sans-extension
  2268. (or (and subtree-p
  2269. (org-entry-get (region-beginning)
  2270. "EXPORT_FILE_NAME" t))
  2271. (file-name-nondirectory bfname)))
  2272. ".txt"))
  2273. (filename (if (equal (file-truename filename)
  2274. (file-truename bfname))
  2275. (concat filename ".txt")
  2276. filename))
  2277. (buffer (find-file-noselect filename))
  2278. (org-levels-open (make-vector org-level-max nil))
  2279. (odd org-odd-levels-only)
  2280. (date (plist-get opt-plist :date))
  2281. (author (plist-get opt-plist :author))
  2282. (title (or (and subtree-p (org-export-get-title-from-subtree))
  2283. (plist-get opt-plist :title)
  2284. (and (not
  2285. (plist-get opt-plist :skip-before-1st-heading))
  2286. (org-export-grab-title-from-buffer))
  2287. (file-name-sans-extension
  2288. (file-name-nondirectory bfname))))
  2289. (email (plist-get opt-plist :email))
  2290. (language (plist-get opt-plist :language))
  2291. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  2292. ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
  2293. (todo nil)
  2294. (lang-words nil)
  2295. (region
  2296. (buffer-substring
  2297. (if (org-region-active-p) (region-beginning) (point-min))
  2298. (if (org-region-active-p) (region-end) (point-max))))
  2299. (lines (org-split-string
  2300. (org-export-preprocess-string
  2301. region
  2302. :for-ascii t
  2303. :skip-before-1st-heading
  2304. (plist-get opt-plist :skip-before-1st-heading)
  2305. :drawers (plist-get opt-plist :drawers)
  2306. :tags (plist-get opt-plist :tags)
  2307. :priority (plist-get opt-plist :priority)
  2308. :footnotes (plist-get opt-plist :footnotes)
  2309. :timestamps (plist-get opt-plist :timestamps)
  2310. :todo-keywords (plist-get opt-plist :todo-keywords)
  2311. :verbatim-multiline t
  2312. :select-tags (plist-get opt-plist :select-tags)
  2313. :exclude-tags (plist-get opt-plist :exclude-tags)
  2314. :archived-trees
  2315. (plist-get opt-plist :archived-trees)
  2316. :add-text (plist-get opt-plist :text))
  2317. "\n"))
  2318. thetoc have-headings first-heading-pos
  2319. table-open table-buffer link desc)
  2320. (let ((inhibit-read-only t))
  2321. (org-unmodified
  2322. (remove-text-properties (point-min) (point-max)
  2323. '(:org-license-to-kill t))))
  2324. (setq org-min-level (org-get-min-level lines))
  2325. (setq org-last-level org-min-level)
  2326. (org-init-section-numbers)
  2327. (find-file-noselect filename)
  2328. (setq lang-words (or (assoc language org-export-language-setup)
  2329. (assoc "en" org-export-language-setup)))
  2330. (switch-to-buffer-other-window buffer)
  2331. (erase-buffer)
  2332. (fundamental-mode)
  2333. ;; create local variables for all options, to make sure all called
  2334. ;; functions get the correct information
  2335. (mapc (lambda (x)
  2336. (set (make-local-variable (nth 2 x))
  2337. (plist-get opt-plist (car x))))
  2338. org-export-plist-vars)
  2339. (org-set-local 'org-odd-levels-only odd)
  2340. (setq umax (if arg (prefix-numeric-value arg)
  2341. org-export-headline-levels))
  2342. (setq umax-toc (if (integerp org-export-with-toc)
  2343. (min org-export-with-toc umax)
  2344. umax))
  2345. ;; File header
  2346. (if title (org-insert-centered title ?=))
  2347. (insert "\n")
  2348. (if (and (or author email)
  2349. org-export-author-info)
  2350. (insert (concat (nth 1 lang-words) ": " (or author "")
  2351. (if email (concat " <" email ">") "")
  2352. "\n")))
  2353. (cond
  2354. ((and date (string-match "%" date))
  2355. (setq date (format-time-string date)))
  2356. (date)
  2357. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  2358. (if (and date org-export-time-stamp-file)
  2359. (insert (concat (nth 2 lang-words) ": " date"\n")))
  2360. (insert "\n\n")
  2361. (if org-export-with-toc
  2362. (progn
  2363. (push (concat (nth 3 lang-words) "\n") thetoc)
  2364. (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
  2365. "\n") thetoc)
  2366. (mapc '(lambda (line)
  2367. (if (string-match org-todo-line-regexp
  2368. line)
  2369. ;; This is a headline
  2370. (progn
  2371. (setq have-headings t)
  2372. (setq level (- (match-end 1) (match-beginning 1))
  2373. level (org-tr-level level)
  2374. txt (match-string 3 line)
  2375. todo
  2376. (or (and org-export-mark-todo-in-toc
  2377. (match-beginning 2)
  2378. (not (member (match-string 2 line)
  2379. org-done-keywords)))
  2380. ; TODO, not DONE
  2381. (and org-export-mark-todo-in-toc
  2382. (= level umax-toc)
  2383. (org-search-todo-below
  2384. line lines level))))
  2385. (setq txt (org-html-expand-for-ascii txt))
  2386. (while (string-match org-bracket-link-regexp txt)
  2387. (setq txt
  2388. (replace-match
  2389. (match-string (if (match-end 2) 3 1) txt)
  2390. t t txt)))
  2391. (if (and (memq org-export-with-tags '(not-in-toc nil))
  2392. (string-match
  2393. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  2394. txt))
  2395. (setq txt (replace-match "" t t txt)))
  2396. (if (string-match quote-re0 txt)
  2397. (setq txt (replace-match "" t t txt)))
  2398. (if org-export-with-section-numbers
  2399. (setq txt (concat (org-section-number level)
  2400. " " txt)))
  2401. (if (<= level umax-toc)
  2402. (progn
  2403. (push
  2404. (concat
  2405. (make-string
  2406. (* (max 0 (- level org-min-level)) 4) ?\ )
  2407. (format (if todo "%s (*)\n" "%s\n") txt))
  2408. thetoc)
  2409. (setq org-last-level level))
  2410. ))))
  2411. lines)
  2412. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  2413. (org-init-section-numbers)
  2414. (while (setq line (pop lines))
  2415. ;; Remove the quoted HTML tags.
  2416. (setq line (org-html-expand-for-ascii line))
  2417. ;; Replace links with the description when possible
  2418. (while (string-match org-bracket-link-regexp line)
  2419. (setq link (match-string 1 line)
  2420. desc (match-string (if (match-end 3) 3 1) line))
  2421. (if (and (> (length link) 8)
  2422. (equal (substring link 0 8) "coderef:"))
  2423. (setq line (replace-match
  2424. (format (org-export-get-coderef-format (substring link 8) desc)
  2425. (cdr (assoc
  2426. (substring link 8)
  2427. org-export-code-refs)))
  2428. t t line))
  2429. (setq line (replace-match
  2430. (if (match-end 3) "[\\3]" "[\\1]")
  2431. t nil line))))
  2432. (when custom-times
  2433. (setq line (org-translate-time line)))
  2434. (cond
  2435. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  2436. ;; a Headline
  2437. (setq first-heading-pos (or first-heading-pos (point)))
  2438. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  2439. txt (match-string 2 line))
  2440. (org-ascii-level-start level txt umax lines))
  2441. ((and org-export-with-tables
  2442. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  2443. (if (not table-open)
  2444. ;; New table starts
  2445. (setq table-open t table-buffer nil))
  2446. ;; Accumulate lines
  2447. (setq table-buffer (cons line table-buffer))
  2448. (when (or (not lines)
  2449. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  2450. (car lines))))
  2451. (setq table-open nil
  2452. table-buffer (nreverse table-buffer))
  2453. (insert (mapconcat
  2454. (lambda (x)
  2455. (org-fix-indentation x org-ascii-current-indentation))
  2456. (org-format-table-ascii table-buffer)
  2457. "\n") "\n")))
  2458. (t
  2459. (setq line (org-fix-indentation line org-ascii-current-indentation))
  2460. ;; Remove forced line breaks
  2461. (if (string-match "\\\\\\\\[ \t]*$" line)
  2462. (setq line (replace-match "" t t line)))
  2463. (if (and org-export-with-fixed-width
  2464. (string-match "^\\([ \t]*\\)\\(:\\)" line))
  2465. (setq line (replace-match "\\1" nil nil line)))
  2466. (insert line "\n"))))
  2467. (normal-mode)
  2468. ;; insert the table of contents
  2469. (when thetoc
  2470. (goto-char (point-min))
  2471. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  2472. (progn
  2473. (goto-char (match-beginning 0))
  2474. (replace-match ""))
  2475. (goto-char first-heading-pos))
  2476. (mapc 'insert thetoc)
  2477. (or (looking-at "[ \t]*\n[ \t]*\n")
  2478. (insert "\n\n")))
  2479. ;; Convert whitespace place holders
  2480. (goto-char (point-min))
  2481. (let (beg end)
  2482. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  2483. (setq end (next-single-property-change beg 'org-whitespace))
  2484. (goto-char beg)
  2485. (delete-region beg end)
  2486. (insert (make-string (- end beg) ?\ ))))
  2487. (save-buffer)
  2488. ;; remove display and invisible chars
  2489. (let (beg end)
  2490. (goto-char (point-min))
  2491. (while (setq beg (next-single-property-change (point) 'display))
  2492. (setq end (next-single-property-change beg 'display))
  2493. (delete-region beg end)
  2494. (goto-char beg)
  2495. (insert "=>"))
  2496. (goto-char (point-min))
  2497. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  2498. (setq end (next-single-property-change beg 'org-cwidth))
  2499. (delete-region beg end)
  2500. (goto-char beg)))
  2501. (goto-char (point-min))))
  2502. (defun org-export-ascii-preprocess ()
  2503. "Do extra work for ASCII export"
  2504. ;; Put quotes around verbatim text
  2505. (goto-char (point-min))
  2506. (while (re-search-forward org-verbatim-re nil t)
  2507. (goto-char (match-end 2))
  2508. (backward-delete-char 1) (insert "'")
  2509. (goto-char (match-beginning 2))
  2510. (delete-char 1) (insert "`")
  2511. (goto-char (match-end 2)))
  2512. (goto-char (point-min))
  2513. ;; Remove target markers
  2514. (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
  2515. (replace-match "\\1\\2")))
  2516. (defun org-search-todo-below (line lines level)
  2517. "Search the subtree below LINE for any TODO entries."
  2518. (let ((rest (cdr (memq line lines)))
  2519. (re org-todo-line-regexp)
  2520. line lv todo)
  2521. (catch 'exit
  2522. (while (setq line (pop rest))
  2523. (if (string-match re line)
  2524. (progn
  2525. (setq lv (- (match-end 1) (match-beginning 1))
  2526. todo (and (match-beginning 2)
  2527. (not (member (match-string 2 line)
  2528. org-done-keywords))))
  2529. ; TODO, not DONE
  2530. (if (<= lv level) (throw 'exit nil))
  2531. (if todo (throw 'exit t))))))))
  2532. (defun org-html-expand-for-ascii (line)
  2533. "Handle quoted HTML for ASCII export."
  2534. (if org-export-html-expand
  2535. (while (string-match "@<[^<>\n]*>" line)
  2536. ;; We just remove the tags for now.
  2537. (setq line (replace-match "" nil nil line))))
  2538. line)
  2539. (defun org-insert-centered (s &optional underline)
  2540. "Insert the string S centered and underline it with character UNDERLINE."
  2541. (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
  2542. (insert (make-string ind ?\ ) s "\n")
  2543. (if underline
  2544. (insert (make-string ind ?\ )
  2545. (make-string (string-width s) underline)
  2546. "\n"))))
  2547. (defun org-ascii-level-start (level title umax &optional lines)
  2548. "Insert a new level in ASCII export."
  2549. (let (char (n (- level umax 1)) (ind 0))
  2550. (if (> level umax)
  2551. (progn
  2552. (insert (make-string (* 2 n) ?\ )
  2553. (char-to-string (nth (% n (length org-export-ascii-bullets))
  2554. org-export-ascii-bullets))
  2555. " " title "\n")
  2556. ;; find the indentation of the next non-empty line
  2557. (catch 'stop
  2558. (while lines
  2559. (if (string-match "^\\* " (car lines)) (throw 'stop nil))
  2560. (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
  2561. (throw 'stop (setq ind (org-get-indentation (car lines)))))
  2562. (pop lines)))
  2563. (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
  2564. (if (or (not (equal (char-before) ?\n))
  2565. (not (equal (char-before (1- (point))) ?\n)))
  2566. (insert "\n"))
  2567. (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
  2568. (unless org-export-with-tags
  2569. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  2570. (setq title (replace-match "" t t title))))
  2571. (if org-export-with-section-numbers
  2572. (setq title (concat (org-section-number level) " " title)))
  2573. (insert title "\n" (make-string (string-width title) char) "\n")
  2574. (setq org-ascii-current-indentation '(0 . 0)))))
  2575. ;;;###autoload
  2576. (defun org-export-visible (type arg)
  2577. "Create a copy of the visible part of the current buffer, and export it.
  2578. The copy is created in a temporary buffer and removed after use.
  2579. TYPE is the final key (as a string) that also select the export command in
  2580. the `C-c C-e' export dispatcher.
  2581. As a special case, if the you type SPC at the prompt, the temporary
  2582. org-mode file will not be removed but presented to you so that you can
  2583. continue to use it. The prefix arg ARG is passed through to the exporting
  2584. command."
  2585. (interactive
  2586. (list (progn
  2587. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
  2588. (read-char-exclusive))
  2589. current-prefix-arg))
  2590. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
  2591. (error "Invalid export key"))
  2592. (let* ((binding (cdr (assoc type
  2593. '((?a . org-export-as-ascii)
  2594. (?\C-a . org-export-as-ascii)
  2595. (?b . org-export-as-html-and-open)
  2596. (?\C-b . org-export-as-html-and-open)
  2597. (?h . org-export-as-html)
  2598. (?H . org-export-as-html-to-buffer)
  2599. (?R . org-export-region-as-html)
  2600. (?x . org-export-as-xoxo)))))
  2601. (keepp (equal type ?\ ))
  2602. (file buffer-file-name)
  2603. (buffer (get-buffer-create "*Org Export Visible*"))
  2604. s e)
  2605. ;; Need to hack the drawers here.
  2606. (save-excursion
  2607. (goto-char (point-min))
  2608. (while (re-search-forward org-drawer-regexp nil t)
  2609. (goto-char (match-beginning 1))
  2610. (or (org-invisible-p) (org-flag-drawer nil))))
  2611. (with-current-buffer buffer (erase-buffer))
  2612. (save-excursion
  2613. (setq s (goto-char (point-min)))
  2614. (while (not (= (point) (point-max)))
  2615. (goto-char (org-find-invisible))
  2616. (append-to-buffer buffer s (point))
  2617. (setq s (goto-char (org-find-visible))))
  2618. (org-cycle-hide-drawers 'all)
  2619. (goto-char (point-min))
  2620. (unless keepp
  2621. ;; Copy all comment lines to the end, to make sure #+ settings are
  2622. ;; still available for the second export step. Kind of a hack, but
  2623. ;; does do the trick.
  2624. (if (looking-at "#[^\r\n]*")
  2625. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  2626. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  2627. (append-to-buffer buffer (1+ (match-beginning 0))
  2628. (min (point-max) (1+ (match-end 0))))))
  2629. (set-buffer buffer)
  2630. (let ((buffer-file-name file)
  2631. (org-inhibit-startup t))
  2632. (org-mode)
  2633. (show-all)
  2634. (unless keepp (funcall binding arg))))
  2635. (if (not keepp)
  2636. (kill-buffer buffer)
  2637. (switch-to-buffer-other-window buffer)
  2638. (goto-char (point-min)))))
  2639. (defun org-find-visible ()
  2640. (let ((s (point)))
  2641. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2642. (get-char-property s 'invisible)))
  2643. s))
  2644. (defun org-find-invisible ()
  2645. (let ((s (point)))
  2646. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  2647. (not (get-char-property s 'invisible))))
  2648. s))
  2649. ;;; HTML export
  2650. (defvar org-archive-location) ;; gets loaded with the org-archive require.
  2651. (defun org-get-current-options ()
  2652. "Return a string with current options as keyword options.
  2653. Does include HTML export options as well as TODO and CATEGORY stuff."
  2654. (require 'org-archive)
  2655. (format
  2656. "#+TITLE: %s
  2657. #+AUTHOR: %s
  2658. #+EMAIL: %s
  2659. #+DATE: %s
  2660. #+LANGUAGE: %s
  2661. #+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
  2662. %s
  2663. #+EXPORT_SELECT_TAGS: %s
  2664. #+EXPORT_EXCLUDE_TAGS: %s
  2665. #+LINK_UP: %s
  2666. #+LINK_HOME: %s
  2667. #+CATEGORY: %s
  2668. #+SEQ_TODO: %s
  2669. #+TYP_TODO: %s
  2670. #+PRIORITIES: %c %c %c
  2671. #+DRAWERS: %s
  2672. #+STARTUP: %s %s %s %s %s
  2673. #+TAGS: %s
  2674. #+FILETAGS: %s
  2675. #+ARCHIVE: %s
  2676. #+LINK: %s
  2677. "
  2678. (buffer-name) (user-full-name) user-mail-address
  2679. (format-time-string (substring (car org-time-stamp-formats) 1 -1))
  2680. org-export-default-language
  2681. org-export-headline-levels
  2682. org-export-with-section-numbers
  2683. org-export-with-toc
  2684. org-export-preserve-breaks
  2685. org-export-html-expand
  2686. org-export-with-fixed-width
  2687. org-export-with-tables
  2688. org-export-with-sub-superscripts
  2689. org-export-with-special-strings
  2690. org-export-with-footnotes
  2691. org-export-with-emphasize
  2692. org-export-with-TeX-macros
  2693. org-export-with-LaTeX-fragments
  2694. org-export-skip-text-before-1st-heading
  2695. org-export-with-drawers
  2696. org-export-with-todo-keywords
  2697. org-export-with-priority
  2698. org-export-with-tags
  2699. (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
  2700. (mapconcat 'identity org-export-select-tags " ")
  2701. (mapconcat 'identity org-export-exclude-tags " ")
  2702. org-export-html-link-up
  2703. org-export-html-link-home
  2704. (file-name-nondirectory buffer-file-name)
  2705. "TODO FEEDBACK VERIFY DONE"
  2706. "Me Jason Marie DONE"
  2707. org-highest-priority org-lowest-priority org-default-priority
  2708. (mapconcat 'identity org-drawers " ")
  2709. (cdr (assoc org-startup-folded
  2710. '((nil . "showall") (t . "overview") (content . "content"))))
  2711. (if org-odd-levels-only "odd" "oddeven")
  2712. (if org-hide-leading-stars "hidestars" "showstars")
  2713. (if org-startup-align-all-tables "align" "noalign")
  2714. (cond ((eq org-log-done t) "logdone")
  2715. ((equal org-log-done 'note) "lognotedone")
  2716. ((not org-log-done) "nologdone"))
  2717. (or (mapconcat (lambda (x)
  2718. (cond
  2719. ((equal '(:startgroup) x) "{")
  2720. ((equal '(:endgroup) x) "}")
  2721. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  2722. (t (car x))))
  2723. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  2724. (mapconcat 'identity org-file-tags " ")
  2725. org-archive-location
  2726. "org file:~/org/%s.org"
  2727. ))
  2728. (defun org-export-html-preprocess (parameters)
  2729. ;; Convert LaTeX fragments to images
  2730. (when (plist-get parameters :LaTeX-fragments)
  2731. (org-format-latex
  2732. (concat "ltxpng/" (file-name-sans-extension
  2733. (file-name-nondirectory
  2734. org-current-export-file)))
  2735. org-current-export-dir nil "Creating LaTeX image %s"))
  2736. (message "Exporting..."))
  2737. ;;;###autoload
  2738. (defun org-insert-export-options-template ()
  2739. "Insert into the buffer a template with information for exporting."
  2740. (interactive)
  2741. (if (not (bolp)) (newline))
  2742. (let ((s (org-get-current-options)))
  2743. (and (string-match "#\\+CATEGORY" s)
  2744. (setq s (substring s 0 (match-beginning 0))))
  2745. (insert s)))
  2746. ;;;###autoload
  2747. (defun org-export-as-html-and-open (arg)
  2748. "Export the outline as HTML and immediately open it with a browser.
  2749. If there is an active region, export only the region.
  2750. The prefix ARG specifies how many levels of the outline should become
  2751. headlines. The default is 3. Lower levels will become bulleted lists."
  2752. (interactive "P")
  2753. (org-export-as-html arg 'hidden)
  2754. (org-open-file buffer-file-name))
  2755. ;;;###autoload
  2756. (defun org-export-as-html-batch ()
  2757. "Call `org-export-as-html', may be used in batch processing as
  2758. emacs --batch
  2759. --load=$HOME/lib/emacs/org.el
  2760. --eval \"(setq org-export-headline-levels 2)\"
  2761. --visit=MyFile --funcall org-export-as-html-batch"
  2762. (org-export-as-html org-export-headline-levels 'hidden))
  2763. ;;;###autoload
  2764. (defun org-export-as-html-to-buffer (arg)
  2765. "Call `org-export-as-html` with output to a temporary buffer.
  2766. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  2767. (interactive "P")
  2768. (org-export-as-html arg nil nil "*Org HTML Export*")
  2769. (switch-to-buffer-other-window "*Org HTML Export*"))
  2770. ;;;###autoload
  2771. (defun org-replace-region-by-html (beg end)
  2772. "Assume the current region has org-mode syntax, and convert it to HTML.
  2773. This can be used in any buffer. For example, you could write an
  2774. itemized list in org-mode syntax in an HTML buffer and then use this
  2775. command to convert it."
  2776. (interactive "r")
  2777. (let (reg html buf pop-up-frames)
  2778. (save-window-excursion
  2779. (if (org-mode-p)
  2780. (setq html (org-export-region-as-html
  2781. beg end t 'string))
  2782. (setq reg (buffer-substring beg end)
  2783. buf (get-buffer-create "*Org tmp*"))
  2784. (with-current-buffer buf
  2785. (erase-buffer)
  2786. (insert reg)
  2787. (org-mode)
  2788. (setq html (org-export-region-as-html
  2789. (point-min) (point-max) t 'string)))
  2790. (kill-buffer buf)))
  2791. (delete-region beg end)
  2792. (insert html)))
  2793. ;;;###autoload
  2794. (defun org-export-region-as-html (beg end &optional body-only buffer)
  2795. "Convert region from BEG to END in org-mode buffer to HTML.
  2796. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  2797. contents, and only produce the region of converted text, useful for
  2798. cut-and-paste operations.
  2799. If BUFFER is a buffer or a string, use/create that buffer as a target
  2800. of the converted HTML. If BUFFER is the symbol `string', return the
  2801. produced HTML as a string and leave not buffer behind. For example,
  2802. a Lisp program could call this function in the following way:
  2803. (setq html (org-export-region-as-html beg end t 'string))
  2804. When called interactively, the output buffer is selected, and shown
  2805. in a window. A non-interactive call will only return the buffer."
  2806. (interactive "r\nP")
  2807. (when (interactive-p)
  2808. (setq buffer "*Org HTML Export*"))
  2809. (let ((transient-mark-mode t) (zmacs-regions t)
  2810. ext-plist rtn)
  2811. (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
  2812. (goto-char end)
  2813. (set-mark (point)) ;; to activate the region
  2814. (goto-char beg)
  2815. (setq rtn (org-export-as-html
  2816. nil nil ext-plist
  2817. buffer body-only))
  2818. (if (fboundp 'deactivate-mark) (deactivate-mark))
  2819. (if (and (interactive-p) (bufferp rtn))
  2820. (switch-to-buffer-other-window rtn)
  2821. rtn)))
  2822. (defvar html-table-tag nil) ; dynamically scoped into this.
  2823. (defvar org-par-open nil)
  2824. ;;;###autoload
  2825. (defun org-export-as-html (arg &optional hidden ext-plist
  2826. to-buffer body-only pub-dir)
  2827. "Export the outline as a pretty HTML file.
  2828. If there is an active region, export only the region. The prefix
  2829. ARG specifies how many levels of the outline should become
  2830. headlines. The default is 3. Lower levels will become bulleted
  2831. lists. When HIDDEN is non-nil, don't display the HTML buffer.
  2832. EXT-PLIST is a property list with external parameters overriding
  2833. org-mode's default settings, but still inferior to file-local
  2834. settings. When TO-BUFFER is non-nil, create a buffer with that
  2835. name and export to that buffer. If TO-BUFFER is the symbol
  2836. `string', don't leave any buffer behind but just return the
  2837. resulting HTML as a string. When BODY-ONLY is set, don't produce
  2838. the file header and footer, simply return the content of
  2839. <body>...</body>, without even the body tags themselves. When
  2840. PUB-DIR is set, use this as the publishing directory."
  2841. (interactive "P")
  2842. ;; Make sure we have a file name when we need it.
  2843. (when (and (not (or to-buffer body-only))
  2844. (not buffer-file-name))
  2845. (if (buffer-base-buffer)
  2846. (org-set-local 'buffer-file-name
  2847. (with-current-buffer (buffer-base-buffer)
  2848. buffer-file-name))
  2849. (error "Need a file name to be able to export.")))
  2850. (message "Exporting...")
  2851. (setq-default org-todo-line-regexp org-todo-line-regexp)
  2852. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  2853. (setq-default org-done-keywords org-done-keywords)
  2854. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  2855. (let* ((opt-plist
  2856. (org-export-process-option-filters
  2857. (org-combine-plists (org-default-export-plist)
  2858. ext-plist
  2859. (org-infile-export-plist))))
  2860. (style (concat (if (plist-get opt-plist :style-include-default)
  2861. org-export-html-style-default)
  2862. (plist-get opt-plist :style)
  2863. (plist-get opt-plist :style-extra)
  2864. "\n" org-export-html-scripts))
  2865. (html-extension (plist-get opt-plist :html-extension))
  2866. (link-validate (plist-get opt-plist :link-validation-function))
  2867. valid thetoc have-headings first-heading-pos
  2868. (odd org-odd-levels-only)
  2869. (region-p (org-region-active-p))
  2870. (rbeg (and region-p (region-beginning)))
  2871. (rend (and region-p (region-end)))
  2872. (subtree-p
  2873. (if (plist-get opt-plist :ignore-subree-p)
  2874. nil
  2875. (when region-p
  2876. (save-excursion
  2877. (goto-char rbeg)
  2878. (and (org-at-heading-p)
  2879. (>= (org-end-of-subtree t t) rend))))))
  2880. (opt-plist (if subtree-p
  2881. (org-export-add-subtree-options opt-plist rbeg)
  2882. opt-plist))
  2883. ;; The following two are dynamically scoped into other
  2884. ;; routines below.
  2885. (org-current-export-dir
  2886. (or pub-dir (org-export-directory :html opt-plist)))
  2887. (org-current-export-file buffer-file-name)
  2888. (level 0) (line "") (origline "") txt todo
  2889. (umax nil)
  2890. (umax-toc nil)
  2891. (filename (if to-buffer nil
  2892. (expand-file-name
  2893. (concat
  2894. (file-name-sans-extension
  2895. (or (and subtree-p
  2896. (org-entry-get (region-beginning)
  2897. "EXPORT_FILE_NAME" t))
  2898. (file-name-nondirectory buffer-file-name)))
  2899. "." html-extension)
  2900. (file-name-as-directory
  2901. (or pub-dir (org-export-directory :html opt-plist))))))
  2902. (current-dir (if buffer-file-name
  2903. (file-name-directory buffer-file-name)
  2904. default-directory))
  2905. (buffer (if to-buffer
  2906. (cond
  2907. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  2908. (t (get-buffer-create to-buffer)))
  2909. (find-file-noselect filename)))
  2910. (org-levels-open (make-vector org-level-max nil))
  2911. (date (plist-get opt-plist :date))
  2912. (author (plist-get opt-plist :author))
  2913. (title (or (and subtree-p (org-export-get-title-from-subtree))
  2914. (plist-get opt-plist :title)
  2915. (and (not
  2916. (plist-get opt-plist :skip-before-1st-heading))
  2917. (org-export-grab-title-from-buffer))
  2918. (and buffer-file-name
  2919. (file-name-sans-extension
  2920. (file-name-nondirectory buffer-file-name)))
  2921. "UNTITLED"))
  2922. (html-table-tag (plist-get opt-plist :html-table-tag))
  2923. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  2924. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  2925. (inquote nil)
  2926. (infixed nil)
  2927. (inverse nil)
  2928. (in-local-list nil)
  2929. (local-list-type nil)
  2930. (local-list-indent nil)
  2931. (llt org-plain-list-ordered-item-terminator)
  2932. (email (plist-get opt-plist :email))
  2933. (language (plist-get opt-plist :language))
  2934. (lang-words nil)
  2935. (head-count 0) cnt
  2936. (start 0)
  2937. (coding-system (and (boundp 'buffer-file-coding-system)
  2938. buffer-file-coding-system))
  2939. (coding-system-for-write (or org-export-html-coding-system
  2940. coding-system))
  2941. (save-buffer-coding-system (or org-export-html-coding-system
  2942. coding-system))
  2943. (charset (and coding-system-for-write
  2944. (fboundp 'coding-system-get)
  2945. (coding-system-get coding-system-for-write
  2946. 'mime-charset)))
  2947. (region
  2948. (buffer-substring
  2949. (if region-p (region-beginning) (point-min))
  2950. (if region-p (region-end) (point-max))))
  2951. (lines
  2952. (org-split-string
  2953. (org-export-preprocess-string
  2954. region
  2955. :emph-multiline t
  2956. :for-html t
  2957. :skip-before-1st-heading
  2958. (plist-get opt-plist :skip-before-1st-heading)
  2959. :drawers (plist-get opt-plist :drawers)
  2960. :todo-keywords (plist-get opt-plist :todo-keywords)
  2961. :tags (plist-get opt-plist :tags)
  2962. :priority (plist-get opt-plist :priority)
  2963. :footnotes (plist-get opt-plist :footnotes)
  2964. :timestamps (plist-get opt-plist :timestamps)
  2965. :archived-trees
  2966. (plist-get opt-plist :archived-trees)
  2967. :select-tags (plist-get opt-plist :select-tags)
  2968. :exclude-tags (plist-get opt-plist :exclude-tags)
  2969. :add-text
  2970. (plist-get opt-plist :text)
  2971. :LaTeX-fragments
  2972. (plist-get opt-plist :LaTeX-fragments))
  2973. "[\r\n]"))
  2974. table-open type
  2975. table-buffer table-orig-buffer
  2976. ind item-type starter didclose
  2977. rpl path attr desc descp desc1 desc2 link
  2978. snumber fnc item-tag
  2979. footnotes footref-seen
  2980. )
  2981. (let ((inhibit-read-only t))
  2982. (org-unmodified
  2983. (remove-text-properties (point-min) (point-max)
  2984. '(:org-license-to-kill t))))
  2985. (message "Exporting...")
  2986. (setq org-min-level (org-get-min-level lines))
  2987. (setq org-last-level org-min-level)
  2988. (org-init-section-numbers)
  2989. (cond
  2990. ((and date (string-match "%" date))
  2991. (setq date (format-time-string date)))
  2992. (date)
  2993. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  2994. ;; Get the language-dependent settings
  2995. (setq lang-words (or (assoc language org-export-language-setup)
  2996. (assoc "en" org-export-language-setup)))
  2997. ;; Switch to the output buffer
  2998. (set-buffer buffer)
  2999. (let ((inhibit-read-only t)) (erase-buffer))
  3000. (fundamental-mode)
  3001. (and (fboundp 'set-buffer-file-coding-system)
  3002. (set-buffer-file-coding-system coding-system-for-write))
  3003. (let ((case-fold-search nil)
  3004. (org-odd-levels-only odd))
  3005. ;; create local variables for all options, to make sure all called
  3006. ;; functions get the correct information
  3007. (mapc (lambda (x)
  3008. (set (make-local-variable (nth 2 x))
  3009. (plist-get opt-plist (car x))))
  3010. org-export-plist-vars)
  3011. (setq umax (if arg (prefix-numeric-value arg)
  3012. org-export-headline-levels))
  3013. (setq umax-toc (if (integerp org-export-with-toc)
  3014. (min org-export-with-toc umax)
  3015. umax))
  3016. (unless body-only
  3017. ;; File header
  3018. (insert (format
  3019. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  3020. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  3021. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  3022. lang=\"%s\" xml:lang=\"%s\">
  3023. <head>
  3024. <title>%s</title>
  3025. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  3026. <meta name=\"generator\" content=\"Org-mode\"/>
  3027. <meta name=\"generated\" content=\"%s\"/>
  3028. <meta name=\"author\" content=\"%s\"/>
  3029. %s
  3030. </head><body>
  3031. "
  3032. language language (org-html-expand title)
  3033. (or charset "iso-8859-1") date author style))
  3034. (insert (or (plist-get opt-plist :preamble) ""))
  3035. (when (plist-get opt-plist :auto-preamble)
  3036. (if title (insert (format org-export-html-title-format
  3037. (org-html-expand title))))))
  3038. (if (and org-export-with-toc (not body-only))
  3039. (progn
  3040. (push (format "<h%d>%s</h%d>\n"
  3041. org-export-html-toplevel-hlevel
  3042. (nth 3 lang-words)
  3043. org-export-html-toplevel-hlevel)
  3044. thetoc)
  3045. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  3046. (push "<ul>\n<li>" thetoc)
  3047. (setq lines
  3048. (mapcar '(lambda (line)
  3049. (if (string-match org-todo-line-regexp line)
  3050. ;; This is a headline
  3051. (progn
  3052. (setq have-headings t)
  3053. (setq level (- (match-end 1) (match-beginning 1))
  3054. level (org-tr-level level)
  3055. txt (save-match-data
  3056. (org-html-expand
  3057. (org-export-cleanup-toc-line
  3058. (match-string 3 line))))
  3059. todo
  3060. (or (and org-export-mark-todo-in-toc
  3061. (match-beginning 2)
  3062. (not (member (match-string 2 line)
  3063. org-done-keywords)))
  3064. ; TODO, not DONE
  3065. (and org-export-mark-todo-in-toc
  3066. (= level umax-toc)
  3067. (org-search-todo-below
  3068. line lines level))))
  3069. (if (string-match
  3070. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  3071. (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  3072. (if (string-match quote-re0 txt)
  3073. (setq txt (replace-match "" t t txt)))
  3074. (setq snumber (org-section-number level))
  3075. (if org-export-with-section-numbers
  3076. (setq txt (concat snumber " " txt)))
  3077. (if (<= level (max umax umax-toc))
  3078. (setq head-count (+ head-count 1)))
  3079. (if (<= level umax-toc)
  3080. (progn
  3081. (if (> level org-last-level)
  3082. (progn
  3083. (setq cnt (- level org-last-level))
  3084. (while (>= (setq cnt (1- cnt)) 0)
  3085. (push "\n<ul>\n<li>" thetoc))
  3086. (push "\n" thetoc)))
  3087. (if (< level org-last-level)
  3088. (progn
  3089. (setq cnt (- org-last-level level))
  3090. (while (>= (setq cnt (1- cnt)) 0)
  3091. (push "</li>\n</ul>" thetoc))
  3092. (push "\n" thetoc)))
  3093. ;; Check for targets
  3094. (while (string-match org-any-target-regexp line)
  3095. (setq line (replace-match
  3096. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  3097. t t line)))
  3098. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  3099. (setq txt (replace-match "" t t txt)))
  3100. (push
  3101. (format
  3102. (if todo
  3103. "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
  3104. "</li>\n<li><a href=\"#sec-%s\">%s</a>")
  3105. snumber txt) thetoc)
  3106. (setq org-last-level level))
  3107. )))
  3108. line)
  3109. lines))
  3110. (while (> org-last-level (1- org-min-level))
  3111. (setq org-last-level (1- org-last-level))
  3112. (push "</li>\n</ul>\n" thetoc))
  3113. (push "</div>\n" thetoc)
  3114. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  3115. (setq head-count 0)
  3116. (org-init-section-numbers)
  3117. (org-open-par)
  3118. (while (setq line (pop lines) origline line)
  3119. (catch 'nextline
  3120. ;; end of quote section?
  3121. (when (and inquote (string-match "^\\*+ " line))
  3122. (insert "</pre>\n")
  3123. (setq inquote nil))
  3124. ;; inside a quote section?
  3125. (when inquote
  3126. (insert (org-html-protect line) "\n")
  3127. (throw 'nextline nil))
  3128. ;; Fixed-width, verbatim lines (examples)
  3129. (when (and org-export-with-fixed-width
  3130. (string-match "^[ \t]*:\\(.*\\)" line))
  3131. (when (not infixed)
  3132. (setq infixed t)
  3133. (org-close-par-maybe)
  3134. (insert "<pre class=\"example\">\n"))
  3135. (insert (org-html-protect (match-string 1 line)) "\n")
  3136. (when (or (not lines)
  3137. (not (string-match "^[ \t]*\\(:.*\\)"
  3138. (car lines))))
  3139. (setq infixed nil)
  3140. (insert "</pre>\n"))
  3141. (throw 'nextline nil))
  3142. ;; Protected HTML
  3143. (when (get-text-property 0 'org-protected line)
  3144. (let (par)
  3145. (when (re-search-backward
  3146. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  3147. (setq par (match-string 1))
  3148. (replace-match "\\2\n"))
  3149. (insert line "\n")
  3150. (while (and lines
  3151. (or (= (length (car lines)) 0)
  3152. (get-text-property 0 'org-protected (car lines))))
  3153. (insert (pop lines) "\n"))
  3154. (and par (insert "<p>\n")))
  3155. (throw 'nextline nil))
  3156. ;; Horizontal line
  3157. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  3158. (if org-par-open
  3159. (insert "\n</p>\n<hr/>\n<p>\n")
  3160. (insert "\n<hr/>\n"))
  3161. (throw 'nextline nil))
  3162. ;; Blockquotes and verse
  3163. (when (equal "ORG-BLOCKQUOTE-START" line)
  3164. (org-close-par-maybe)
  3165. (insert "<blockquote>\n<p>\n")
  3166. (throw 'nextline nil))
  3167. (when (equal "ORG-BLOCKQUOTE-END" line)
  3168. (insert "</p>\n</blockquote>\n")
  3169. (throw 'nextline nil))
  3170. (when (equal "ORG-VERSE-START" line)
  3171. (org-close-par-maybe)
  3172. (insert "\n<p class=\"verse\">\n")
  3173. (setq inverse t)
  3174. (throw 'nextline nil))
  3175. (when (equal "ORG-VERSE-END" line)
  3176. (insert "</p>\n")
  3177. (setq inverse nil)
  3178. (throw 'nextline nil))
  3179. (when inverse
  3180. (let ((i (org-get-string-indentation line)))
  3181. (if (> i 0)
  3182. (setq line (concat (mapconcat 'identity
  3183. (make-list (* 2 i) "\\nbsp") "")
  3184. " " (org-trim line))))
  3185. (setq line (concat line "\\\\"))))
  3186. ;; make targets to anchors
  3187. (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
  3188. (cond
  3189. ((match-end 2)
  3190. (setq line (replace-match
  3191. (format
  3192. "@<a name=\"%s\" id=\"%s\">@</a>"
  3193. (org-solidify-link-text (match-string 1 line))
  3194. (org-solidify-link-text (match-string 1 line)))
  3195. t t line)))
  3196. ((and org-export-with-toc (equal (string-to-char line) ?*))
  3197. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  3198. (setq line (replace-match
  3199. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  3200. ; (concat "@<i>" (match-string 1 line) "@</i> ")
  3201. t t line)))
  3202. (t
  3203. (setq line (replace-match
  3204. (concat "@<a name=\""
  3205. (org-solidify-link-text (match-string 1 line))
  3206. "\" class=\"target\">" (match-string 1 line) "@</a> ")
  3207. t t line)))))
  3208. (setq line (org-html-handle-time-stamps line))
  3209. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  3210. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  3211. ;; Also handle sub_superscripts and checkboxes
  3212. (or (string-match org-table-hline-regexp line)
  3213. (setq line (org-html-expand line)))
  3214. ;; Format the links
  3215. (setq start 0)
  3216. (while (string-match org-bracket-link-analytic-regexp++ line start)
  3217. (setq start (match-beginning 0))
  3218. (setq path (save-match-data (org-link-unescape
  3219. (match-string 3 line))))
  3220. (setq type (cond
  3221. ((match-end 2) (match-string 2 line))
  3222. ((save-match-data
  3223. (or (file-name-absolute-p path)
  3224. (string-match "^\\.\\.?/" path)))
  3225. "file")
  3226. (t "internal")))
  3227. (setq path (org-extract-attributes (org-link-unescape path)))
  3228. (setq attr (get-text-property 0 'org-attributes path))
  3229. (setq desc1 (if (match-end 5) (match-string 5 line))
  3230. desc2 (if (match-end 2) (concat type ":" path) path)
  3231. descp (and desc1 (not (equal desc1 desc2)))
  3232. desc (or desc1 desc2))
  3233. ;; Make an image out of the description if that is so wanted
  3234. (when (and descp (org-file-image-p desc))
  3235. (save-match-data
  3236. (if (string-match "^file:" desc)
  3237. (setq desc (substring desc (match-end 0)))))
  3238. (setq desc (org-add-props
  3239. (concat "<img src=\"" desc "\"/>")
  3240. '(org-protected t))))
  3241. ;; FIXME: do we need to unescape here somewhere?
  3242. (cond
  3243. ((equal type "internal")
  3244. (setq rpl
  3245. (concat
  3246. "<a href=\"#"
  3247. (org-solidify-link-text
  3248. (save-match-data (org-link-unescape path)) nil)
  3249. "\"" attr ">"
  3250. (org-export-html-format-desc desc)
  3251. "</a>")))
  3252. ((member type '("http" "https"))
  3253. ;; standard URL, just check if we need to inline an image
  3254. (if (and (or (eq t org-export-html-inline-images)
  3255. (and org-export-html-inline-images (not descp)))
  3256. (org-file-image-p path))
  3257. (setq rpl (org-export-html-format-image
  3258. (concat type ":" path)))
  3259. (setq link (concat type ":" path))
  3260. (setq rpl (concat "<a href=\""
  3261. (org-export-html-format-href link)
  3262. "\"" attr ">"
  3263. (org-export-html-format-desc desc)
  3264. "</a>"))))
  3265. ((member type '("ftp" "mailto" "news"))
  3266. ;; standard URL
  3267. (setq link (concat type ":" path))
  3268. (setq rpl (concat "<a href=\""
  3269. (org-export-html-format-href link)
  3270. "\"" attr ">"
  3271. (org-export-html-format-desc desc)
  3272. "</a>")))
  3273. ((string= type "coderef")
  3274. (setq rpl (format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
  3275. path path path
  3276. (format (org-export-get-coderef-format path (and descp desc))
  3277. (cdr (assoc path org-export-code-refs))))))
  3278. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  3279. ;; The link protocol has a function for format the link
  3280. (setq rpl
  3281. (save-match-data
  3282. (funcall fnc (org-link-unescape path) desc1 'html))))
  3283. ((string= type "file")
  3284. ;; FILE link
  3285. (let* ((filename path)
  3286. (abs-p (file-name-absolute-p filename))
  3287. thefile file-is-image-p search)
  3288. (save-match-data
  3289. (if (string-match "::\\(.*\\)" filename)
  3290. (setq search (match-string 1 filename)
  3291. filename (replace-match "" t nil filename)))
  3292. (setq valid
  3293. (if (functionp link-validate)
  3294. (funcall link-validate filename current-dir)
  3295. t))
  3296. (setq file-is-image-p (org-file-image-p filename))
  3297. (setq thefile (if abs-p (expand-file-name filename) filename))
  3298. (when (and org-export-html-link-org-files-as-html
  3299. (string-match "\\.org$" thefile))
  3300. (setq thefile (concat (substring thefile 0
  3301. (match-beginning 0))
  3302. "." html-extension))
  3303. (if (and search
  3304. ;; make sure this is can be used as target search
  3305. (not (string-match "^[0-9]*$" search))
  3306. (not (string-match "^\\*" search))
  3307. (not (string-match "^/.*/$" search)))
  3308. (setq thefile (concat thefile "#"
  3309. (org-solidify-link-text
  3310. (org-link-unescape search)))))
  3311. (when (string-match "^file:" desc)
  3312. (setq desc (replace-match "" t t desc))
  3313. (if (string-match "\\.org$" desc)
  3314. (setq desc (replace-match "" t t desc))))))
  3315. (setq rpl (if (and file-is-image-p
  3316. (or (eq t org-export-html-inline-images)
  3317. (and org-export-html-inline-images
  3318. (not descp))))
  3319. (org-export-html-format-image thefile)
  3320. (concat "<a href=\"" thefile "\"" attr ">"
  3321. (org-export-html-format-desc desc)
  3322. "</a>")))
  3323. (if (not valid) (setq rpl desc))))
  3324. (t
  3325. ;; just publish the path, as default
  3326. (setq rpl (concat "<i>&lt;" type ":"
  3327. (save-match-data (org-link-unescape path))
  3328. "&gt;</i>"))))
  3329. (setq line (replace-match rpl t t line)
  3330. start (+ start (length rpl))))
  3331. ;; TODO items
  3332. (if (and (string-match org-todo-line-regexp line)
  3333. (match-beginning 2))
  3334. (setq line
  3335. (concat (substring line 0 (match-beginning 2))
  3336. "<span class=\""
  3337. (if (member (match-string 2 line)
  3338. org-done-keywords)
  3339. "done" "todo")
  3340. "\">" (match-string 2 line)
  3341. "</span>" (substring line (match-end 2)))))
  3342. ;; Does this contain a reference to a footnote?
  3343. (when org-export-with-footnotes
  3344. (setq start 0)
  3345. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  3346. (if (get-text-property (match-beginning 2) 'org-protected line)
  3347. (setq start (match-end 2))
  3348. (let ((n (match-string 2 line)) extra a)
  3349. (if (setq a (assoc n footref-seen))
  3350. (progn
  3351. (setcdr a (1+ (cdr a)))
  3352. (setq extra (format ".%d" (cdr a))))
  3353. (setq extra "")
  3354. (push (cons n 1) footref-seen))
  3355. (setq line
  3356. (replace-match
  3357. (format
  3358. "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
  3359. (match-string 1 line) n extra n n)
  3360. t t line))))))
  3361. (cond
  3362. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  3363. ;; This is a headline
  3364. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  3365. txt (match-string 2 line))
  3366. (if (string-match quote-re0 txt)
  3367. (setq txt (replace-match "" t t txt)))
  3368. (if (<= level (max umax umax-toc))
  3369. (setq head-count (+ head-count 1)))
  3370. (when in-local-list
  3371. ;; Close any local lists before inserting a new header line
  3372. (while local-list-type
  3373. (org-close-li (car local-list-type))
  3374. (insert (format "</%sl>\n" (car local-list-type)))
  3375. (pop local-list-type))
  3376. (setq local-list-indent nil
  3377. in-local-list nil))
  3378. (setq first-heading-pos (or first-heading-pos (point)))
  3379. (org-html-level-start level txt umax
  3380. (and org-export-with-toc (<= level umax))
  3381. head-count)
  3382. ;; QUOTES
  3383. (when (string-match quote-re line)
  3384. (org-close-par-maybe)
  3385. (insert "<pre>")
  3386. (setq inquote t)))
  3387. ((and org-export-with-tables
  3388. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  3389. (if (not table-open)
  3390. ;; New table starts
  3391. (setq table-open t table-buffer nil table-orig-buffer nil))
  3392. ;; Accumulate lines
  3393. (setq table-buffer (cons line table-buffer)
  3394. table-orig-buffer (cons origline table-orig-buffer))
  3395. (when (or (not lines)
  3396. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  3397. (car lines))))
  3398. (setq table-open nil
  3399. table-buffer (nreverse table-buffer)
  3400. table-orig-buffer (nreverse table-orig-buffer))
  3401. (org-close-par-maybe)
  3402. (insert (org-format-table-html table-buffer table-orig-buffer))))
  3403. (t
  3404. ;; Normal lines
  3405. (when (string-match
  3406. (cond
  3407. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  3408. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  3409. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  3410. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  3411. line)
  3412. (setq ind (org-get-string-indentation line)
  3413. item-type (if (match-beginning 4) "o" "u")
  3414. starter (if (match-beginning 2)
  3415. (substring (match-string 2 line) 0 -1))
  3416. line (substring line (match-beginning 5))
  3417. item-tag nil)
  3418. (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
  3419. (setq item-type "d"
  3420. item-tag (match-string 1 line)
  3421. line (substring line (match-end 0))))
  3422. (when (and (not (equal item-type "d"))
  3423. (not (string-match "[^ \t]" line)))
  3424. ;; empty line. Pretend indentation is large.
  3425. (setq ind (if org-empty-line-terminates-plain-lists
  3426. 0
  3427. (1+ (or (car local-list-indent) 1)))))
  3428. (setq didclose nil)
  3429. (while (and in-local-list
  3430. (or (and (= ind (car local-list-indent))
  3431. (not starter))
  3432. (< ind (car local-list-indent))))
  3433. (setq didclose t)
  3434. (org-close-li (car local-list-type))
  3435. (insert (format "</%sl>\n" (car local-list-type)))
  3436. (pop local-list-type) (pop local-list-indent)
  3437. (setq in-local-list local-list-indent))
  3438. (cond
  3439. ((and starter
  3440. (or (not in-local-list)
  3441. (> ind (car local-list-indent))))
  3442. ;; Start new (level of) list
  3443. (org-close-par-maybe)
  3444. (insert (cond
  3445. ((equal item-type "u") "<ul>\n<li>\n")
  3446. ((equal item-type "o") "<ol>\n<li>\n")
  3447. ((equal item-type "d")
  3448. (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
  3449. (push item-type local-list-type)
  3450. (push ind local-list-indent)
  3451. (setq in-local-list t))
  3452. (starter
  3453. ;; continue current list
  3454. (org-close-li (car local-list-type))
  3455. (insert (cond
  3456. ((equal (car local-list-type) "d")
  3457. (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
  3458. (t "<li>\n"))))
  3459. (didclose
  3460. ;; we did close a list, normal text follows: need <p>
  3461. (org-open-par)))
  3462. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  3463. (setq line
  3464. (replace-match
  3465. (if (equal (match-string 1 line) "X")
  3466. "<b>[X]</b>"
  3467. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  3468. t t line))))
  3469. ;; Empty lines start a new paragraph. If hand-formatted lists
  3470. ;; are not fully interpreted, lines starting with "-", "+", "*"
  3471. ;; also start a new paragraph.
  3472. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  3473. ;; Is this the start of a footnote?
  3474. (when org-export-with-footnotes
  3475. (when (and (boundp 'footnote-section-tag-regexp)
  3476. (string-match (concat "^" footnote-section-tag-regexp)
  3477. line))
  3478. ;; ignore this line
  3479. (throw 'nextline nil))
  3480. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  3481. (org-close-par-maybe)
  3482. (let ((n (match-string 1 line)))
  3483. (setq org-par-open t
  3484. line (replace-match
  3485. (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
  3486. ;; Check if the line break needs to be conserved
  3487. (cond
  3488. ((string-match "\\\\\\\\[ \t]*$" line)
  3489. (setq line (replace-match "<br/>" t t line)))
  3490. (org-export-preserve-breaks
  3491. (setq line (concat line "<br/>"))))
  3492. (insert line "\n")))))
  3493. ;; Properly close all local lists and other lists
  3494. (when inquote
  3495. (insert "</pre>\n")
  3496. (org-open-par))
  3497. (when in-local-list
  3498. ;; Close any local lists before inserting a new header line
  3499. (while local-list-type
  3500. (org-close-li (car local-list-type))
  3501. (insert (format "</%sl>\n" (car local-list-type)))
  3502. (pop local-list-type))
  3503. (setq local-list-indent nil
  3504. in-local-list nil))
  3505. (org-html-level-start 1 nil umax
  3506. (and org-export-with-toc (<= level umax))
  3507. head-count)
  3508. ;; the </div> to close the last text-... div.
  3509. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  3510. (save-excursion
  3511. (goto-char (point-min))
  3512. (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
  3513. (push (match-string 0) footnotes)
  3514. (replace-match "" t t)))
  3515. (when footnotes
  3516. (insert (format org-export-html-footnotes-section
  3517. (or (nth 4 lang-words) "Footnotes")
  3518. (mapconcat 'identity (nreverse footnotes) "\n"))
  3519. "\n"))
  3520. (unless body-only
  3521. (when (plist-get opt-plist :auto-postamble)
  3522. (insert "<div id=\"postamble\">")
  3523. (when (and org-export-author-info author)
  3524. (insert "<p class=\"author\"> "
  3525. (nth 1 lang-words) ": " author "\n")
  3526. (when email
  3527. (if (listp (split-string email ",+ *"))
  3528. (mapc (lambda(e)
  3529. (insert "<a href=\"mailto:" e "\">&lt;"
  3530. e "&gt;</a>\n"))
  3531. (split-string email ",+ *"))
  3532. (insert "<a href=\"mailto:" email "\">&lt;"
  3533. email "&gt;</a>\n")))
  3534. (insert "</p>\n"))
  3535. (when (and date org-export-time-stamp-file)
  3536. (insert "<p class=\"date\"> "
  3537. (nth 2 lang-words) ": "
  3538. date "</p>\n"))
  3539. (when org-export-creator-info
  3540. (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
  3541. org-version emacs-major-version)))
  3542. (insert "</div>"))
  3543. (if org-export-html-with-timestamp
  3544. (insert org-export-html-html-helper-timestamp))
  3545. (insert (or (plist-get opt-plist :postamble) ""))
  3546. (insert "</body>\n</html>\n"))
  3547. (unless (plist-get opt-plist :buffer-will-be-killed)
  3548. (normal-mode)
  3549. (if (eq major-mode default-major-mode) (html-mode)))
  3550. ;; insert the table of contents
  3551. (goto-char (point-min))
  3552. (when thetoc
  3553. (if (or (re-search-forward
  3554. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  3555. (re-search-forward
  3556. "\\[TABLE-OF-CONTENTS\\]" nil t))
  3557. (progn
  3558. (goto-char (match-beginning 0))
  3559. (replace-match ""))
  3560. (goto-char first-heading-pos)
  3561. (when (looking-at "\\s-*</p>")
  3562. (goto-char (match-end 0))
  3563. (insert "\n")))
  3564. (insert "<div id=\"table-of-contents\">\n")
  3565. (mapc 'insert thetoc)
  3566. (insert "</div>\n"))
  3567. ;; remove empty paragraphs and lists
  3568. (goto-char (point-min))
  3569. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  3570. (replace-match ""))
  3571. (goto-char (point-min))
  3572. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  3573. (replace-match ""))
  3574. (goto-char (point-min))
  3575. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  3576. (replace-match ""))
  3577. ;; Convert whitespace place holders
  3578. (goto-char (point-min))
  3579. (let (beg end n)
  3580. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  3581. (setq n (get-text-property beg 'org-whitespace)
  3582. end (next-single-property-change beg 'org-whitespace))
  3583. (goto-char beg)
  3584. (delete-region beg end)
  3585. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  3586. (make-string n ?x)))))
  3587. (or to-buffer (save-buffer))
  3588. (goto-char (point-min))
  3589. (message "Exporting... done")
  3590. (if (eq to-buffer 'string)
  3591. (prog1 (buffer-substring (point-min) (point-max))
  3592. (kill-buffer (current-buffer)))
  3593. (current-buffer)))))
  3594. (defun org-export-get-coderef-format (path desc)
  3595. (save-match-data
  3596. (if (and desc (string-match
  3597. (regexp-quote (concat "(" path ")"))
  3598. desc))
  3599. (replace-match "%s" t t desc)
  3600. "%s")))
  3601. (defun org-export-html-format-href (s)
  3602. "Make sure the S is valid as a href reference in an XHTML document."
  3603. (save-match-data
  3604. (let ((start 0))
  3605. (while (string-match "&" s start)
  3606. (setq start (+ (match-beginning 0) 3)
  3607. s (replace-match "&amp;" t t s)))))
  3608. s)
  3609. (defun org-export-html-format-desc (s)
  3610. "Make sure the S is valid as a description in a link."
  3611. (if (and s (not (get-text-property 1 'org-protected s)))
  3612. (save-match-data
  3613. (org-html-do-expand s))
  3614. s))
  3615. (defun org-export-html-format-image (src)
  3616. "Create image tag with source and attributes."
  3617. (save-match-data
  3618. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  3619. (attr (org-find-text-property-in-string 'org-attributes src))
  3620. (label (org-find-text-property-in-string 'org-label src)))
  3621. (format "<div %sclass=\"figure\">
  3622. <p><img src=\"%s\"%s /></p>%s
  3623. </div>"
  3624. (if label (format "id=\"%s\" " label) "")
  3625. src
  3626. (if (string-match "\\<alt=" (or attr ""))
  3627. (concat " " attr )
  3628. (concat " " attr " alt=\"" src "\""))
  3629. (if caption (concat "\n<p>" caption "</p>") "")))))
  3630. (defvar org-table-colgroup-info nil)
  3631. (defun org-format-table-ascii (lines)
  3632. "Format a table for ascii export."
  3633. (if (stringp lines)
  3634. (setq lines (org-split-string lines "\n")))
  3635. (if (not (string-match "^[ \t]*|" (car lines)))
  3636. ;; Table made by table.el - test for spanning
  3637. lines
  3638. ;; A normal org table
  3639. ;; Get rid of hlines at beginning and end
  3640. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3641. (setq lines (nreverse lines))
  3642. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3643. (setq lines (nreverse lines))
  3644. (when org-export-table-remove-special-lines
  3645. ;; Check if the table has a marking column. If yes remove the
  3646. ;; column and the special lines
  3647. (setq lines (org-table-clean-before-export lines)))
  3648. ;; Get rid of the vertical lines except for grouping
  3649. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  3650. rtn line vl1 start)
  3651. (while (setq line (pop lines))
  3652. (if (string-match org-table-hline-regexp line)
  3653. (and (string-match "|\\(.*\\)|" line)
  3654. (setq line (replace-match " \\1" t nil line)))
  3655. (setq start 0 vl1 vl)
  3656. (while (string-match "|" line start)
  3657. (setq start (match-end 0))
  3658. (or (pop vl1) (setq line (replace-match " " t t line)))))
  3659. (push line rtn))
  3660. (nreverse rtn))))
  3661. (defun org-colgroup-info-to-vline-list (info)
  3662. (let (vl new last)
  3663. (while info
  3664. (setq last new new (pop info))
  3665. (if (or (memq last '(:end :startend))
  3666. (memq new '(:start :startend)))
  3667. (push t vl)
  3668. (push nil vl)))
  3669. (setq vl (nreverse vl))
  3670. (and vl (setcar vl nil))
  3671. vl))
  3672. (defvar org-table-number-regexp) ; defined in org-table.el
  3673. (defun org-format-table-html (lines olines)
  3674. "Find out which HTML converter to use and return the HTML code."
  3675. (if (stringp lines)
  3676. (setq lines (org-split-string lines "\n")))
  3677. (if (string-match "^[ \t]*|" (car lines))
  3678. ;; A normal org table
  3679. (org-format-org-table-html lines)
  3680. ;; Table made by table.el - test for spanning
  3681. (let* ((hlines (delq nil (mapcar
  3682. (lambda (x)
  3683. (if (string-match "^[ \t]*\\+-" x) x
  3684. nil))
  3685. lines)))
  3686. (first (car hlines))
  3687. (ll (and (string-match "\\S-+" first)
  3688. (match-string 0 first)))
  3689. (re (concat "^[ \t]*" (regexp-quote ll)))
  3690. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  3691. hlines))))
  3692. (if (and (not spanning)
  3693. (not org-export-prefer-native-exporter-for-tables))
  3694. ;; We can use my own converter with HTML conversions
  3695. (org-format-table-table-html lines)
  3696. ;; Need to use the code generator in table.el, with the original text.
  3697. (org-format-table-table-html-using-table-generate-source olines)))))
  3698. (defvar org-table-number-fraction) ; defined in org-table.el
  3699. (defun org-format-org-table-html (lines &optional splice)
  3700. "Format a table into HTML."
  3701. (require 'org-table)
  3702. ;; Get rid of hlines at beginning and end
  3703. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3704. (setq lines (nreverse lines))
  3705. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  3706. (setq lines (nreverse lines))
  3707. (when org-export-table-remove-special-lines
  3708. ;; Check if the table has a marking column. If yes remove the
  3709. ;; column and the special lines
  3710. (setq lines (org-table-clean-before-export lines)))
  3711. (let ((caption (or (get-text-property 0 'org-caption (car lines))
  3712. (get-text-property (or (next-single-property-change
  3713. 0 'org-caption (car lines))
  3714. 0)
  3715. 'org-caption (car lines))))
  3716. (head (and org-export-highlight-first-table-line
  3717. (delq nil (mapcar
  3718. (lambda (x) (string-match "^[ \t]*|-" x))
  3719. (cdr lines)))))
  3720. (nlines 0) fnum i
  3721. tbopen line fields html gr colgropen)
  3722. (if splice (setq head nil))
  3723. (unless splice (push (if head "<thead>" "<tbody>") html))
  3724. (setq tbopen t)
  3725. (while (setq line (pop lines))
  3726. (catch 'next-line
  3727. (if (string-match "^[ \t]*|-" line)
  3728. (progn
  3729. (unless splice
  3730. (push (if head "</thead>" "</tbody>") html)
  3731. (if lines (push "<tbody>" html) (setq tbopen nil)))
  3732. (setq head nil) ;; head ends here, first time around
  3733. ;; ignore this line
  3734. (throw 'next-line t)))
  3735. ;; Break the line into fields
  3736. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  3737. (unless fnum (setq fnum (make-vector (length fields) 0)))
  3738. (setq nlines (1+ nlines) i -1)
  3739. (push (concat "<tr>"
  3740. (mapconcat
  3741. (lambda (x)
  3742. (setq i (1+ i))
  3743. (if (and (< i nlines)
  3744. (string-match org-table-number-regexp x))
  3745. (incf (aref fnum i)))
  3746. (if head
  3747. (concat (car org-export-table-header-tags) x
  3748. (cdr org-export-table-header-tags))
  3749. (concat (car org-export-table-data-tags) x
  3750. (cdr org-export-table-data-tags))))
  3751. fields "")
  3752. "</tr>")
  3753. html)))
  3754. (unless splice (if tbopen (push "</tbody>" html)))
  3755. (unless splice (push "</table>\n" html))
  3756. (setq html (nreverse html))
  3757. (unless splice
  3758. ;; Put in col tags with the alignment (unfortunately often ignored...)
  3759. (push (mapconcat
  3760. (lambda (x)
  3761. (setq gr (pop org-table-colgroup-info))
  3762. (format "%s<col align=\"%s\"></col>%s"
  3763. (if (memq gr '(:start :startend))
  3764. (prog1
  3765. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  3766. (setq colgropen t))
  3767. "")
  3768. (if (> (/ (float x) nlines) org-table-number-fraction)
  3769. "right" "left")
  3770. (if (memq gr '(:end :startend))
  3771. (progn (setq colgropen nil) "</colgroup>")
  3772. "")))
  3773. fnum "")
  3774. html)
  3775. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  3776. (if caption (push (format "<caption>%s</caption>" caption) html))
  3777. (push html-table-tag html))
  3778. (concat (mapconcat 'identity html "\n") "\n")))
  3779. (defun org-table-clean-before-export (lines)
  3780. "Check if the table has a marking column.
  3781. If yes remove the column and the special lines."
  3782. (setq org-table-colgroup-info nil)
  3783. (if (memq nil
  3784. (mapcar
  3785. (lambda (x) (or (string-match "^[ \t]*|-" x)
  3786. (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
  3787. lines))
  3788. (progn
  3789. (setq org-table-clean-did-remove-column nil)
  3790. (delq nil
  3791. (mapcar
  3792. (lambda (x)
  3793. (cond
  3794. ((string-match "^[ \t]*| */ *|" x)
  3795. (setq org-table-colgroup-info
  3796. (mapcar (lambda (x)
  3797. (cond ((member x '("<" "&lt;")) :start)
  3798. ((member x '(">" "&gt;")) :end)
  3799. ((member x '("<>" "&lt;&gt;")) :startend)
  3800. (t nil)))
  3801. (org-split-string x "[ \t]*|[ \t]*")))
  3802. nil)
  3803. (t x)))
  3804. lines)))
  3805. (setq org-table-clean-did-remove-column t)
  3806. (delq nil
  3807. (mapcar
  3808. (lambda (x)
  3809. (cond
  3810. ((string-match "^[ \t]*| */ *|" x)
  3811. (setq org-table-colgroup-info
  3812. (mapcar (lambda (x)
  3813. (cond ((member x '("<" "&lt;")) :start)
  3814. ((member x '(">" "&gt;")) :end)
  3815. ((member x '("<>" "&lt;&gt;")) :startend)
  3816. (t nil)))
  3817. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  3818. nil)
  3819. ((string-match "^[ \t]*| *[!_^/] *|" x)
  3820. nil) ; ignore this line
  3821. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  3822. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  3823. ;; remove the first column
  3824. (replace-match "\\1|" t nil x))))
  3825. lines))))
  3826. (defun org-format-table-table-html (lines)
  3827. "Format a table generated by table.el into HTML.
  3828. This conversion does *not* use `table-generate-source' from table.el.
  3829. This has the advantage that Org-mode's HTML conversions can be used.
  3830. But it has the disadvantage, that no cell- or row-spanning is allowed."
  3831. (let (line field-buffer
  3832. (head org-export-highlight-first-table-line)
  3833. fields html empty)
  3834. (setq html (concat html-table-tag "\n"))
  3835. (while (setq line (pop lines))
  3836. (setq empty "&nbsp;")
  3837. (catch 'next-line
  3838. (if (string-match "^[ \t]*\\+-" line)
  3839. (progn
  3840. (if field-buffer
  3841. (progn
  3842. (setq
  3843. html
  3844. (concat
  3845. html
  3846. "<tr>"
  3847. (mapconcat
  3848. (lambda (x)
  3849. (if (equal x "") (setq x empty))
  3850. (if head
  3851. (concat (car org-export-table-header-tags) x
  3852. (cdr org-export-table-header-tags))
  3853. (concat (car org-export-table-data-tags) x
  3854. (cdr org-export-table-data-tags))))
  3855. field-buffer "\n")
  3856. "</tr>\n"))
  3857. (setq head nil)
  3858. (setq field-buffer nil)))
  3859. ;; Ignore this line
  3860. (throw 'next-line t)))
  3861. ;; Break the line into fields and store the fields
  3862. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  3863. (if field-buffer
  3864. (setq field-buffer (mapcar
  3865. (lambda (x)
  3866. (concat x "<br/>" (pop fields)))
  3867. field-buffer))
  3868. (setq field-buffer fields))))
  3869. (setq html (concat html "</table>\n"))
  3870. html))
  3871. (defun org-format-table-table-html-using-table-generate-source (lines)
  3872. "Format a table into html, using `table-generate-source' from table.el.
  3873. This has the advantage that cell- or row-spanning is allowed.
  3874. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  3875. (require 'table)
  3876. (with-current-buffer (get-buffer-create " org-tmp1 ")
  3877. (erase-buffer)
  3878. (insert (mapconcat 'identity lines "\n"))
  3879. (goto-char (point-min))
  3880. (if (not (re-search-forward "|[^+]" nil t))
  3881. (error "Error processing table"))
  3882. (table-recognize-table)
  3883. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  3884. (table-generate-source 'html " org-tmp2 ")
  3885. (set-buffer " org-tmp2 ")
  3886. (buffer-substring (point-min) (point-max))))
  3887. (defun org-export-splice-style (style extra)
  3888. "Splice EXTRA into STYLE, just before \"</style>\"."
  3889. (if (and (stringp extra)
  3890. (string-match "\\S-" extra)
  3891. (string-match "</style>" style))
  3892. (concat (substring style 0 (match-beginning 0))
  3893. "\n" extra "\n"
  3894. (substring style (match-beginning 0)))
  3895. style))
  3896. (defun org-html-handle-time-stamps (s)
  3897. "Format time stamps in string S, or remove them."
  3898. (catch 'exit
  3899. (let (r b)
  3900. (while (string-match org-maybe-keyword-time-regexp s)
  3901. (or b (setq b (substring s 0 (match-beginning 0))))
  3902. (setq r (concat
  3903. r (substring s 0 (match-beginning 0))
  3904. (if (match-end 1)
  3905. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  3906. (match-string 1 s)))
  3907. (format " @<span class=\"timestamp\">%s@</span>"
  3908. (substring
  3909. (org-translate-time (match-string 3 s)) 1 -1)))
  3910. s (substring s (match-end 0))))
  3911. ;; Line break if line started and ended with time stamp stuff
  3912. (if (not r)
  3913. s
  3914. (setq r (concat r s))
  3915. (unless (string-match "\\S-" (concat b s))
  3916. (setq r (concat r "@<br/>")))
  3917. r))))
  3918. (defun org-export-htmlize-region-for-paste (beg end)
  3919. "Convert the region to HTML, using htmlize.el.
  3920. This is much like `htmlize-region-for-paste', only that it uses
  3921. the settings define in the org-... variables."
  3922. (let* ((htmlize-output-type org-export-htmlize-output-type)
  3923. (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
  3924. (htmlbuf (htmlize-region beg end)))
  3925. (unwind-protect
  3926. (with-current-buffer htmlbuf
  3927. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  3928. (plist-get htmlize-buffer-places 'content-end)))
  3929. (kill-buffer htmlbuf))))
  3930. ;;;###autoload
  3931. (defun org-export-htmlize-generate-css ()
  3932. "Create the CSS for all font definitions in the current Emacs session.
  3933. Use this to create face definitions in your CSS style file that can then
  3934. be used by code snippets transformed by htmlize.
  3935. This command just produces a buffer that contains class definitions for all
  3936. faces used in the current Emacs session. You can copy and paste the ones you
  3937. need into your CSS file.
  3938. If you then set `org-export-htmlize-output-type' to `css', calls to
  3939. the function `org-export-htmlize-region-for-paste' will produce code
  3940. that uses these same face definitions."
  3941. (interactive)
  3942. (require 'htmlize)
  3943. (and (get-buffer "*html*") (kill-buffer "*html*"))
  3944. (with-temp-buffer
  3945. (let ((fl (face-list))
  3946. (htmlize-css-name-prefix "org-")
  3947. (htmlize-output-type 'css)
  3948. f i)
  3949. (while (setq f (pop fl)
  3950. i (and f (face-attribute f :inherit)))
  3951. (when (and (symbolp f) (or (not i) (not (listp i))))
  3952. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  3953. (htmlize-region (point-min) (point-max))))
  3954. (switch-to-buffer "*html*")
  3955. (goto-char (point-min))
  3956. (if (re-search-forward "<style" nil t)
  3957. (delete-region (point-min) (match-beginning 0)))
  3958. (if (re-search-forward "</style>" nil t)
  3959. (delete-region (1+ (match-end 0)) (point-max)))
  3960. (beginning-of-line 1)
  3961. (if (looking-at " +") (replace-match ""))
  3962. (goto-char (point-min)))
  3963. (defun org-html-protect (s)
  3964. ;; convert & to &amp;, < to &lt; and > to &gt;
  3965. (let ((start 0))
  3966. (while (string-match "&" s start)
  3967. (setq s (replace-match "&amp;" t t s)
  3968. start (1+ (match-beginning 0))))
  3969. (while (string-match "<" s)
  3970. (setq s (replace-match "&lt;" t t s)))
  3971. (while (string-match ">" s)
  3972. (setq s (replace-match "&gt;" t t s)))
  3973. ; (while (string-match "\"" s)
  3974. ; (setq s (replace-match "&quot;" t t s)))
  3975. )
  3976. s)
  3977. (defun org-export-cleanup-toc-line (s)
  3978. "Remove tags and timestamps from lines going into the toc."
  3979. (when (memq org-export-with-tags '(not-in-toc nil))
  3980. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  3981. (setq s (replace-match "" t t s))))
  3982. (when org-export-remove-timestamps-from-toc
  3983. (while (string-match org-maybe-keyword-time-regexp s)
  3984. (setq s (replace-match "" t t s))))
  3985. (while (string-match org-bracket-link-regexp s)
  3986. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  3987. t t s)))
  3988. s)
  3989. (defun org-html-expand (string)
  3990. "Prepare STRING for HTML export. Applies all active conversions.
  3991. If there are links in the string, don't modify these."
  3992. (let* ((re (concat org-bracket-link-regexp "\\|"
  3993. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  3994. m s l res)
  3995. (while (setq m (string-match re string))
  3996. (setq s (substring string 0 m)
  3997. l (match-string 0 string)
  3998. string (substring string (match-end 0)))
  3999. (push (org-html-do-expand s) res)
  4000. (push l res))
  4001. (push (org-html-do-expand string) res)
  4002. (apply 'concat (nreverse res))))
  4003. (defun org-html-do-expand (s)
  4004. "Apply all active conversions to translate special ASCII to HTML."
  4005. (setq s (org-html-protect s))
  4006. (if org-export-html-expand
  4007. (let ((start 0))
  4008. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  4009. (setq s (replace-match "<\\1>" t nil s)))))
  4010. (if org-export-with-emphasize
  4011. (setq s (org-export-html-convert-emphasize s)))
  4012. (if org-export-with-special-strings
  4013. (setq s (org-export-html-convert-special-strings s)))
  4014. (if org-export-with-sub-superscripts
  4015. (setq s (org-export-html-convert-sub-super s)))
  4016. (if org-export-with-TeX-macros
  4017. (let ((start 0) wd ass)
  4018. (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
  4019. s start))
  4020. (if (get-text-property (match-beginning 0) 'org-protected s)
  4021. (setq start (match-end 0))
  4022. (setq wd (match-string 1 s))
  4023. (if (setq ass (assoc wd org-html-entities))
  4024. (setq s (replace-match (or (cdr ass)
  4025. (concat "&" (car ass) ";"))
  4026. t t s))
  4027. (setq start (+ start (length wd))))))))
  4028. s)
  4029. (defun org-create-multibrace-regexp (left right n)
  4030. "Create a regular expression which will match a balanced sexp.
  4031. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  4032. as single character strings.
  4033. The regexp returned will match the entire expression including the
  4034. delimiters. It will also define a single group which contains the
  4035. match except for the outermost delimiters. The maximum depth of
  4036. stacked delimiters is N. Escaping delimiters is not possible."
  4037. (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
  4038. (or "\\|")
  4039. (re nothing)
  4040. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  4041. (while (> n 1)
  4042. (setq n (1- n)
  4043. re (concat re or next)
  4044. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  4045. (concat left "\\(" re "\\)" right)))
  4046. (defvar org-match-substring-regexp
  4047. (concat
  4048. "\\([^\\]\\)\\([_^]\\)\\("
  4049. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  4050. "\\|"
  4051. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  4052. "\\|"
  4053. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  4054. "The regular expression matching a sub- or superscript.")
  4055. (defvar org-match-substring-with-braces-regexp
  4056. (concat
  4057. "\\([^\\]\\)\\([_^]\\)\\("
  4058. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  4059. "\\)")
  4060. "The regular expression matching a sub- or superscript, forcing braces.")
  4061. (defconst org-export-html-special-string-regexps
  4062. '(("\\\\-" . "&shy;")
  4063. ("---\\([^-]\\)" . "&mdash;\\1")
  4064. ("--\\([^-]\\)" . "&ndash;\\1")
  4065. ("\\.\\.\\." . "&hellip;"))
  4066. "Regular expressions for special string conversion.")
  4067. (defun org-export-html-convert-special-strings (string)
  4068. "Convert special characters in STRING to HTML."
  4069. (let ((all org-export-html-special-string-regexps)
  4070. e a re rpl start)
  4071. (while (setq a (pop all))
  4072. (setq re (car a) rpl (cdr a) start 0)
  4073. (while (string-match re string start)
  4074. (if (get-text-property (match-beginning 0) 'org-protected string)
  4075. (setq start (match-end 0))
  4076. (setq string (replace-match rpl t nil string)))))
  4077. string))
  4078. (defun org-export-html-convert-sub-super (string)
  4079. "Convert sub- and superscripts in STRING to HTML."
  4080. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  4081. (while (string-match org-match-substring-regexp string s)
  4082. (cond
  4083. ((and requireb (match-end 8)) (setq s (match-end 2)))
  4084. ((get-text-property (match-beginning 2) 'org-protected string)
  4085. (setq s (match-end 2)))
  4086. (t
  4087. (setq s (match-end 1)
  4088. key (if (string= (match-string 2 string) "_") "sub" "sup")
  4089. c (or (match-string 8 string)
  4090. (match-string 6 string)
  4091. (match-string 5 string))
  4092. string (replace-match
  4093. (concat (match-string 1 string)
  4094. "<" key ">" c "</" key ">")
  4095. t t string)))))
  4096. (while (string-match "\\\\\\([_^]\\)" string)
  4097. (setq string (replace-match (match-string 1 string) t t string)))
  4098. string))
  4099. (defun org-export-html-convert-emphasize (string)
  4100. "Apply emphasis."
  4101. (let ((s 0) rpl)
  4102. (while (string-match org-emph-re string s)
  4103. (if (not (equal
  4104. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  4105. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  4106. (setq s (match-beginning 0)
  4107. rpl
  4108. (concat
  4109. (match-string 1 string)
  4110. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  4111. (match-string 4 string)
  4112. (nth 3 (assoc (match-string 3 string)
  4113. org-emphasis-alist))
  4114. (match-string 5 string))
  4115. string (replace-match rpl t t string)
  4116. s (+ s (- (length rpl) 2)))
  4117. (setq s (1+ s))))
  4118. string))
  4119. (defun org-open-par ()
  4120. "Insert <p>, but first close previous paragraph if any."
  4121. (org-close-par-maybe)
  4122. (insert "\n<p>")
  4123. (setq org-par-open t))
  4124. (defun org-close-par-maybe ()
  4125. "Close paragraph if there is one open."
  4126. (when org-par-open
  4127. (insert "</p>")
  4128. (setq org-par-open nil)))
  4129. (defun org-close-li (&optional type)
  4130. "Close <li> if necessary."
  4131. (org-close-par-maybe)
  4132. (insert (if (equal type "d") "</dd>\n" "</li>\n")))
  4133. (defvar body-only) ; dynamically scoped into this.
  4134. (defun org-html-level-start (level title umax with-toc head-count)
  4135. "Insert a new level in HTML export.
  4136. When TITLE is nil, just close all open levels."
  4137. (org-close-par-maybe)
  4138. (let* ((target (and title (org-get-text-property-any 0 'target title)))
  4139. (extra-targets
  4140. (mapconcat (lambda (x)
  4141. (format "<a name=\"%s\" id=\"%s\"></a>"
  4142. x x))
  4143. (cdr (assoc target org-export-target-aliases))
  4144. ""))
  4145. (l org-level-max)
  4146. snumber)
  4147. (while (>= l level)
  4148. (if (aref org-levels-open (1- l))
  4149. (progn
  4150. (org-html-level-close l umax)
  4151. (aset org-levels-open (1- l) nil)))
  4152. (setq l (1- l)))
  4153. (when title
  4154. ;; If title is nil, this means this function is called to close
  4155. ;; all levels, so the rest is done only if title is given
  4156. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  4157. (setq title (replace-match
  4158. (if org-export-with-tags
  4159. (save-match-data
  4160. (concat
  4161. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  4162. (mapconcat 'identity (org-split-string
  4163. (match-string 1 title) ":")
  4164. "&nbsp;")
  4165. "</span>"))
  4166. "")
  4167. t t title)))
  4168. (if (> level umax)
  4169. (progn
  4170. (if (aref org-levels-open (1- level))
  4171. (progn
  4172. (org-close-li)
  4173. (if target
  4174. (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
  4175. (insert "<li>" title "<br/>\n")))
  4176. (aset org-levels-open (1- level) t)
  4177. (org-close-par-maybe)
  4178. (if target
  4179. (insert (format "<ul>\n<li id=\"%s\">" target)
  4180. extra-targets title "<br/>\n")
  4181. (insert "<ul>\n<li>" title "<br/>\n"))))
  4182. (aset org-levels-open (1- level) t)
  4183. (setq snumber (org-section-number level))
  4184. (if (and org-export-with-section-numbers (not body-only))
  4185. (setq title (concat snumber " " title)))
  4186. (setq level (+ level org-export-html-toplevel-hlevel -1))
  4187. (unless (= head-count 1) (insert "\n</div>\n"))
  4188. (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"
  4189. snumber level level snumber extra-targets title level snumber))
  4190. (org-open-par)))))
  4191. (defun org-get-text-property-any (pos prop &optional object)
  4192. (or (get-text-property pos prop object)
  4193. (and (setq pos (next-single-property-change pos prop object))
  4194. (get-text-property pos prop object))))
  4195. (defun org-html-level-close (level max-outline-level)
  4196. "Terminate one level in HTML export."
  4197. (if (<= level max-outline-level)
  4198. (insert "</div>\n")
  4199. (org-close-li)
  4200. (insert "</ul>\n")))
  4201. ;;; iCalendar export
  4202. ;;;###autoload
  4203. (defun org-export-icalendar-this-file ()
  4204. "Export current file as an iCalendar file.
  4205. The iCalendar file will be located in the same directory as the Org-mode
  4206. file, but with extension `.ics'."
  4207. (interactive)
  4208. (org-export-icalendar nil buffer-file-name))
  4209. ;;;###autoload
  4210. (defun org-export-icalendar-all-agenda-files ()
  4211. "Export all files in `org-agenda-files' to iCalendar .ics files.
  4212. Each iCalendar file will be located in the same directory as the Org-mode
  4213. file, but with extension `.ics'."
  4214. (interactive)
  4215. (apply 'org-export-icalendar nil (org-agenda-files t)))
  4216. ;;;###autoload
  4217. (defun org-export-icalendar-combine-agenda-files ()
  4218. "Export all files in `org-agenda-files' to a single combined iCalendar file.
  4219. The file is stored under the name `org-combined-agenda-icalendar-file'."
  4220. (interactive)
  4221. (apply 'org-export-icalendar t (org-agenda-files t)))
  4222. (defun org-export-icalendar (combine &rest files)
  4223. "Create iCalendar files for all elements of FILES.
  4224. If COMBINE is non-nil, combine all calendar entries into a single large
  4225. file and store it under the name `org-combined-agenda-icalendar-file'."
  4226. (save-excursion
  4227. (org-prepare-agenda-buffers files)
  4228. (let* ((dir (org-export-directory
  4229. :ical (list :publishing-directory
  4230. org-export-publishing-directory)))
  4231. file ical-file ical-buffer category started org-agenda-new-buffers)
  4232. (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
  4233. (when combine
  4234. (setq ical-file
  4235. (if (file-name-absolute-p org-combined-agenda-icalendar-file)
  4236. org-combined-agenda-icalendar-file
  4237. (expand-file-name org-combined-agenda-icalendar-file dir))
  4238. ical-buffer (org-get-agenda-file-buffer ical-file))
  4239. (set-buffer ical-buffer) (erase-buffer))
  4240. (while (setq file (pop files))
  4241. (catch 'nextfile
  4242. (org-check-agenda-file file)
  4243. (set-buffer (org-get-agenda-file-buffer file))
  4244. (unless combine
  4245. (setq ical-file (concat (file-name-as-directory dir)
  4246. (file-name-sans-extension
  4247. (file-name-nondirectory buffer-file-name))
  4248. ".ics"))
  4249. (setq ical-buffer (org-get-agenda-file-buffer ical-file))
  4250. (with-current-buffer ical-buffer (erase-buffer)))
  4251. (setq category (or org-category
  4252. (file-name-sans-extension
  4253. (file-name-nondirectory buffer-file-name))))
  4254. (if (symbolp category) (setq category (symbol-name category)))
  4255. (let ((standard-output ical-buffer))
  4256. (if combine
  4257. (and (not started) (setq started t)
  4258. (org-start-icalendar-file org-icalendar-combined-name))
  4259. (org-start-icalendar-file category))
  4260. (org-print-icalendar-entries combine)
  4261. (when (or (and combine (not files)) (not combine))
  4262. (org-finish-icalendar-file)
  4263. (set-buffer ical-buffer)
  4264. (run-hooks 'org-before-save-iCalendar-file-hook)
  4265. (save-buffer)
  4266. (run-hooks 'org-after-save-iCalendar-file-hook)
  4267. (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
  4268. ))))
  4269. (org-release-buffers org-agenda-new-buffers))))
  4270. (defvar org-before-save-iCalendar-file-hook nil
  4271. "Hook run before an iCalendar file has been saved.
  4272. This can be used to modify the result of the export.")
  4273. (defvar org-after-save-iCalendar-file-hook nil
  4274. "Hook run after an iCalendar file has been saved.
  4275. The iCalendar buffer is still current when this hook is run.
  4276. A good way to use this is to tell a desktop calendar application to re-read
  4277. the iCalendar file.")
  4278. (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
  4279. (defun org-print-icalendar-entries (&optional combine)
  4280. "Print iCalendar entries for the current Org-mode file to `standard-output'.
  4281. When COMBINE is non nil, add the category to each line."
  4282. (require 'org-agenda)
  4283. (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
  4284. (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
  4285. (dts (org-ical-ts-to-string
  4286. (format-time-string (cdr org-time-stamp-formats) (current-time))
  4287. "DTSTART"))
  4288. hd ts ts2 state status (inc t) pos b sexp rrule
  4289. scheduledp deadlinep todo prefix due start
  4290. tmp pri categories entry location summary desc uid
  4291. (sexp-buffer (get-buffer-create "*ical-tmp*")))
  4292. (org-refresh-category-properties)
  4293. (save-excursion
  4294. (goto-char (point-min))
  4295. (while (re-search-forward re1 nil t)
  4296. (catch :skip
  4297. (org-agenda-skip)
  4298. (when (boundp 'org-icalendar-verify-function)
  4299. (unless (funcall org-icalendar-verify-function)
  4300. (outline-next-heading)
  4301. (backward-char 1)
  4302. (throw :skip nil)))
  4303. (setq pos (match-beginning 0)
  4304. ts (match-string 0)
  4305. inc t
  4306. hd (condition-case nil
  4307. (org-icalendar-cleanup-string
  4308. (org-get-heading))
  4309. (error (throw :skip nil)))
  4310. summary (org-icalendar-cleanup-string
  4311. (org-entry-get nil "SUMMARY"))
  4312. desc (org-icalendar-cleanup-string
  4313. (or (org-entry-get nil "DESCRIPTION")
  4314. (and org-icalendar-include-body (org-get-entry)))
  4315. t org-icalendar-include-body)
  4316. location (org-icalendar-cleanup-string
  4317. (org-entry-get nil "LOCATION" 'selective))
  4318. uid (if org-icalendar-store-UID
  4319. (org-id-get-create)
  4320. (or (org-id-get) (org-id-new)))
  4321. categories (org-export-get-categories)
  4322. deadlinep nil scheduledp nil)
  4323. (if (looking-at re2)
  4324. (progn
  4325. (goto-char (match-end 0))
  4326. (setq ts2 (match-string 1)
  4327. inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
  4328. (setq tmp (buffer-substring (max (point-min)
  4329. (- pos org-ds-keyword-length))
  4330. pos)
  4331. ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
  4332. (progn
  4333. (setq inc nil)
  4334. (replace-match "\\1" t nil ts))
  4335. ts)
  4336. deadlinep (string-match org-deadline-regexp tmp)
  4337. scheduledp (string-match org-scheduled-regexp tmp)
  4338. todo (org-get-todo-state)
  4339. ;; donep (org-entry-is-done-p)
  4340. ))
  4341. (when (and
  4342. deadlinep
  4343. (if todo
  4344. (not (memq 'event-if-todo org-icalendar-use-deadline))
  4345. (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
  4346. (throw :skip t))
  4347. (when (and
  4348. scheduledp
  4349. (if todo
  4350. (not (memq 'event-if-todo org-icalendar-use-scheduled))
  4351. (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
  4352. (throw :skip t))
  4353. (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
  4354. (if (or (string-match org-tr-regexp hd)
  4355. (string-match org-ts-regexp hd))
  4356. (setq hd (replace-match "" t t hd)))
  4357. (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
  4358. (setq rrule
  4359. (concat "\nRRULE:FREQ="
  4360. (cdr (assoc
  4361. (match-string 2 ts)
  4362. '(("d" . "DAILY")("w" . "WEEKLY")
  4363. ("m" . "MONTHLY")("y" . "YEARLY"))))
  4364. ";INTERVAL=" (match-string 1 ts)))
  4365. (setq rrule ""))
  4366. (setq summary (or summary hd))
  4367. (if (string-match org-bracket-link-regexp summary)
  4368. (setq summary
  4369. (replace-match (if (match-end 3)
  4370. (match-string 3 summary)
  4371. (match-string 1 summary))
  4372. t t summary)))
  4373. (if deadlinep (setq summary (concat "DL: " summary)))
  4374. (if scheduledp (setq summary (concat "S: " summary)))
  4375. (if (string-match "\\`<%%" ts)
  4376. (with-current-buffer sexp-buffer
  4377. (insert (substring ts 1 -1) " " summary "\n"))
  4378. (princ (format "BEGIN:VEVENT
  4379. UID: %s
  4380. %s
  4381. %s%s
  4382. SUMMARY:%s%s%s
  4383. CATEGORIES:%s
  4384. END:VEVENT\n"
  4385. (concat prefix uid)
  4386. (org-ical-ts-to-string ts "DTSTART")
  4387. (org-ical-ts-to-string ts2 "DTEND" inc)
  4388. rrule summary
  4389. (if (and desc (string-match "\\S-" desc))
  4390. (concat "\nDESCRIPTION: " desc) "")
  4391. (if (and location (string-match "\\S-" location))
  4392. (concat "\nLOCATION: " location) "")
  4393. categories)))))
  4394. (when (and org-icalendar-include-sexps
  4395. (condition-case nil (require 'icalendar) (error nil))
  4396. (fboundp 'icalendar-export-region))
  4397. ;; Get all the literal sexps
  4398. (goto-char (point-min))
  4399. (while (re-search-forward "^&?%%(" nil t)
  4400. (catch :skip
  4401. (org-agenda-skip)
  4402. (setq b (match-beginning 0))
  4403. (goto-char (1- (match-end 0)))
  4404. (forward-sexp 1)
  4405. (end-of-line 1)
  4406. (setq sexp (buffer-substring b (point)))
  4407. (with-current-buffer sexp-buffer
  4408. (insert sexp "\n"))))
  4409. (princ (org-diary-to-ical-string sexp-buffer))
  4410. (kill-buffer sexp-buffer))
  4411. (when org-icalendar-include-todo
  4412. (setq prefix "TODO-")
  4413. (goto-char (point-min))
  4414. (while (re-search-forward org-todo-line-regexp nil t)
  4415. (catch :skip
  4416. (org-agenda-skip)
  4417. (when (boundp 'org-icalendar-verify-function)
  4418. (unless (funcall org-icalendar-verify-function)
  4419. (outline-next-heading)
  4420. (backward-char 1)
  4421. (throw :skip nil)))
  4422. (setq state (match-string 2))
  4423. (setq status (if (member state org-done-keywords)
  4424. "COMPLETED" "NEEDS-ACTION"))
  4425. (when (and state
  4426. (or (not (member state org-done-keywords))
  4427. (eq org-icalendar-include-todo 'all))
  4428. (not (member org-archive-tag (org-get-tags-at)))
  4429. )
  4430. (setq hd (match-string 3)
  4431. summary (org-icalendar-cleanup-string
  4432. (org-entry-get nil "SUMMARY"))
  4433. desc (org-icalendar-cleanup-string
  4434. (or (org-entry-get nil "DESCRIPTION")
  4435. (and org-icalendar-include-body (org-get-entry)))
  4436. t org-icalendar-include-body)
  4437. location (org-icalendar-cleanup-string
  4438. (org-entry-get nil "LOCATION" 'selective))
  4439. due (and (member 'todo-due org-icalendar-use-deadline)
  4440. (org-entry-get nil "DEADLINE"))
  4441. start (and (member 'todo-start org-icalendar-use-scheduled)
  4442. (org-entry-get nil "SCHEDULED"))
  4443. categories (org-export-get-categories)
  4444. uid (if org-icalendar-store-UID
  4445. (org-id-get-create)
  4446. (or (org-id-get) (org-id-new))))
  4447. (and due (setq due (org-ical-ts-to-string due "DUE")))
  4448. (and start (setq start (org-ical-ts-to-string start "DTSTART")))
  4449. (if (string-match org-bracket-link-regexp hd)
  4450. (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
  4451. (match-string 1 hd))
  4452. t t hd)))
  4453. (if (string-match org-priority-regexp hd)
  4454. (setq pri (string-to-char (match-string 2 hd))
  4455. hd (concat (substring hd 0 (match-beginning 1))
  4456. (substring hd (match-end 1))))
  4457. (setq pri org-default-priority))
  4458. (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
  4459. (- org-lowest-priority org-highest-priority))))))
  4460. (princ (format "BEGIN:VTODO
  4461. UID: %s
  4462. %s
  4463. SUMMARY:%s%s%s%s
  4464. CATEGORIES:%s
  4465. SEQUENCE:1
  4466. PRIORITY:%d
  4467. STATUS:%s
  4468. END:VTODO\n"
  4469. (concat prefix uid)
  4470. (or start dts)
  4471. (or summary hd)
  4472. (if (and location (string-match "\\S-" location))
  4473. (concat "\nLOCATION: " location) "")
  4474. (if (and desc (string-match "\\S-" desc))
  4475. (concat "\nDESCRIPTION: " desc) "")
  4476. (if due (concat "\n" due) "")
  4477. categories
  4478. pri status)))))))))
  4479. (defun org-export-get-categories ()
  4480. "Get categories according to `org-icalendar-categories'."
  4481. (let ((cs org-icalendar-categories) c rtn tmp)
  4482. (while (setq c (pop cs))
  4483. (cond
  4484. ((eq c 'category) (push (org-get-category) rtn))
  4485. ((eq c 'todo-state)
  4486. (setq tmp (org-get-todo-state))
  4487. (and tmp (push tmp rtn)))
  4488. ((eq c 'local-tags)
  4489. (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
  4490. ((eq c 'all-tags)
  4491. (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
  4492. (mapconcat 'identity (nreverse rtn) ",")))
  4493. (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
  4494. "Take out stuff and quote what needs to be quoted.
  4495. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  4496. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  4497. characters."
  4498. (if (not s)
  4499. nil
  4500. (when is-body
  4501. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  4502. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  4503. (while (string-match re s) (setq s (replace-match "" t t s)))
  4504. (while (string-match re2 s) (setq s (replace-match "" t t s)))))
  4505. (let ((start 0))
  4506. (while (string-match "\\([,;]\\)" s start)
  4507. (setq start (+ (match-beginning 0) 2)
  4508. s (replace-match "\\\\\\1" nil nil s))))
  4509. (setq s (org-trim s))
  4510. (when is-body
  4511. (while (string-match "[ \t]*\n[ \t]*" s)
  4512. (setq s (replace-match "\\n" t t s))))
  4513. (if is-body
  4514. (if maxlength
  4515. (if (and (numberp maxlength)
  4516. (> (length s) maxlength))
  4517. (setq s (substring s 0 maxlength)))))
  4518. s))
  4519. (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength)
  4520. "Take out stuff and quote what needs to be quoted.
  4521. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  4522. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  4523. characters.
  4524. This seems to be more like RFC 2455, but it causes problems, so it is
  4525. not used right now."
  4526. (if (not s)
  4527. nil
  4528. (if is-body
  4529. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  4530. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  4531. (while (string-match re s) (setq s (replace-match "" t t s)))
  4532. (while (string-match re2 s) (setq s (replace-match "" t t s)))
  4533. (setq s (org-trim s))
  4534. (while (string-match "[ \t]*\n[ \t]*" s)
  4535. (setq s (replace-match "\\n" t t s)))
  4536. (if maxlength
  4537. (if (and (numberp maxlength)
  4538. (> (length s) maxlength))
  4539. (setq s (substring s 0 maxlength)))))
  4540. (setq s (org-trim s)))
  4541. (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
  4542. (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
  4543. s))
  4544. (defun org-get-entry ()
  4545. "Clean-up description string."
  4546. (save-excursion
  4547. (org-back-to-heading t)
  4548. (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
  4549. (defun org-start-icalendar-file (name)
  4550. "Start an iCalendar file by inserting the header."
  4551. (let ((user user-full-name)
  4552. (name (or name "unknown"))
  4553. (timezone (cadr (current-time-zone))))
  4554. (princ
  4555. (format "BEGIN:VCALENDAR
  4556. VERSION:2.0
  4557. X-WR-CALNAME:%s
  4558. PRODID:-//%s//Emacs with Org-mode//EN
  4559. X-WR-TIMEZONE:%s
  4560. CALSCALE:GREGORIAN\n" name user timezone))))
  4561. (defun org-finish-icalendar-file ()
  4562. "Finish an iCalendar file by inserting the END statement."
  4563. (princ "END:VCALENDAR\n"))
  4564. (defun org-ical-ts-to-string (s keyword &optional inc)
  4565. "Take a time string S and convert it to iCalendar format.
  4566. KEYWORD is added in front, to make a complete line like DTSTART....
  4567. When INC is non-nil, increase the hour by two (if time string contains
  4568. a time), or the day by one (if it does not contain a time)."
  4569. (let ((t1 (org-parse-time-string s 'nodefault))
  4570. t2 fmt have-time time)
  4571. (if (and (car t1) (nth 1 t1) (nth 2 t1))
  4572. (setq t2 t1 have-time t)
  4573. (setq t2 (org-parse-time-string s)))
  4574. (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
  4575. (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
  4576. (when inc
  4577. (if have-time
  4578. (if org-agenda-default-appointment-duration
  4579. (setq mi (+ org-agenda-default-appointment-duration mi))
  4580. (setq h (+ 2 h)))
  4581. (setq d (1+ d))))
  4582. (setq time (encode-time s mi h d m y)))
  4583. (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
  4584. (concat keyword (format-time-string fmt time))))
  4585. ;;; XOXO export
  4586. (defun org-export-as-xoxo-insert-into (buffer &rest output)
  4587. (with-current-buffer buffer
  4588. (apply 'insert output)))
  4589. (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
  4590. ;;;###autoload
  4591. (defun org-export-as-xoxo (&optional buffer)
  4592. "Export the org buffer as XOXO.
  4593. The XOXO buffer is named *xoxo-<source buffer name>*"
  4594. (interactive (list (current-buffer)))
  4595. ;; A quickie abstraction
  4596. ;; Output everything as XOXO
  4597. (with-current-buffer (get-buffer buffer)
  4598. (let* ((pos (point))
  4599. (opt-plist (org-combine-plists (org-default-export-plist)
  4600. (org-infile-export-plist)))
  4601. (filename (concat (file-name-as-directory
  4602. (org-export-directory :xoxo opt-plist))
  4603. (file-name-sans-extension
  4604. (file-name-nondirectory buffer-file-name))
  4605. ".html"))
  4606. (out (find-file-noselect filename))
  4607. (last-level 1)
  4608. (hanging-li nil))
  4609. (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
  4610. ;; Check the output buffer is empty.
  4611. (with-current-buffer out (erase-buffer))
  4612. ;; Kick off the output
  4613. (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
  4614. (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
  4615. (let* ((hd (match-string-no-properties 1))
  4616. (level (length hd))
  4617. (text (concat
  4618. (match-string-no-properties 2)
  4619. (save-excursion
  4620. (goto-char (match-end 0))
  4621. (let ((str ""))
  4622. (catch 'loop
  4623. (while 't
  4624. (forward-line)
  4625. (if (looking-at "^[ \t]\\(.*\\)")
  4626. (setq str (concat str (match-string-no-properties 1)))
  4627. (throw 'loop str)))))))))
  4628. ;; Handle level rendering
  4629. (cond
  4630. ((> level last-level)
  4631. (org-export-as-xoxo-insert-into out "\n<ol>\n"))
  4632. ((< level last-level)
  4633. (dotimes (- (- last-level level) 1)
  4634. (if hanging-li
  4635. (org-export-as-xoxo-insert-into out "</li>\n"))
  4636. (org-export-as-xoxo-insert-into out "</ol>\n"))
  4637. (when hanging-li
  4638. (org-export-as-xoxo-insert-into out "</li>\n")
  4639. (setq hanging-li nil)))
  4640. ((equal level last-level)
  4641. (if hanging-li
  4642. (org-export-as-xoxo-insert-into out "</li>\n")))
  4643. )
  4644. (setq last-level level)
  4645. ;; And output the new li
  4646. (setq hanging-li 't)
  4647. (if (equal ?+ (elt text 0))
  4648. (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
  4649. (org-export-as-xoxo-insert-into out "<li>" text))))
  4650. ;; Finally finish off the ol
  4651. (dotimes (- last-level 1)
  4652. (if hanging-li
  4653. (org-export-as-xoxo-insert-into out "</li>\n"))
  4654. (org-export-as-xoxo-insert-into out "</ol>\n"))
  4655. (goto-char pos)
  4656. ;; Finish the buffer off and clean it up.
  4657. (switch-to-buffer-other-window out)
  4658. (indent-region (point-min) (point-max) nil)
  4659. (save-buffer)
  4660. (goto-char (point-min))
  4661. )))
  4662. (provide 'org-exp)
  4663. ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
  4664. ;;; org-exp.el ends here