org-exp.el 179 KB

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