org-exp.el 177 KB

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