org-exp.el 185 KB

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