org-exp.el 189 KB

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