org-exp.el 181 KB

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