org-exp.el 152 KB

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