org-exp.el 186 KB

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