org-exp.el 187 KB

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