org-exp.el 168 KB

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