org-e-html.el 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896
  1. ;;; org-e-html.el --- HTML Back-End For Org Export Engine
  2. ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. ;; Author: Jambunathan K <kjambunathan at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library implements a HTML back-end for Org generic exporter.
  17. ;; To test it, run
  18. ;;
  19. ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
  20. ;;
  21. ;; in an org-mode buffer then switch to the buffer to see the HTML
  22. ;; export. See contrib/lisp/org-export.el for more details on how
  23. ;; this exporter works.
  24. ;;; Code:
  25. ;;; org-e-html.el
  26. ;;; Dependencies
  27. (require 'org-export)
  28. (require 'org-e-publish)
  29. (require 'format-spec)
  30. (eval-when-compile (require 'cl) (require 'table))
  31. ;;; Function Declarations
  32. (declare-function org-id-find-id-file "org-id" (id))
  33. (declare-function htmlize-region "ext:htmlize" (beg end))
  34. (declare-function org-pop-to-buffer-same-window
  35. "org-compat" (&optional buffer-or-name norecord label))
  36. ;;; Define Back-End
  37. (org-export-define-backend e-html
  38. ((bold . org-e-html-bold)
  39. (center-block . org-e-html-center-block)
  40. (clock . org-e-html-clock)
  41. (code . org-e-html-code)
  42. (drawer . org-e-html-drawer)
  43. (dynamic-block . org-e-html-dynamic-block)
  44. (entity . org-e-html-entity)
  45. (example-block . org-e-html-example-block)
  46. (export-block . org-e-html-export-block)
  47. (export-snippet . org-e-html-export-snippet)
  48. (fixed-width . org-e-html-fixed-width)
  49. (footnote-definition . org-e-html-footnote-definition)
  50. (footnote-reference . org-e-html-footnote-reference)
  51. (headline . org-e-html-headline)
  52. (horizontal-rule . org-e-html-horizontal-rule)
  53. (inline-src-block . org-e-html-inline-src-block)
  54. (inlinetask . org-e-html-inlinetask)
  55. (italic . org-e-html-italic)
  56. (item . org-e-html-item)
  57. (keyword . org-e-html-keyword)
  58. (latex-environment . org-e-html-latex-environment)
  59. (latex-fragment . org-e-html-latex-fragment)
  60. (line-break . org-e-html-line-break)
  61. (link . org-e-html-link)
  62. (paragraph . org-e-html-paragraph)
  63. (plain-list . org-e-html-plain-list)
  64. (plain-text . org-e-html-plain-text)
  65. (planning . org-e-html-planning)
  66. (property-drawer . org-e-html-property-drawer)
  67. (quote-block . org-e-html-quote-block)
  68. (quote-section . org-e-html-quote-section)
  69. (radio-target . org-e-html-radio-target)
  70. (section . org-e-html-section)
  71. (special-block . org-e-html-special-block)
  72. (src-block . org-e-html-src-block)
  73. (statistics-cookie . org-e-html-statistics-cookie)
  74. (strike-through . org-e-html-strike-through)
  75. (subscript . org-e-html-subscript)
  76. (superscript . org-e-html-superscript)
  77. (table . org-e-html-table)
  78. (table-cell . org-e-html-table-cell)
  79. (table-row . org-e-html-table-row)
  80. (target . org-e-html-target)
  81. (template . org-e-html-template)
  82. (timestamp . org-e-html-timestamp)
  83. (underline . org-e-html-underline)
  84. (verbatim . org-e-html-verbatim)
  85. (verse-block . org-e-html-verse-block))
  86. :export-block "HTML"
  87. :filters-alist ((:filter-final-output . org-e-html-final-function))
  88. :menu-entry
  89. (?h "Export to HTML"
  90. ((?H "To temporary buffer" org-e-html-export-as-html)
  91. (?h "To file" org-e-html-export-to-html)
  92. (?o "To file and open"
  93. (lambda (s v b) (org-open-file (org-e-html-export-to-html s v b))))))
  94. :options-alist
  95. ;; FIXME: Prefix KEYWORD and OPTION with "HTML_". Prefix
  96. ;; corresponding properties with `:html-". If such a renaming is
  97. ;; taken up, some changes will be required in `org-jsinfo.el',
  98. ;; I think. So defer renaming for now.
  99. ((:agenda-style nil nil org-agenda-export-html-style)
  100. (:creator "CREATOR" nil org-e-html-creator-string)
  101. (:convert-org-links nil nil org-e-html-link-org-files-as-html)
  102. (:inline-images nil nil org-e-html-inline-images)
  103. (:link-home "LINK_HOME" nil org-e-html-link-home)
  104. (:link-up "LINK_UP" nil org-e-html-link-up)
  105. (:style nil nil org-e-html-style)
  106. (:style-extra "STYLE" nil org-e-html-style-extra newline)
  107. (:style-include-default nil nil org-e-html-style-include-default)
  108. (:style-include-scripts nil nil org-e-html-style-include-scripts)
  109. (:html-extension nil nil org-e-html-extension)
  110. (:html-postamble nil "html-postamble" org-e-html-postamble)
  111. (:html-preamble nil "html-preamble" org-e-html-preamble)
  112. (:html-table-tag nil nil org-e-html-table-tag)
  113. (:xml-declaration nil nil org-e-html-xml-declaration)
  114. (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)
  115. (:mathjax "MATHJAX" nil "" space)))
  116. ;;; Internal Variables
  117. ;; FIXME: it already exists in org-e-html.el
  118. (defconst org-e-html-cvt-link-fn
  119. nil
  120. "Function to convert link URLs to exportable URLs.
  121. Takes two arguments, TYPE and PATH.
  122. Returns exportable url as (TYPE PATH), or nil to signal that it
  123. didn't handle this case.
  124. Intended to be locally bound around a call to `org-export-as-html'." )
  125. (defvar org-e-html-format-table-no-css)
  126. (defvar htmlize-buffer-places) ; from htmlize.el
  127. (defvar body-only) ; dynamically scoped into this.
  128. (defconst org-e-html-special-string-regexps
  129. '(("\\\\-" . "&shy;")
  130. ("---\\([^-]\\)" . "&mdash;\\1")
  131. ("--\\([^-]\\)" . "&ndash;\\1")
  132. ("\\.\\.\\." . "&hellip;"))
  133. "Regular expressions for special string conversion.")
  134. (defconst org-e-html-scripts
  135. "<script type=\"text/javascript\">
  136. /*
  137. @licstart The following is the entire license notice for the
  138. JavaScript code in this tag.
  139. Copyright (C) 2012 Free Software Foundation, Inc.
  140. The JavaScript code in this tag is free software: you can
  141. redistribute it and/or modify it under the terms of the GNU
  142. General Public License (GNU GPL) as published by the Free Software
  143. Foundation, either version 3 of the License, or (at your option)
  144. any later version. The code is distributed WITHOUT ANY WARRANTY;
  145. without even the implied warranty of MERCHANTABILITY or FITNESS
  146. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  147. As additional permission under GNU GPL version 3 section 7, you
  148. may distribute non-source (e.g., minimized or compacted) forms of
  149. that code without the copy of the GNU GPL normally required by
  150. section 4, provided you include this license notice and a URL
  151. through which recipients can access the Corresponding Source.
  152. @licend The above is the entire license notice
  153. for the JavaScript code in this tag.
  154. */
  155. <!--/*--><![CDATA[/*><!--*/
  156. function CodeHighlightOn(elem, id)
  157. {
  158. var target = document.getElementById(id);
  159. if(null != target) {
  160. elem.cacheClassElem = elem.className;
  161. elem.cacheClassTarget = target.className;
  162. target.className = \"code-highlighted\";
  163. elem.className = \"code-highlighted\";
  164. }
  165. }
  166. function CodeHighlightOff(elem, id)
  167. {
  168. var target = document.getElementById(id);
  169. if(elem.cacheClassElem)
  170. elem.className = elem.cacheClassElem;
  171. if(elem.cacheClassTarget)
  172. target.className = elem.cacheClassTarget;
  173. }
  174. /*]]>*///-->
  175. </script>"
  176. "Basic JavaScript that is needed by HTML files produced by Org mode.")
  177. (defconst org-e-html-style-default
  178. "<style type=\"text/css\">
  179. <!--/*--><![CDATA[/*><!--*/
  180. html { font-family: Times, serif; font-size: 12pt; }
  181. .title { text-align: center; }
  182. .todo { color: red; }
  183. .done { color: green; }
  184. .tag { background-color: #add8e6; font-weight:normal }
  185. .target { }
  186. .timestamp { color: #bebebe; }
  187. .timestamp-kwd { color: #5f9ea0; }
  188. .right {margin-left:auto; margin-right:0px; text-align:right;}
  189. .left {margin-left:0px; margin-right:auto; text-align:left;}
  190. .center {margin-left:auto; margin-right:auto; text-align:center;}
  191. p.verse { margin-left: 3% }
  192. pre {
  193. border: 1pt solid #AEBDCC;
  194. background-color: #F3F5F7;
  195. padding: 5pt;
  196. font-family: courier, monospace;
  197. font-size: 90%;
  198. overflow:auto;
  199. }
  200. table { border-collapse: collapse; }
  201. td, th { vertical-align: top; }
  202. th.right { text-align:center; }
  203. th.left { text-align:center; }
  204. th.center { text-align:center; }
  205. td.right { text-align:right; }
  206. td.left { text-align:left; }
  207. td.center { text-align:center; }
  208. dt { font-weight: bold; }
  209. div.figure { padding: 0.5em; }
  210. div.figure p { text-align: center; }
  211. div.inlinetask {
  212. padding:10px;
  213. border:2px solid gray;
  214. margin:10px;
  215. background: #ffffcc;
  216. }
  217. textarea { overflow-x: auto; }
  218. .linenr { font-size:smaller }
  219. .code-highlighted {background-color:#ffff00;}
  220. .org-info-js_info-navigation { border-style:none; }
  221. #org-info-js_console-label { font-size:10px; font-weight:bold;
  222. white-space:nowrap; }
  223. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  224. font-weight:bold; }
  225. /*]]>*/-->
  226. </style>"
  227. "The default style specification for exported HTML files.
  228. Please use the variables `org-e-html-style' and
  229. `org-e-html-style-extra' to add to this style. If you wish to not
  230. have the default style included, customize the variable
  231. `org-e-html-style-include-default'.")
  232. ;;; User Configuration Variables
  233. (defgroup org-export-e-html nil
  234. "Options for exporting Org mode files to HTML."
  235. :tag "Org Export HTML"
  236. :group 'org-export)
  237. (defgroup org-export-e-htmlize nil
  238. "Options for processing examples with htmlize.el."
  239. :tag "Org Export Htmlize"
  240. :group 'org-export-e-html)
  241. ;;;; Bold etc
  242. (defcustom org-e-html-text-markup-alist
  243. '((bold . "<b>%s</b>")
  244. (code . "<code>%s</code>")
  245. (italic . "<i>%s</i>")
  246. (strike-through . "<del>%s</del>")
  247. (underline . "<span style=\"text-decoration:underline;\">%s</span>")
  248. (verbatim . "<code>%s</code>"))
  249. "Alist of HTML expressions to convert text markup
  250. The key must be a symbol among `bold', `code', `italic',
  251. `strike-through', `underline' and `verbatim'. The value is
  252. a formatting string to wrap fontified text with.
  253. If no association can be found for a given markup, text will be
  254. returned as-is."
  255. :group 'org-export-e-html
  256. :type '(alist :key-type (symbol :tag "Markup type")
  257. :value-type (string :tag "Format string"))
  258. :options '(bold code italic strike-through underline verbatim))
  259. ;;;; Debugging
  260. (defcustom org-e-html-pretty-output nil
  261. "Enable this to generate pretty HTML."
  262. :group 'org-export-e-html
  263. :type 'boolean)
  264. ;;;; Drawers
  265. (defcustom org-e-html-format-drawer-function nil
  266. "Function called to format a drawer in HTML code.
  267. The function must accept two parameters:
  268. NAME the drawer name, like \"LOGBOOK\"
  269. CONTENTS the contents of the drawer.
  270. The function should return the string to be exported.
  271. For example, the variable could be set to the following function
  272. in order to mimic default behaviour:
  273. \(defun org-e-html-format-drawer-default \(name contents\)
  274. \"Format a drawer element for HTML export.\"
  275. contents\)"
  276. :group 'org-export-e-html
  277. :type 'function)
  278. ;;;; Footnotes
  279. (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
  280. <h2 class=\"footnotes\">%s: </h2>
  281. <div id=\"text-footnotes\">
  282. %s
  283. </div>
  284. </div>"
  285. "Format for the footnotes section.
  286. Should contain a two instances of %s. The first will be replaced with the
  287. language-specific word for \"Footnotes\", the second one will be replaced
  288. by the footnotes themselves."
  289. :group 'org-export-e-html
  290. :type 'string)
  291. (defcustom org-e-html-footnote-format "<sup>%s</sup>"
  292. "The format for the footnote reference.
  293. %s will be replaced by the footnote reference itself."
  294. :group 'org-export-e-html
  295. :type 'string)
  296. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  297. "Text used to separate footnotes."
  298. :group 'org-export-e-html
  299. :type 'string)
  300. ;;;; Headline
  301. (defcustom org-e-html-toplevel-hlevel 2
  302. "The <H> level for level 1 headings in HTML export.
  303. This is also important for the classes that will be wrapped around headlines
  304. and outline structure. If this variable is 1, the top-level headlines will
  305. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  306. and outline-text-1. If this is 2, all of these will get a 2 instead.
  307. The default for this variable is 2, because we use <h1> for formatting the
  308. document title."
  309. :group 'org-export-e-html
  310. :type 'integer)
  311. (defcustom org-e-html-format-headline-function nil
  312. "Function to format headline text.
  313. This function will be called with 5 arguments:
  314. TODO the todo keyword (string or nil).
  315. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  316. PRIORITY the priority of the headline (integer or nil)
  317. TEXT the main headline text (string).
  318. TAGS the tags (string or nil).
  319. The function result will be used in the section format string.
  320. As an example, one could set the variable to the following, in
  321. order to reproduce the default set-up:
  322. \(defun org-e-html-format-headline \(todo todo-type priority text tags)
  323. \"Default format function for an headline.\"
  324. \(concat \(when todo
  325. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
  326. \(when priority
  327. \(format \"\\\\framebox{\\\\#%c} \" priority))
  328. text
  329. \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
  330. :group 'org-export-e-html
  331. :type 'function)
  332. ;;;; HTML-specific
  333. (defcustom org-e-html-allow-name-attribute-in-anchors t
  334. "When nil, do not set \"name\" attribute in anchors.
  335. By default, anchors are formatted with both \"id\" and \"name\"
  336. attributes, when appropriate."
  337. :group 'org-export-e-html
  338. :type 'boolean)
  339. ;;;; Inlinetasks
  340. (defcustom org-e-html-format-inlinetask-function nil
  341. "Function called to format an inlinetask in HTML code.
  342. The function must accept six parameters:
  343. TODO the todo keyword, as a string
  344. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  345. PRIORITY the inlinetask priority, as a string
  346. NAME the inlinetask name, as a string.
  347. TAGS the inlinetask tags, as a list of strings.
  348. CONTENTS the contents of the inlinetask, as a string.
  349. The function should return the string to be exported.
  350. For example, the variable could be set to the following function
  351. in order to mimic default behaviour:
  352. \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
  353. \"Format an inline task element for HTML export.\"
  354. \(let \(\(full-title
  355. \(concat
  356. \(when todo
  357. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
  358. \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
  359. title
  360. \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
  361. \(format (concat \"\\\\begin{center}\\n\"
  362. \"\\\\fbox{\\n\"
  363. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  364. \"%s\\n\\n\"
  365. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  366. \"%s\"
  367. \"\\\\end{minipage}}\"
  368. \"\\\\end{center}\")
  369. full-title contents))"
  370. :group 'org-export-e-html
  371. :type 'function)
  372. ;;;; Links :: Generic
  373. (defcustom org-e-html-link-org-files-as-html t
  374. "Non-nil means make file links to `file.org' point to `file.html'.
  375. When org-mode is exporting an org-mode file to HTML, links to
  376. non-html files are directly put into a href tag in HTML.
  377. However, links to other Org-mode files (recognized by the
  378. extension `.org.) should become links to the corresponding html
  379. file, assuming that the linked org-mode file will also be
  380. converted to HTML.
  381. When nil, the links still point to the plain `.org' file."
  382. :group 'org-export-e-html
  383. :type 'boolean)
  384. ;;;; Links :: Inline images
  385. (defcustom org-e-html-inline-images 'maybe
  386. "Non-nil means inline images into exported HTML pages.
  387. This is done using an <img> tag. When nil, an anchor with href is used to
  388. link to the image. If this option is `maybe', then images in links with
  389. an empty description will be inlined, while images with a description will
  390. be linked only."
  391. :group 'org-export-e-html
  392. :type '(choice (const :tag "Never" nil)
  393. (const :tag "Always" t)
  394. (const :tag "When there is no description" maybe)))
  395. (defcustom org-e-html-inline-image-rules
  396. '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  397. ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  398. ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
  399. "Rules characterizing image files that can be inlined into HTML.
  400. A rule consists in an association whose key is the type of link
  401. to consider, and value is a regexp that will be matched against
  402. link's path.
  403. Note that, by default, the image extension *actually* allowed
  404. depend on the way the HTML file is processed. When used with
  405. pdflatex, pdf, jpg and png images are OK. When processing
  406. through dvi to Postscript, only ps and eps are allowed. The
  407. default we use here encompasses both."
  408. :group 'org-export-e-html
  409. :type '(alist :key-type (string :tag "Type")
  410. :value-type (regexp :tag "Path")))
  411. ;;;; Plain Text
  412. (defcustom org-e-html-protect-char-alist
  413. '(("&" . "&amp;")
  414. ("<" . "&lt;")
  415. (">" . "&gt;"))
  416. "Alist of characters to be converted by `org-e-html-protect'."
  417. :group 'org-export-e-html
  418. :type '(repeat (cons (string :tag "Character")
  419. (string :tag "HTML equivalent"))))
  420. ;;;; Src Block
  421. (defcustom org-export-e-htmlize-output-type 'inline-css
  422. "Output type to be used by htmlize when formatting code snippets.
  423. Choices are `css', to export the CSS selectors only, or `inline-css', to
  424. export the CSS attribute values inline in the HTML. We use as default
  425. `inline-css', in order to make the resulting HTML self-containing.
  426. However, this will fail when using Emacs in batch mode for export, because
  427. then no rich font definitions are in place. It will also not be good if
  428. people with different Emacs setup contribute HTML files to a website,
  429. because the fonts will represent the individual setups. In these cases,
  430. it is much better to let Org/Htmlize assign classes only, and to use
  431. a style file to define the look of these classes.
  432. To get a start for your css file, start Emacs session and make sure that
  433. all the faces you are interested in are defined, for example by loading files
  434. in all modes you want. Then, use the command
  435. \\[org-export-e-htmlize-generate-css] to extract class definitions."
  436. :group 'org-export-e-htmlize
  437. :type '(choice (const css) (const inline-css)))
  438. (defcustom org-export-e-htmlize-css-font-prefix "org-"
  439. "The prefix for CSS class names for htmlize font specifications."
  440. :group 'org-export-e-htmlize
  441. :type 'string)
  442. (defcustom org-export-e-htmlized-org-css-url nil
  443. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  444. Normally when creating an htmlized version of an Org buffer, htmlize will
  445. create CSS to define the font colors. However, this does not work when
  446. converting in batch mode, and it also can look bad if different people
  447. with different fontification setup work on the same website.
  448. When this variable is non-nil, creating an htmlized version of an Org buffer
  449. using `org-export-as-org' will remove the internal CSS section and replace it
  450. with a link to this URL."
  451. :group 'org-export-e-htmlize
  452. :type '(choice
  453. (const :tag "Keep internal css" nil)
  454. (string :tag "URL or local href")))
  455. ;;;; Table
  456. (defcustom org-e-html-table-tag
  457. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  458. "The HTML tag that is used to start a table.
  459. This must be a <table> tag, but you may change the options like
  460. borders and spacing."
  461. :group 'org-export-e-html
  462. :type 'string)
  463. (defcustom org-e-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  464. "The opening tag for table header fields.
  465. This is customizable so that alignment options can be specified.
  466. The first %s will be filled with the scope of the field, either row or col.
  467. The second %s will be replaced by a style entry to align the field.
  468. See also the variable `org-e-html-table-use-header-tags-for-first-column'.
  469. See also the variable `org-e-html-table-align-individual-fields'."
  470. :group 'org-export-tables ; FIXME: change group?
  471. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  472. (defcustom org-e-html-table-data-tags '("<td%s>" . "</td>")
  473. "The opening tag for table data fields.
  474. This is customizable so that alignment options can be specified.
  475. The first %s will be filled with the scope of the field, either row or col.
  476. The second %s will be replaced by a style entry to align the field.
  477. See also the variable `org-e-html-table-align-individual-fields'."
  478. :group 'org-export-tables
  479. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  480. (defcustom org-e-html-table-row-tags '("<tr>" . "</tr>")
  481. "The opening tag for table data fields.
  482. This is customizable so that alignment options can be specified.
  483. Instead of strings, these can be Lisp forms that will be evaluated
  484. for each row in order to construct the table row tags. During evaluation,
  485. the variable `head' will be true when this is a header line, nil when this
  486. is a body line. And the variable `nline' will contain the line number,
  487. starting from 1 in the first header line. For example
  488. (setq org-e-html-table-row-tags
  489. (cons '(if head
  490. \"<tr>\"
  491. (if (= (mod nline 2) 1)
  492. \"<tr class=\\\"tr-odd\\\">\"
  493. \"<tr class=\\\"tr-even\\\">\"))
  494. \"</tr>\"))
  495. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  496. :group 'org-export-tables
  497. :type '(cons
  498. (choice :tag "Opening tag"
  499. (string :tag "Specify")
  500. (sexp))
  501. (choice :tag "Closing tag"
  502. (string :tag "Specify")
  503. (sexp))))
  504. (defcustom org-e-html-table-align-individual-fields t
  505. "Non-nil means attach style attributes for alignment to each table field.
  506. When nil, alignment will only be specified in the column tags, but this
  507. is ignored by some browsers (like Firefox, Safari). Opera does it right
  508. though."
  509. :group 'org-export-tables
  510. :type 'boolean)
  511. (defcustom org-e-html-table-use-header-tags-for-first-column nil
  512. "Non-nil means format column one in tables with header tags.
  513. When nil, also column one will use data tags."
  514. :group 'org-export-tables
  515. :type 'boolean)
  516. (defcustom org-e-html-table-caption-above t
  517. "When non-nil, place caption string at the beginning of the table.
  518. Otherwise, place it near the end."
  519. :group 'org-export-e-html
  520. :type 'boolean)
  521. ;;;; Tags
  522. (defcustom org-e-html-tag-class-prefix ""
  523. "Prefix to class names for TODO keywords.
  524. Each tag gets a class given by the tag itself, with this prefix.
  525. The default prefix is empty because it is nice to just use the keyword
  526. as a class name. But if you get into conflicts with other, existing
  527. CSS classes, then this prefix can be very useful."
  528. :group 'org-export-e-html
  529. :type 'string)
  530. ;;;; Template :: Generic
  531. (defcustom org-e-html-extension "html"
  532. "The extension for exported HTML files."
  533. :group 'org-export-e-html
  534. :type 'string)
  535. (defcustom org-e-html-xml-declaration
  536. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  537. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  538. "The extension for exported HTML files.
  539. %s will be replaced with the charset of the exported file.
  540. This may be a string, or an alist with export extensions
  541. and corresponding declarations."
  542. :group 'org-export-e-html
  543. :type '(choice
  544. (string :tag "Single declaration")
  545. (repeat :tag "Dependent on extension"
  546. (cons (string :tag "Extension")
  547. (string :tag "Declaration")))))
  548. (defcustom org-e-html-coding-system 'utf-8
  549. "Coding system for HTML export.
  550. Use utf-8 as the default value."
  551. :group 'org-export-e-html
  552. :type 'coding-system)
  553. (defcustom org-e-html-divs '("preamble" "content" "postamble")
  554. "The name of the main divs for HTML export.
  555. This is a list of three strings, the first one for the preamble
  556. DIV, the second one for the content DIV and the third one for the
  557. postamble DIV."
  558. :group 'org-export-e-html
  559. :type '(list
  560. (string :tag " Div for the preamble:")
  561. (string :tag " Div for the content:")
  562. (string :tag "Div for the postamble:")))
  563. ;;;; Template :: Mathjax
  564. (defcustom org-e-html-mathjax-options
  565. '((path "http://orgmode.org/mathjax/MathJax.js")
  566. (scale "100")
  567. (align "center")
  568. (indent "2em")
  569. (mathml nil))
  570. "Options for MathJax setup.
  571. path The path where to find MathJax
  572. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  573. align How to align display math: left, center, or right
  574. indent If align is not center, how far from the left/right side?
  575. mathml Should a MathML player be used if available?
  576. This is faster and reduces bandwidth use, but currently
  577. sometimes has lower spacing quality. Therefore, the default is
  578. nil. When browsers get better, this switch can be flipped.
  579. You can also customize this for each buffer, using something like
  580. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  581. :group 'org-export-e-html
  582. :type '(list :greedy t
  583. (list :tag "path (the path from where to load MathJax.js)"
  584. (const :format " " path) (string))
  585. (list :tag "scale (scaling for the displayed math)"
  586. (const :format " " scale) (string))
  587. (list :tag "align (alignment of displayed equations)"
  588. (const :format " " align) (string))
  589. (list :tag "indent (indentation with left or right alignment)"
  590. (const :format " " indent) (string))
  591. (list :tag "mathml (should MathML display be used is possible)"
  592. (const :format " " mathml) (boolean))))
  593. (defcustom org-e-html-mathjax-template
  594. "<script type=\"text/javascript\" src=\"%PATH\">
  595. <!--/*--><![CDATA[/*><!--*/
  596. MathJax.Hub.Config({
  597. // Only one of the two following lines, depending on user settings
  598. // First allows browser-native MathML display, second forces HTML/CSS
  599. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  600. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  601. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  602. \"TeX/noUndefined.js\"],
  603. tex2jax: {
  604. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  605. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  606. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  607. ignoreClass: \"tex2jax_ignore\",
  608. processEscapes: false,
  609. processEnvironments: true,
  610. preview: \"TeX\"
  611. },
  612. showProcessingMessages: true,
  613. displayAlign: \"%ALIGN\",
  614. displayIndent: \"%INDENT\",
  615. \"HTML-CSS\": {
  616. scale: %SCALE,
  617. availableFonts: [\"STIX\",\"TeX\"],
  618. preferredFont: \"TeX\",
  619. webFont: \"TeX\",
  620. imageFont: \"TeX\",
  621. showMathMenu: true,
  622. },
  623. MMLorHTML: {
  624. prefer: {
  625. MSIE: \"MML\",
  626. Firefox: \"MML\",
  627. Opera: \"HTML\",
  628. other: \"HTML\"
  629. }
  630. }
  631. });
  632. /*]]>*///-->
  633. </script>"
  634. "The MathJax setup for XHTML files."
  635. :group 'org-export-e-html
  636. :type 'string)
  637. ;;;; Template :: Postamble
  638. (defcustom org-e-html-postamble 'auto
  639. "Non-nil means insert a postamble in HTML export.
  640. When `t', insert a string as defined by the formatting string in
  641. `org-e-html-postamble-format'. When set to a string, this
  642. string overrides `org-e-html-postamble-format'. When set to
  643. 'auto, discard `org-e-html-postamble-format' and honor
  644. `org-export-author/email/creator-info' variables. When set to a
  645. function, apply this function and insert the returned string.
  646. The function takes the property list of export options as its
  647. only argument.
  648. Setting :html-postamble in publishing projects will take
  649. precedence over this variable."
  650. :group 'org-export-e-html
  651. :type '(choice (const :tag "No postamble" nil)
  652. (const :tag "Auto preamble" 'auto)
  653. (const :tag "Default formatting string" t)
  654. (string :tag "Custom formatting string")
  655. (function :tag "Function (must return a string)")))
  656. (defcustom org-e-html-postamble-format
  657. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  658. <p class=\"date\">Date: %d</p>
  659. <p class=\"creator\">Generated by %c</p>
  660. <p class=\"xhtml-validation\">%v</p>"))
  661. "Alist of languages and format strings for the HTML postamble.
  662. The first element of each list is the language code, as used for
  663. the #+LANGUAGE keyword.
  664. The second element of each list is a format string to format the
  665. postamble itself. This format string can contain these elements:
  666. %a stands for the author's name.
  667. %e stands for the author's email.
  668. %d stands for the date.
  669. %c will be replaced by information about Org/Emacs versions.
  670. %v will be replaced by `org-e-html-validation-link'.
  671. If you need to use a \"%\" character, you need to escape it
  672. like that: \"%%\"."
  673. :group 'org-export-e-html
  674. :type '(alist :key-type (string :tag "Language")
  675. :value-type (string :tag "Format string")))
  676. (defcustom org-e-html-validation-link
  677. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  678. "Link to HTML validation service."
  679. :group 'org-export-e-html
  680. :type 'string)
  681. (defcustom org-e-html-creator-string
  682. (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
  683. (if (fboundp 'org-version) (org-version) "(Unknown)")
  684. emacs-version)
  685. "String to insert at the end of the HTML document."
  686. :group 'org-export-e-html
  687. :type '(string :tag "Creator string"))
  688. ;;;; Template :: Preamble
  689. (defcustom org-e-html-preamble t
  690. "Non-nil means insert a preamble in HTML export.
  691. When `t', insert a string as defined by one of the formatting
  692. strings in `org-e-html-preamble-format'. When set to a
  693. string, this string overrides `org-e-html-preamble-format'.
  694. When set to a function, apply this function and insert the
  695. returned string. The function takes the property list of export
  696. options as its only argument.
  697. Setting :html-preamble in publishing projects will take
  698. precedence over this variable."
  699. :group 'org-export-e-html
  700. :type '(choice (const :tag "No preamble" nil)
  701. (const :tag "Default preamble" t)
  702. (string :tag "Custom formatting string")
  703. (function :tag "Function (must return a string)")))
  704. (defcustom org-e-html-preamble-format '(("en" ""))
  705. "Alist of languages and format strings for the HTML preamble.
  706. The first element of each list is the language code, as used for
  707. the #+LANGUAGE keyword.
  708. The second element of each list is a format string to format the
  709. preamble itself. This format string can contain these elements:
  710. %t stands for the title.
  711. %a stands for the author's name.
  712. %e stands for the author's email.
  713. %d stands for the date.
  714. If you need to use a \"%\" character, you need to escape it
  715. like that: \"%%\"."
  716. :group 'org-export-e-html
  717. :type '(alist :key-type (string :tag "Language")
  718. :value-type (string :tag "Format string")))
  719. (defcustom org-e-html-link-up ""
  720. "Where should the \"UP\" link of exported HTML pages lead?"
  721. :group 'org-export-e-html
  722. :type '(string :tag "File or URL"))
  723. (defcustom org-e-html-link-home ""
  724. "Where should the \"HOME\" link of exported HTML pages lead?"
  725. :group 'org-export-e-html
  726. :type '(string :tag "File or URL"))
  727. (defcustom org-e-html-home/up-format
  728. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  729. <a accesskey=\"h\" href=\"%s\"> UP </a>
  730. |
  731. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  732. </div>"
  733. "Snippet used to insert the HOME and UP links.
  734. This is a format string, the first %s will receive the UP link,
  735. the second the HOME link. If both `org-e-html-link-up' and
  736. `org-e-html-link-home' are empty, the entire snippet will be
  737. ignored."
  738. :group 'org-export-e-html
  739. :type 'string)
  740. ;;;; Template :: Scripts
  741. (defcustom org-e-html-style-include-scripts t
  742. "Non-nil means include the JavaScript snippets in exported HTML files.
  743. The actual script is defined in `org-e-html-scripts' and should
  744. not be modified."
  745. :group 'org-export-e-html
  746. :type 'boolean)
  747. ;;;; Template :: Styles
  748. (defcustom org-e-html-style-include-default t
  749. "Non-nil means include the default style in exported HTML files.
  750. The actual style is defined in `org-e-html-style-default' and should
  751. not be modified. Use the variables `org-e-html-style' to add
  752. your own style information."
  753. :group 'org-export-e-html
  754. :type 'boolean)
  755. ;;;###autoload
  756. (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
  757. (defcustom org-e-html-style ""
  758. "Org-wide style definitions for exported HTML files.
  759. This variable needs to contain the full HTML structure to provide a style,
  760. including the surrounding HTML tags. If you set the value of this variable,
  761. you should consider to include definitions for the following classes:
  762. title, todo, done, timestamp, timestamp-kwd, tag, target.
  763. For example, a valid value would be:
  764. <style type=\"text/css\">
  765. <![CDATA[
  766. p { font-weight: normal; color: gray; }
  767. h1 { color: black; }
  768. .title { text-align: center; }
  769. .todo, .timestamp-kwd { color: red; }
  770. .done { color: green; }
  771. ]]>
  772. </style>
  773. If you'd like to refer to an external style file, use something like
  774. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  775. As the value of this option simply gets inserted into the HTML <head> header,
  776. you can \"misuse\" it to add arbitrary text to the header.
  777. See also the variable `org-e-html-style-extra'."
  778. :group 'org-export-e-html
  779. :type 'string)
  780. ;;;###autoload
  781. (put 'org-e-html-style 'safe-local-variable 'stringp)
  782. (defcustom org-e-html-style-extra ""
  783. "Additional style information for HTML export.
  784. The value of this variable is inserted into the HTML buffer right after
  785. the value of `org-e-html-style'. Use this variable for per-file
  786. settings of style information, and do not forget to surround the style
  787. settings with <style>...</style> tags."
  788. :group 'org-export-e-html
  789. :type 'string)
  790. ;;;###autoload
  791. (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
  792. ;;;; Todos
  793. (defcustom org-e-html-todo-kwd-class-prefix ""
  794. "Prefix to class names for TODO keywords.
  795. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  796. The default prefix is empty because it is nice to just use the keyword
  797. as a class name. But if you get into conflicts with other, existing
  798. CSS classes, then this prefix can be very useful."
  799. :group 'org-export-e-html
  800. :type 'string)
  801. ;;; Internal Functions
  802. (defun org-e-html-format-inline-image (src &optional
  803. caption label attr standalone-p)
  804. (let* ((id (if (not label) ""
  805. (format " id=\"%s\"" (org-export-solidify-link-text label))))
  806. (attr (concat attr
  807. (cond
  808. ((string-match "\\<alt=" (or attr "")) "")
  809. ((string-match "^ltxpng/" src)
  810. (format " alt=\"%s\""
  811. (org-e-html-encode-plain-text
  812. (org-find-text-property-in-string
  813. 'org-latex-src src))))
  814. (t (format " alt=\"%s\""
  815. (file-name-nondirectory src)))))))
  816. (cond
  817. (standalone-p
  818. (let ((img (format "<img src=\"%s\" %s/>" src attr)))
  819. (format "\n<div%s class=\"figure\">%s%s\n</div>"
  820. id (format "\n<p>%s</p>" img)
  821. (when caption (format "\n<p>%s</p>" caption)))))
  822. (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
  823. ;;;; Bibliography
  824. (defun org-e-html-bibliography ()
  825. "Find bibliography, cut it out and return it."
  826. (catch 'exit
  827. (let (beg end (cnt 1) bib)
  828. (save-excursion
  829. (goto-char (point-min))
  830. (when (re-search-forward
  831. "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  832. (setq beg (match-beginning 0))
  833. (while (re-search-forward "</?div\\>" nil t)
  834. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  835. (when (= cnt 0)
  836. (and (looking-at ">") (forward-char 1))
  837. (setq bib (buffer-substring beg (point)))
  838. (delete-region beg (point))
  839. (throw 'exit bib))))
  840. nil))))
  841. ;;;; Table
  842. (defun org-e-html-splice-attributes (tag attributes)
  843. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  844. (if (not attributes)
  845. tag
  846. (let (oldatt newatt)
  847. (setq oldatt (org-extract-attributes-from-string tag)
  848. tag (pop oldatt)
  849. newatt (cdr (org-extract-attributes-from-string attributes)))
  850. (while newatt
  851. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  852. (if (string-match ">" tag)
  853. (setq tag
  854. (replace-match (concat (org-attributes-to-string oldatt) ">")
  855. t t tag)))
  856. tag)))
  857. (defun org-export-splice-style (style extra)
  858. "Splice EXTRA into STYLE, just before \"</style>\"."
  859. (if (and (stringp extra)
  860. (string-match "\\S-" extra)
  861. (string-match "</style>" style))
  862. (concat (substring style 0 (match-beginning 0))
  863. "\n" extra "\n"
  864. (substring style (match-beginning 0)))
  865. style))
  866. (defun org-export-e-htmlize-region-for-paste (beg end)
  867. "Convert the region to HTML, using htmlize.el.
  868. This is much like `htmlize-region-for-paste', only that it uses
  869. the settings define in the org-... variables."
  870. (let* ((htmlize-output-type org-export-e-htmlize-output-type)
  871. (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
  872. (htmlbuf (htmlize-region beg end)))
  873. (unwind-protect
  874. (with-current-buffer htmlbuf
  875. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  876. (plist-get htmlize-buffer-places 'content-end)))
  877. (kill-buffer htmlbuf))))
  878. ;;;###autoload
  879. (defun org-export-e-htmlize-generate-css ()
  880. "Create the CSS for all font definitions in the current Emacs session.
  881. Use this to create face definitions in your CSS style file that can then
  882. be used by code snippets transformed by htmlize.
  883. This command just produces a buffer that contains class definitions for all
  884. faces used in the current Emacs session. You can copy and paste the ones you
  885. need into your CSS file.
  886. If you then set `org-export-e-htmlize-output-type' to `css', calls to
  887. the function `org-export-e-htmlize-region-for-paste' will produce code
  888. that uses these same face definitions."
  889. (interactive)
  890. (require 'htmlize)
  891. (and (get-buffer "*html*") (kill-buffer "*html*"))
  892. (with-temp-buffer
  893. (let ((fl (face-list))
  894. (htmlize-css-name-prefix "org-")
  895. (htmlize-output-type 'css)
  896. f i)
  897. (while (setq f (pop fl)
  898. i (and f (face-attribute f :inherit)))
  899. (when (and (symbolp f) (or (not i) (not (listp i))))
  900. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  901. (htmlize-region (point-min) (point-max))))
  902. (org-pop-to-buffer-same-window "*html*")
  903. (goto-char (point-min))
  904. (if (re-search-forward "<style" nil t)
  905. (delete-region (point-min) (match-beginning 0)))
  906. (if (re-search-forward "</style>" nil t)
  907. (delete-region (1+ (match-end 0)) (point-max)))
  908. (beginning-of-line 1)
  909. (if (looking-at " +") (replace-match ""))
  910. (goto-char (point-min)))
  911. (defun org-e-html-make-string (n string)
  912. (let (out) (dotimes (i n out) (setq out (concat string out)))))
  913. (defun org-e-html-toc-text (toc-entries)
  914. (let* ((prev-level (1- (nth 1 (car toc-entries))))
  915. (start-level prev-level))
  916. (concat
  917. (mapconcat
  918. (lambda (entry)
  919. (let ((headline (nth 0 entry))
  920. (level (nth 1 entry)))
  921. (concat
  922. (let* ((cnt (- level prev-level))
  923. (times (if (> cnt 0) (1- cnt) (- cnt)))
  924. rtn)
  925. (setq prev-level level)
  926. (concat
  927. (org-e-html-make-string
  928. times (cond ((> cnt 0) "\n<ul>\n<li>")
  929. ((< cnt 0) "</li>\n</ul>\n")))
  930. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  931. headline)))
  932. toc-entries "")
  933. (org-e-html-make-string
  934. (- prev-level start-level) "</li>\n</ul>\n"))))
  935. (defun* org-e-html-format-toc-headline
  936. (todo todo-type priority text tags
  937. &key level section-number headline-label &allow-other-keys)
  938. (let ((headline (concat
  939. section-number (and section-number ". ")
  940. text
  941. (and tags "&nbsp;&nbsp;&nbsp;") (org-e-html--tags tags))))
  942. (format "<a href=\"#%s\">%s</a>"
  943. (org-export-solidify-link-text headline-label)
  944. (if (not nil) headline
  945. (format "<span class=\"%s\">%s</span>" todo-type headline)))))
  946. (defun org-e-html-toc (depth info)
  947. (let* ((headlines (org-export-collect-headlines info depth))
  948. (toc-entries
  949. (loop for headline in headlines collect
  950. (list (org-e-html-format-headline--wrap
  951. headline info 'org-e-html-format-toc-headline)
  952. (org-export-get-relative-level headline info)))))
  953. (when toc-entries
  954. (concat
  955. "<div id=\"table-of-contents\">\n"
  956. (format "<h%d>%s</h%d>\n"
  957. org-e-html-toplevel-hlevel
  958. (org-e-html--translate "Table of Contents" info)
  959. org-e-html-toplevel-hlevel)
  960. "<div id=\"text-table-of-contents\">"
  961. (org-e-html-toc-text toc-entries)
  962. "</div>\n"
  963. "</div>\n"))))
  964. (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
  965. "Turn todo keyword into a valid class name.
  966. Replaces invalid characters with \"_\"."
  967. (save-match-data
  968. (while (string-match "[^a-zA-Z0-9_]" kwd)
  969. (setq kwd (replace-match "_" t t kwd))))
  970. kwd)
  971. (defun org-e-html-format-footnote-reference (n def refcnt)
  972. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  973. (format org-e-html-footnote-format
  974. (let* ((id (format "fnr.%s%s" n extra))
  975. (href (format " href=\"#fn.%s\"" n))
  976. (attributes (concat " class=\"footref\"" href)))
  977. (org-e-html--anchor id n attributes)))))
  978. (defun org-e-html-format-footnotes-section (section-name definitions)
  979. (if (not definitions) ""
  980. (format org-e-html-footnotes-section section-name definitions)))
  981. (defun org-e-html-format-footnote-definition (fn)
  982. (let ((n (car fn)) (def (cdr fn)))
  983. (format
  984. "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
  985. (format org-e-html-footnote-format
  986. (let* ((id (format "fn.%s" n))
  987. (href (format " href=\"#fnr.%s\"" n))
  988. (attributes (concat " class=\"footnum\"" href)))
  989. (org-e-html--anchor id n attributes)))
  990. def)))
  991. (defun org-e-html-footnote-section (info)
  992. (let* ((fn-alist (org-export-collect-footnote-definitions
  993. (plist-get info :parse-tree) info))
  994. (fn-alist
  995. (loop for (n type raw) in fn-alist collect
  996. (cons n (if (eq (org-element-type raw) 'org-data)
  997. (org-trim (org-export-data raw info))
  998. (format "<p>%s</p>"
  999. (org-trim (org-export-data raw info))))))))
  1000. (when fn-alist
  1001. (org-e-html-format-footnotes-section
  1002. (org-e-html--translate "Footnotes" info)
  1003. (format
  1004. "<table>\n%s\n</table>\n"
  1005. (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
  1006. ;;; Template
  1007. (defun org-e-html--build-meta-info (info)
  1008. "Return meta tags for exported document.
  1009. INFO is a plist used as a communication channel."
  1010. (let* ((title (org-export-data (plist-get info :title) info))
  1011. (author (and (plist-get info :with-author)
  1012. (let ((auth (plist-get info :author)))
  1013. (and auth (org-export-data auth info)))))
  1014. (date (and (plist-get info :with-date)
  1015. (let ((date (plist-get info :date)))
  1016. (and date (org-export-data date info)))))
  1017. (description (plist-get info :description))
  1018. (keywords (plist-get info :keywords)))
  1019. (concat
  1020. (format "<title>%s</title>\n" title)
  1021. (format
  1022. "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
  1023. (or (and org-e-html-coding-system
  1024. (fboundp 'coding-system-get)
  1025. (coding-system-get org-e-html-coding-system 'mime-charset))
  1026. "iso-8859-1"))
  1027. (format "<meta name=\"title\" content=\"%s\"/>\n" title)
  1028. (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
  1029. (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
  1030. (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
  1031. (and description
  1032. (format "<meta name=\"description\" content=\"%s\"/>\n" description))
  1033. (and keywords
  1034. (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
  1035. (defun org-e-html--build-style (info)
  1036. "Return style information for exported document.
  1037. INFO is a plist used as a communication channel."
  1038. (org-element-normalize-string
  1039. (concat
  1040. (when (plist-get info :style-include-default) org-e-html-style-default)
  1041. (org-element-normalize-string (plist-get info :style))
  1042. (org-element-normalize-string (plist-get info :style-extra))
  1043. (when (plist-get info :style-include-scripts) org-e-html-scripts))))
  1044. (defun org-e-html--build-mathjax-config (info)
  1045. "Insert the user setup into the mathjax template.
  1046. INFO is a plist used as a communication channel."
  1047. (when (member (plist-get info :LaTeX-fragments) '(mathjax t))
  1048. (let ((template org-e-html-mathjax-template)
  1049. (options org-e-html-mathjax-options)
  1050. (in-buffer (or (plist-get info :mathjax) ""))
  1051. name val (yes " ") (no "// ") x)
  1052. (mapc
  1053. (lambda (e)
  1054. (setq name (car e) val (nth 1 e))
  1055. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  1056. (setq val (car (read-from-string
  1057. (substring in-buffer (match-end 0))))))
  1058. (if (not (stringp val)) (setq val (format "%s" val)))
  1059. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  1060. (setq template (replace-match val t t template))))
  1061. options)
  1062. (setq val (nth 1 (assq 'mathml options)))
  1063. (if (string-match (concat "\\<mathml:") in-buffer)
  1064. (setq val (car (read-from-string
  1065. (substring in-buffer (match-end 0))))))
  1066. ;; Exchange prefixes depending on mathml setting.
  1067. (if (not val) (setq x yes yes no no x))
  1068. ;; Replace cookies to turn on or off the config/jax lines.
  1069. (if (string-match ":MMLYES:" template)
  1070. (setq template (replace-match yes t t template)))
  1071. (if (string-match ":MMLNO:" template)
  1072. (setq template (replace-match no t t template)))
  1073. ;; Return the modified template.
  1074. (org-element-normalize-string template))))
  1075. (defun org-e-html--build-preamble (info)
  1076. "Return document preamble as a string, or nil.
  1077. INFO is a plist used as a communication channel."
  1078. (let ((preamble (plist-get info :html-preamble)))
  1079. (when preamble
  1080. (let ((preamble-contents
  1081. (if (functionp preamble) (funcall preamble info)
  1082. (let ((title (org-export-data (plist-get info :title) info))
  1083. (date (if (not (plist-get info :with-date)) ""
  1084. (org-export-data (plist-get info :date) info)))
  1085. (author (if (not (plist-get info :with-author)) ""
  1086. (org-export-data (plist-get info :author) info)))
  1087. (email (if (not (plist-get info :with-email)) ""
  1088. (plist-get info :email))))
  1089. (if (stringp preamble)
  1090. (format-spec preamble
  1091. `((?t . ,title) (?a . ,author)
  1092. (?d . ,date) (?e . ,email)))
  1093. (format-spec
  1094. (or (cadr (assoc (plist-get info :language)
  1095. org-e-html-preamble-format))
  1096. (cadr (assoc "en" org-e-html-preamble-format)))
  1097. `((?t . ,title) (?a . ,author)
  1098. (?d . ,date) (?e . ,email))))))))
  1099. (when (org-string-nw-p preamble-contents)
  1100. (concat (format "<div id=\"%s\">\n" (nth 0 org-e-html-divs))
  1101. (org-element-normalize-string preamble-contents)
  1102. "</div>\n"))))))
  1103. (defun org-e-html--build-postamble (info)
  1104. "Return document postamble as a string, or nil.
  1105. INFO is a plist used as a communication channel."
  1106. (let ((postamble (plist-get info :html-postamble)))
  1107. (when postamble
  1108. (let ((postamble-contents
  1109. (if (functionp postamble) (funcall postamble info)
  1110. (let ((date (if (not (plist-get info :with-date)) ""
  1111. (org-export-data (plist-get info :date) info)))
  1112. (author (let ((author (plist-get info :author)))
  1113. (and author (org-export-data author info))))
  1114. (email (mapconcat
  1115. (lambda (e)
  1116. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1117. (split-string (plist-get info :email) ",+ *")
  1118. ", "))
  1119. (html-validation-link (or org-e-html-validation-link ""))
  1120. (creator-info (plist-get info :creator)))
  1121. (cond ((stringp postamble)
  1122. (format-spec postamble
  1123. `((?a . ,author) (?e . ,email)
  1124. (?d . ,date) (?c . ,creator-info)
  1125. (?v . ,html-validation-link))))
  1126. ((eq postamble 'auto)
  1127. (concat
  1128. (when (plist-get info :time-stamp-file)
  1129. (format "<p class=\"date\">%s: %s</p>\n"
  1130. (org-e-html--translate "Date" info)
  1131. date))
  1132. (when (and (plist-get info :with-author) author)
  1133. (format "<p class=\"author\">%s : %s</p>\n"
  1134. (org-e-html--translate "Author" info)
  1135. author))
  1136. (when (and (plist-get info :with-email) email)
  1137. (format "<p class=\"email\">%s </p>\n" email))
  1138. (when (plist-get info :with-creator)
  1139. (format "<p class=\"creator\">%s</p>\n"
  1140. creator-info))
  1141. html-validation-link "\n"))
  1142. (t (format-spec
  1143. (or (cadr (assoc (plist-get info :language)
  1144. org-e-html-postamble-format))
  1145. (cadr (assoc "en" org-e-html-postamble-format)))
  1146. `((?a . ,author) (?e . ,email)
  1147. (?d . ,date) (?c . ,creator-info)
  1148. (?v . ,html-validation-link)))))))))
  1149. (when (org-string-nw-p postamble-contents)
  1150. (concat
  1151. (format "<div id=\"%s\">\n" (nth 2 org-e-html-divs))
  1152. (org-element-normalize-string postamble-contents)
  1153. "</div>\n"))))))
  1154. (defun org-e-html-template (contents info)
  1155. "Return complete document string after HTML conversion.
  1156. CONTENTS is the transcoded contents string. INFO is a plist
  1157. holding export options."
  1158. (concat
  1159. (format
  1160. (or (and (stringp org-e-html-xml-declaration)
  1161. org-e-html-xml-declaration)
  1162. (cdr (assoc (plist-get info :html-extension)
  1163. org-e-html-xml-declaration))
  1164. (cdr (assoc "html" org-e-html-xml-declaration))
  1165. "")
  1166. (or (and org-e-html-coding-system
  1167. (fboundp 'coding-system-get)
  1168. (coding-system-get org-e-html-coding-system 'mime-charset))
  1169. "iso-8859-1"))
  1170. "\n"
  1171. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1172. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
  1173. (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
  1174. (plist-get info :language) (plist-get info :language))
  1175. "<head>\n"
  1176. (org-e-html--build-meta-info info)
  1177. (org-e-html--build-style info)
  1178. (org-e-html--build-mathjax-config info)
  1179. "</head>\n"
  1180. "<body>\n"
  1181. (let ((link-up (org-trim (plist-get info :link-up)))
  1182. (link-home (org-trim (plist-get info :link-home))))
  1183. (unless (and (string= link-up "") (string= link-up ""))
  1184. (format org-e-html-home/up-format
  1185. (or link-up link-home)
  1186. (or link-home link-up))))
  1187. ;; Preamble.
  1188. (org-e-html--build-preamble info)
  1189. ;; Begin content.
  1190. (format "<div id=\"%s\">\n" (nth 1 org-e-html-divs))
  1191. ;; Document title.
  1192. (format "<h1 class=\"title\">%s</h1>\n"
  1193. (org-export-data (plist-get info :title) info))
  1194. ;; Table of contents.
  1195. (let ((depth (plist-get info :with-toc)))
  1196. (when depth (org-e-html-toc depth info)))
  1197. ;; Document contents.
  1198. contents
  1199. ;; Footnotes section.
  1200. (org-e-html-footnote-section info)
  1201. ;; Bibliography.
  1202. (org-e-html-bibliography)
  1203. ;; End content.
  1204. "\n</div>"
  1205. ;; Postamble.
  1206. (org-e-html--build-postamble info)
  1207. ;; Closing document.
  1208. "</body>\n</html>"))
  1209. (defun org-e-html--translate (s info)
  1210. "Translate string S according to specified language.
  1211. INFO is a plist used as a communication channel."
  1212. (org-export-translate s :html info))
  1213. ;;;; Anchor
  1214. (defun org-e-html--anchor (&optional id desc attributes)
  1215. (let* ((name (and org-e-html-allow-name-attribute-in-anchors id))
  1216. (attributes (concat (and id (format " id=\"%s\"" id))
  1217. (and name (format " name=\"%s\"" name))
  1218. attributes)))
  1219. (format "<a%s>%s</a>" attributes (or desc ""))))
  1220. ;;;; Todo
  1221. (defun org-e-html--todo (todo)
  1222. (when todo
  1223. (format "<span class=\"%s %s%s\">%s</span>"
  1224. (if (member todo org-done-keywords) "done" "todo")
  1225. org-e-html-todo-kwd-class-prefix (org-e-html-fix-class-name todo)
  1226. todo)))
  1227. ;;;; Tags
  1228. (defun org-e-html--tags (tags)
  1229. (when tags
  1230. (format "<span class=\"tag\">%s</span>"
  1231. (mapconcat
  1232. (lambda (tag)
  1233. (format "<span class=\"%s\">%s</span>"
  1234. (concat org-e-html-tag-class-prefix
  1235. (org-e-html-fix-class-name tag))
  1236. tag))
  1237. tags "&nbsp;"))))
  1238. ;;;; Headline
  1239. (defun* org-e-html-format-headline
  1240. (todo todo-type priority text tags
  1241. &key level section-number headline-label &allow-other-keys)
  1242. (let ((section-number
  1243. (when section-number
  1244. (format "<span class=\"section-number-%d\">%s</span> "
  1245. level section-number)))
  1246. (todo (org-e-html--todo todo))
  1247. (tags (org-e-html--tags tags)))
  1248. (concat section-number todo (and todo " ") text
  1249. (and tags "&nbsp;&nbsp;&nbsp;") tags)))
  1250. ;;;; Src Code
  1251. (defun org-e-html-fontify-code (code lang)
  1252. (when code
  1253. (cond
  1254. ;; Case 1: No lang. Possibly an example block.
  1255. ((not lang)
  1256. ;; Simple transcoding.
  1257. (org-e-html-encode-plain-text code))
  1258. ;; Case 2: No htmlize or an inferior version of htmlize
  1259. ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
  1260. ;; Emit a warning.
  1261. (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
  1262. ;; Simple transcoding.
  1263. (org-e-html-encode-plain-text code))
  1264. (t
  1265. ;; Map language
  1266. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1267. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1268. (cond
  1269. ;; Case 1: Language is not associated with any Emacs mode
  1270. ((not (functionp lang-mode))
  1271. ;; Simple transcoding.
  1272. (org-e-html-encode-plain-text code))
  1273. ;; Case 2: Default. Fontify code.
  1274. (t
  1275. ;; htmlize
  1276. (setq code (with-temp-buffer
  1277. (insert code)
  1278. ;; Switch to language-specific mode.
  1279. (funcall lang-mode)
  1280. ;; Fontify buffer.
  1281. (font-lock-fontify-buffer)
  1282. ;; Remove formatting on newline characters.
  1283. (save-excursion
  1284. (let ((beg (point-min))
  1285. (end (point-max)))
  1286. (goto-char beg)
  1287. (while (progn (end-of-line) (< (point) end))
  1288. (put-text-property (point) (1+ (point)) 'face nil)
  1289. (forward-char 1))))
  1290. (org-src-mode)
  1291. (set-buffer-modified-p nil)
  1292. ;; Htmlize region.
  1293. (org-export-e-htmlize-region-for-paste
  1294. (point-min) (point-max))))
  1295. ;; Strip any encolosing <pre></pre> tags.
  1296. (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
  1297. (match-string 1 code)
  1298. code))))))))
  1299. (defun org-e-html-do-format-code
  1300. (code &optional lang refs retain-labels num-start textarea-p)
  1301. (when textarea-p
  1302. (setq num-start nil refs nil lang nil))
  1303. (let* ((code-lines (org-split-string code "\n"))
  1304. (code-length (length code-lines))
  1305. (num-fmt
  1306. (and num-start
  1307. (format "%%%ds: "
  1308. (length (number-to-string (+ code-length num-start))))))
  1309. (code (org-e-html-fontify-code code lang)))
  1310. (assert (= code-length (length (org-split-string code "\n"))))
  1311. (org-export-format-code
  1312. code
  1313. (lambda (loc line-num ref)
  1314. (setq loc
  1315. (concat
  1316. ;; Add line number, if needed.
  1317. (when num-start
  1318. (format "<span class=\"linenr\">%s</span>"
  1319. (format num-fmt line-num)))
  1320. ;; Transcoded src line.
  1321. loc
  1322. ;; Add label, if needed.
  1323. (when (and ref retain-labels) (format " (%s)" ref))))
  1324. ;; Mark transcoded line as an anchor, if needed.
  1325. (if (not ref) loc
  1326. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  1327. ref loc)))
  1328. num-start refs)))
  1329. (defun org-e-html-format-code (element info)
  1330. (let* ((lang (org-element-property :language element))
  1331. ;; (switches (org-element-property :switches element))
  1332. (switches nil) ; FIXME
  1333. (textarea-p (and switches (string-match "-t\\>" switches)))
  1334. ;; Extract code and references.
  1335. (code-info (org-export-unravel-code element))
  1336. (code (car code-info))
  1337. (refs (cdr code-info))
  1338. ;; Does the src block contain labels?
  1339. (retain-labels (org-element-property :retain-labels element))
  1340. ;; Does it have line numbers?
  1341. (num-start (case (org-element-property :number-lines element)
  1342. (continued (org-export-get-loc element info))
  1343. (new 0))))
  1344. (org-e-html-do-format-code
  1345. code lang refs retain-labels num-start textarea-p)))
  1346. ;;; Transcode Functions
  1347. ;;;; Bold
  1348. (defun org-e-html-bold (bold contents info)
  1349. "Transcode BOLD from Org to HTML.
  1350. CONTENTS is the text with bold markup. INFO is a plist holding
  1351. contextual information."
  1352. (format (or (cdr (assq 'bold org-e-html-text-markup-alist)) "%s")
  1353. contents))
  1354. ;;;; Center Block
  1355. (defun org-e-html-center-block (center-block contents info)
  1356. "Transcode a CENTER-BLOCK element from Org to HTML.
  1357. CONTENTS holds the contents of the block. INFO is a plist
  1358. holding contextual information."
  1359. (format "<div style=\"text-align: center\">\n%s</div>" contents))
  1360. ;;;; Clock
  1361. (defun org-e-html-clock (clock contents info)
  1362. "Transcode a CLOCK element from Org to HTML.
  1363. CONTENTS is nil. INFO is a plist used as a communication
  1364. channel."
  1365. (format "<p>
  1366. <span class=\"timestamp-wrapper\">
  1367. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  1368. </span>
  1369. </p>"
  1370. org-clock-string
  1371. (org-translate-time
  1372. (org-element-property :raw-value
  1373. (org-element-property :value clock)))
  1374. (let ((time (org-element-property :duration clock)))
  1375. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1376. ;;;; Code
  1377. (defun org-e-html-code (code contents info)
  1378. "Transcode CODE from Org to HTML.
  1379. CONTENTS is nil. INFO is a plist holding contextual
  1380. information."
  1381. (format (or (cdr (assq 'code org-e-html-text-markup-alist)) "%s")
  1382. (org-element-property :value code)))
  1383. ;;;; Comment
  1384. ;; Comments are ignored.
  1385. ;;;; Comment Block
  1386. ;; Comment Blocks are ignored.
  1387. ;;;; Drawer
  1388. (defun org-e-html-drawer (drawer contents info)
  1389. "Transcode a DRAWER element from Org to HTML.
  1390. CONTENTS holds the contents of the block. INFO is a plist
  1391. holding contextual information."
  1392. (if (functionp org-e-html-format-drawer-function)
  1393. (funcall org-e-html-format-drawer-function
  1394. (org-element-property :drawer-name drawer)
  1395. contents)
  1396. ;; If there's no user defined function: simply
  1397. ;; display contents of the drawer.
  1398. contents))
  1399. ;;;; Dynamic Block
  1400. (defun org-e-html-dynamic-block (dynamic-block contents info)
  1401. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1402. CONTENTS holds the contents of the block. INFO is a plist
  1403. holding contextual information. See `org-export-data'."
  1404. contents)
  1405. ;;;; Entity
  1406. (defun org-e-html-entity (entity contents info)
  1407. "Transcode an ENTITY object from Org to HTML.
  1408. CONTENTS are the definition itself. INFO is a plist holding
  1409. contextual information."
  1410. (org-element-property :html entity))
  1411. ;;;; Example Block
  1412. (defun org-e-html-example-block (example-block contents info)
  1413. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  1414. CONTENTS is nil. INFO is a plist holding contextual information."
  1415. (let ((attr (org-export-read-attribute :attr_html example-block))
  1416. (code (org-e-html-format-code example-block info)))
  1417. (cond
  1418. ((plist-get attr :textarea)
  1419. (let ((cols (or (plist-get attr :width) 80))
  1420. (rows (or (plist-get attr :height) (org-count-lines code))))
  1421. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
  1422. cols rows code)))
  1423. (t (format "<pre class=\"example\">\n%s</pre>" code)))))
  1424. ;;;; Export Snippet
  1425. (defun org-e-html-export-snippet (export-snippet contents info)
  1426. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  1427. CONTENTS is nil. INFO is a plist holding contextual information."
  1428. (when (eq (org-export-snippet-backend export-snippet) 'e-html)
  1429. (org-element-property :value export-snippet)))
  1430. ;;;; Export Block
  1431. (defun org-e-html-export-block (export-block contents info)
  1432. "Transcode a EXPORT-BLOCK element from Org to HTML.
  1433. CONTENTS is nil. INFO is a plist holding contextual information."
  1434. (when (string= (org-element-property :type export-block) "HTML")
  1435. (org-remove-indentation (org-element-property :value export-block))))
  1436. ;;;; Fixed Width
  1437. (defun org-e-html-fixed-width (fixed-width contents info)
  1438. "Transcode a FIXED-WIDTH element from Org to HTML.
  1439. CONTENTS is nil. INFO is a plist holding contextual information."
  1440. (format "<pre class=\"example\">\n%s</pre>"
  1441. (org-e-html-do-format-code
  1442. (org-remove-indentation
  1443. (org-element-property :value fixed-width)))))
  1444. ;;;; Footnote Definition
  1445. ;; Footnote Definitions are ignored.
  1446. ;;;; Footnote Reference
  1447. (defun org-e-html-footnote-reference (footnote-reference contents info)
  1448. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  1449. CONTENTS is nil. INFO is a plist holding contextual information."
  1450. (concat
  1451. ;; Insert separator between two footnotes in a row.
  1452. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1453. (when (eq (org-element-type prev) 'footnote-reference)
  1454. org-e-html-footnote-separator))
  1455. (cond
  1456. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1457. (org-e-html-format-footnote-reference
  1458. (org-export-get-footnote-number footnote-reference info)
  1459. "IGNORED" 100))
  1460. ;; Inline definitions are secondary strings.
  1461. ((eq (org-element-property :type footnote-reference) 'inline)
  1462. (org-e-html-format-footnote-reference
  1463. (org-export-get-footnote-number footnote-reference info)
  1464. "IGNORED" 1))
  1465. ;; Non-inline footnotes definitions are full Org data.
  1466. (t (org-e-html-format-footnote-reference
  1467. (org-export-get-footnote-number footnote-reference info)
  1468. "IGNORED" 1)))))
  1469. ;;;; Headline
  1470. (defun org-e-html-format-headline--wrap (headline info
  1471. &optional format-function
  1472. &rest extra-keys)
  1473. "Transcode an HEADLINE element from Org to HTML.
  1474. CONTENTS holds the contents of the headline. INFO is a plist
  1475. holding contextual information."
  1476. (let* ((level (+ (org-export-get-relative-level headline info)
  1477. (1- org-e-html-toplevel-hlevel)))
  1478. (headline-number (org-export-get-headline-number headline info))
  1479. (section-number (and (not (org-export-low-level-p headline info))
  1480. (org-export-numbered-headline-p headline info)
  1481. (mapconcat 'number-to-string
  1482. headline-number ".")))
  1483. (todo (and (plist-get info :with-todo-keywords)
  1484. (let ((todo (org-element-property :todo-keyword headline)))
  1485. (and todo (org-export-data todo info)))))
  1486. (todo-type (and todo (org-element-property :todo-type headline)))
  1487. (priority (and (plist-get info :with-priority)
  1488. (org-element-property :priority headline)))
  1489. (text (org-export-data (org-element-property :title headline) info))
  1490. (tags (and (plist-get info :with-tags)
  1491. (org-export-get-tags headline info)))
  1492. (headline-label (or (org-element-property :custom-id headline)
  1493. (concat "sec-" (mapconcat 'number-to-string
  1494. headline-number "-"))))
  1495. (format-function (cond
  1496. ((functionp format-function) format-function)
  1497. ((functionp org-e-html-format-headline-function)
  1498. (function*
  1499. (lambda (todo todo-type priority text tags
  1500. &allow-other-keys)
  1501. (funcall org-e-html-format-headline-function
  1502. todo todo-type priority text tags))))
  1503. (t 'org-e-html-format-headline))))
  1504. (apply format-function
  1505. todo todo-type priority text tags
  1506. :headline-label headline-label :level level
  1507. :section-number section-number extra-keys)))
  1508. (defun org-e-html-headline (headline contents info)
  1509. "Transcode an HEADLINE element from Org to HTML.
  1510. CONTENTS holds the contents of the headline. INFO is a plist
  1511. holding contextual information."
  1512. ;; Empty contents?
  1513. (setq contents (or contents ""))
  1514. (let* ((numberedp (org-export-numbered-headline-p headline info))
  1515. (level (org-export-get-relative-level headline info))
  1516. (text (org-export-data (org-element-property :title headline) info))
  1517. (todo (and (plist-get info :with-todo-keywords)
  1518. (let ((todo (org-element-property :todo-keyword headline)))
  1519. (and todo (org-export-data todo info)))))
  1520. (todo-type (and todo (org-element-property :todo-type headline)))
  1521. (tags (and (plist-get info :with-tags)
  1522. (org-export-get-tags headline info)))
  1523. (priority (and (plist-get info :with-priority)
  1524. (org-element-property :priority headline)))
  1525. (section-number (and (org-export-numbered-headline-p headline info)
  1526. (mapconcat 'number-to-string
  1527. (org-export-get-headline-number
  1528. headline info) ".")))
  1529. ;; Create the headline text.
  1530. (full-text (org-e-html-format-headline--wrap headline info)))
  1531. (cond
  1532. ;; Case 1: This is a footnote section: ignore it.
  1533. ((org-element-property :footnote-section-p headline) nil)
  1534. ;; Case 2. This is a deep sub-tree: export it as a list item.
  1535. ;; Also export as items headlines for which no section
  1536. ;; format has been found.
  1537. ((org-export-low-level-p headline info)
  1538. ;; Build the real contents of the sub-tree.
  1539. (let* ((type (if numberedp 'ordered 'unordered))
  1540. (itemized-body (org-e-html-format-list-item
  1541. contents type nil nil full-text)))
  1542. (concat
  1543. (and (org-export-first-sibling-p headline info)
  1544. (org-e-html-begin-plain-list type))
  1545. itemized-body
  1546. (and (org-export-last-sibling-p headline info)
  1547. (org-e-html-end-plain-list type)))))
  1548. ;; Case 3. Standard headline. Export it as a section.
  1549. (t
  1550. (let* ((section-number (mapconcat 'number-to-string
  1551. (org-export-get-headline-number
  1552. headline info) "-"))
  1553. (ids (remove 'nil
  1554. (list (org-element-property :custom-id headline)
  1555. (concat "sec-" section-number)
  1556. (org-element-property :id headline))))
  1557. (preferred-id (car ids))
  1558. (extra-ids (cdr ids))
  1559. (extra-class (org-element-property :html-container-class headline))
  1560. (level1 (+ level (1- org-e-html-toplevel-hlevel))))
  1561. (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
  1562. (format "outline-container-%s"
  1563. (or (org-element-property :custom-id headline)
  1564. section-number))
  1565. (concat (format "outline-%d" level1) (and extra-class " ")
  1566. extra-class)
  1567. (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  1568. level1
  1569. preferred-id
  1570. (mapconcat
  1571. (lambda (x)
  1572. (let ((id (org-export-solidify-link-text
  1573. (if (org-uuidgen-p x) (concat "ID-" x)
  1574. x))))
  1575. (org-e-html--anchor id)))
  1576. extra-ids "")
  1577. full-text
  1578. level1)
  1579. contents))))))
  1580. ;;;; Horizontal Rule
  1581. (defun org-e-html-horizontal-rule (horizontal-rule contents info)
  1582. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  1583. CONTENTS is nil. INFO is a plist holding contextual information."
  1584. "<hr/>")
  1585. ;;;; Inline Babel Call
  1586. ;; Inline Babel Calls are ignored.
  1587. ;;;; Inline Src Block
  1588. (defun org-e-html-inline-src-block (inline-src-block contents info)
  1589. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  1590. CONTENTS holds the contents of the item. INFO is a plist holding
  1591. contextual information."
  1592. (let* ((org-lang (org-element-property :language inline-src-block))
  1593. (code (org-element-property :value inline-src-block)))
  1594. (error "FIXME")))
  1595. ;;;; Inlinetask
  1596. (defun org-e-html-format-section (text class &optional id)
  1597. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  1598. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  1599. (defun org-e-html-inlinetask (inlinetask contents info)
  1600. "Transcode an INLINETASK element from Org to HTML.
  1601. CONTENTS holds the contents of the block. INFO is a plist
  1602. holding contextual information."
  1603. (cond
  1604. ;; If `org-e-html-format-inlinetask-function' is provided, call it
  1605. ;; with appropriate arguments.
  1606. ((functionp org-e-html-format-inlinetask-function)
  1607. (let ((format-function
  1608. (function*
  1609. (lambda (todo todo-type priority text tags
  1610. &key contents &allow-other-keys)
  1611. (funcall org-e-html-format-inlinetask-function
  1612. todo todo-type priority text tags contents)))))
  1613. (org-e-html-format-headline--wrap
  1614. inlinetask info format-function :contents contents)))
  1615. ;; Otherwise, use a default template.
  1616. (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
  1617. (org-e-html-format-headline--wrap inlinetask info)
  1618. contents))))
  1619. ;;;; Italic
  1620. (defun org-e-html-italic (italic contents info)
  1621. "Transcode ITALIC from Org to HTML.
  1622. CONTENTS is the text with italic markup. INFO is a plist holding
  1623. contextual information."
  1624. (format (or (cdr (assq 'italic org-e-html-text-markup-alist)) "%s") contents))
  1625. ;;;; Item
  1626. (defun org-e-html-checkbox (checkbox)
  1627. (case checkbox (on "<code>[X]</code>")
  1628. (off "<code>[&nbsp;]</code>")
  1629. (trans "<code>[-]</code>")
  1630. (t "")))
  1631. (defun org-e-html-format-list-item (contents type checkbox
  1632. &optional term-counter-id
  1633. headline)
  1634. (let ((checkbox (concat (org-e-html-checkbox checkbox) (and checkbox " "))))
  1635. (concat
  1636. (case type
  1637. (ordered
  1638. (let* ((counter term-counter-id)
  1639. (extra (if counter (format " value=\"%s\"" counter) "")))
  1640. (concat
  1641. (format "<li%s>" extra)
  1642. (when headline (concat headline "<br/>")))))
  1643. (unordered
  1644. (let* ((id term-counter-id)
  1645. (extra (if id (format " id=\"%s\"" id) "")))
  1646. (concat
  1647. (format "<li%s>" extra)
  1648. (when headline (concat headline "<br/>")))))
  1649. (descriptive
  1650. (let* ((term term-counter-id))
  1651. (setq term (or term "(no term)"))
  1652. ;; Check-boxes in descriptive lists are associated to tag.
  1653. (concat (format "<dt> %s </dt>"
  1654. (concat checkbox term))
  1655. "<dd>"))))
  1656. (unless (eq type 'descriptive) checkbox)
  1657. contents
  1658. (case type
  1659. (ordered "</li>")
  1660. (unordered "</li>")
  1661. (descriptive "</dd>")))))
  1662. (defun org-e-html-item (item contents info)
  1663. "Transcode an ITEM element from Org to HTML.
  1664. CONTENTS holds the contents of the item. INFO is a plist holding
  1665. contextual information."
  1666. (let* ((plain-list (org-export-get-parent item))
  1667. (type (org-element-property :type plain-list))
  1668. (counter (org-element-property :counter item))
  1669. (checkbox (org-element-property :checkbox item))
  1670. (tag (let ((tag (org-element-property :tag item)))
  1671. (and tag (org-export-data tag info)))))
  1672. (org-e-html-format-list-item
  1673. contents type checkbox (or tag counter))))
  1674. ;;;; Keyword
  1675. (defun org-e-html-keyword (keyword contents info)
  1676. "Transcode a KEYWORD element from Org to HTML.
  1677. CONTENTS is nil. INFO is a plist holding contextual information."
  1678. (let ((key (org-element-property :key keyword))
  1679. (value (org-element-property :value keyword)))
  1680. (cond
  1681. ((string= key "HTML") value)
  1682. ((string= key "INDEX") (format "\\index{%s}" value))
  1683. ;; Invisible targets.
  1684. ((string= key "TARGET") nil)
  1685. ((string= key "TOC")
  1686. (let ((value (downcase value)))
  1687. (cond
  1688. ((string-match "\\<headlines\\>" value)
  1689. (let ((depth (or (and (string-match "[0-9]+" value)
  1690. (string-to-number (match-string 0 value)))
  1691. (plist-get info :with-toc))))
  1692. (org-e-html-toc depth info)))
  1693. ((string= "tables" value) "\\listoftables")
  1694. ((string= "figures" value) "\\listoffigures")
  1695. ((string= "listings" value)
  1696. (cond
  1697. ;; At the moment, src blocks with a caption are wrapped
  1698. ;; into a figure environment.
  1699. (t "\\listoffigures")))))))))
  1700. ;;;; Latex Environment
  1701. (defun org-e-html-format-latex (latex-frag processing-type)
  1702. (let* ((cache-relpath
  1703. (concat "ltxpng/" (file-name-sans-extension
  1704. (file-name-nondirectory (buffer-file-name)))))
  1705. (cache-dir (file-name-directory (buffer-file-name )))
  1706. (display-msg "Creating LaTeX Image..."))
  1707. (with-temp-buffer
  1708. (insert latex-frag)
  1709. (org-format-latex cache-relpath cache-dir nil display-msg
  1710. nil nil processing-type)
  1711. (buffer-string))))
  1712. (defun org-e-html-latex-environment (latex-environment contents info)
  1713. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  1714. CONTENTS is nil. INFO is a plist holding contextual information."
  1715. (let ((processing-type (plist-get info :LaTeX-fragments))
  1716. (latex-frag (org-remove-indentation
  1717. (org-element-property :value latex-environment)))
  1718. (caption (org-export-data
  1719. (org-export-get-caption latex-environment) info))
  1720. (attr nil) ; FIXME
  1721. (label (org-element-property :name latex-environment)))
  1722. (cond
  1723. ((memq processing-type '(t mathjax))
  1724. (org-e-html-format-latex latex-frag 'mathjax))
  1725. ((eq processing-type 'dvipng)
  1726. (let* ((formula-link (org-e-html-format-latex
  1727. latex-frag processing-type)))
  1728. (when (and formula-link
  1729. (string-match "file:\\([^]]*\\)" formula-link))
  1730. (org-e-html-format-inline-image
  1731. (match-string 1 formula-link) caption label attr t))))
  1732. (t latex-frag))))
  1733. ;;;; Latex Fragment
  1734. (defun org-e-html-latex-fragment (latex-fragment contents info)
  1735. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  1736. CONTENTS is nil. INFO is a plist holding contextual information."
  1737. (let ((latex-frag (org-element-property :value latex-fragment))
  1738. (processing-type (plist-get info :LaTeX-fragments)))
  1739. (case processing-type
  1740. ((t mathjax)
  1741. (org-e-html-format-latex latex-frag 'mathjax))
  1742. (dvipng
  1743. (let* ((formula-link (org-e-html-format-latex
  1744. latex-frag processing-type)))
  1745. (when (and formula-link
  1746. (string-match "file:\\([^]]*\\)" formula-link))
  1747. (org-e-html-format-inline-image
  1748. (match-string 1 formula-link)))))
  1749. (t latex-frag))))
  1750. ;;;; Line Break
  1751. (defun org-e-html-line-break (line-break contents info)
  1752. "Transcode a LINE-BREAK object from Org to HTML.
  1753. CONTENTS is nil. INFO is a plist holding contextual information."
  1754. "<br/>")
  1755. ;;;; Link
  1756. (defun org-e-html-link--inline-image (link desc info)
  1757. "Return HTML code for an inline image.
  1758. LINK is the link pointing to the inline image. INFO is a plist
  1759. used as a communication channel."
  1760. (let* ((type (org-element-property :type link))
  1761. (raw-path (org-element-property :path link))
  1762. (path (cond ((member type '("http" "https"))
  1763. (concat type ":" raw-path))
  1764. ((file-name-absolute-p raw-path)
  1765. (expand-file-name raw-path))
  1766. (t raw-path)))
  1767. (parent (org-export-get-parent-element link))
  1768. (caption (org-export-data (org-export-get-caption parent) info))
  1769. (label (org-element-property :name parent))
  1770. ;; Retrieve latex attributes from the element around.
  1771. (attr (let ((raw-attr
  1772. (mapconcat #'identity
  1773. (org-element-property :attr_html parent)
  1774. " ")))
  1775. (unless (string= raw-attr "") raw-attr))))
  1776. ;; Now clear ATTR from any special keyword and set a default
  1777. ;; value if nothing is left.
  1778. (setq attr (if (not attr) "" (org-trim attr)))
  1779. ;; Return proper string, depending on DISPOSITION.
  1780. (org-e-html-format-inline-image
  1781. path caption label attr (org-e-html-standalone-image-p link info))))
  1782. (defvar org-e-html-standalone-image-predicate)
  1783. (defun org-e-html-standalone-image-p (element info &optional predicate)
  1784. "Test if ELEMENT is a standalone image for the purpose HTML export.
  1785. INFO is a plist holding contextual information.
  1786. Return non-nil, if ELEMENT is of type paragraph and it's sole
  1787. content, save for whitespaces, is a link that qualifies as an
  1788. inline image.
  1789. Return non-nil, if ELEMENT is of type link and it's containing
  1790. paragraph has no other content save for leading and trailing
  1791. whitespaces.
  1792. Return nil, otherwise.
  1793. Bind `org-e-html-standalone-image-predicate' to constrain
  1794. paragraph further. For example, to check for only captioned
  1795. standalone images, do the following.
  1796. \(setq org-e-html-standalone-image-predicate
  1797. \(lambda \(paragraph\)
  1798. \(org-element-property :caption paragraph\)\)\)
  1799. "
  1800. (let ((paragraph (case (org-element-type element)
  1801. (paragraph element)
  1802. (link (and (org-export-inline-image-p
  1803. element org-e-html-inline-image-rules)
  1804. (org-export-get-parent element)))
  1805. (t nil))))
  1806. (when (eq (org-element-type paragraph) 'paragraph)
  1807. (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
  1808. (functionp org-e-html-standalone-image-predicate)))
  1809. (funcall org-e-html-standalone-image-predicate paragraph))
  1810. (let ((contents (org-element-contents paragraph)))
  1811. (loop for x in contents
  1812. with inline-image-count = 0
  1813. always (cond
  1814. ((eq (org-element-type x) 'plain-text)
  1815. (not (org-string-nw-p x)))
  1816. ((eq (org-element-type x) 'link)
  1817. (when (org-export-inline-image-p
  1818. x org-e-html-inline-image-rules)
  1819. (= (incf inline-image-count) 1)))
  1820. (t nil))))))))
  1821. (defun org-e-html-link (link desc info)
  1822. "Transcode a LINK object from Org to HTML.
  1823. DESC is the description part of the link, or the empty string.
  1824. INFO is a plist holding contextual information. See
  1825. `org-export-data'."
  1826. (let* ((--link-org-files-as-html-maybe
  1827. (function
  1828. (lambda (raw-path info)
  1829. "Treat links to `file.org' as links to `file.html', if needed.
  1830. See `org-e-html-link-org-files-as-html'."
  1831. (cond
  1832. ((and org-e-html-link-org-files-as-html
  1833. (string= ".org"
  1834. (downcase (file-name-extension raw-path "."))))
  1835. (concat (file-name-sans-extension raw-path) "."
  1836. (plist-get info :html-extension)))
  1837. (t raw-path)))))
  1838. (type (org-element-property :type link))
  1839. (raw-path (org-element-property :path link))
  1840. ;; Ensure DESC really exists, or set it to nil.
  1841. (desc (and (not (string= desc "")) desc))
  1842. (path (cond
  1843. ((member type '("http" "https" "ftp" "mailto"))
  1844. (concat type ":" raw-path))
  1845. ((string= type "file")
  1846. ;; Treat links to ".org" files as ".html", if needed.
  1847. (setq raw-path (funcall --link-org-files-as-html-maybe
  1848. raw-path info))
  1849. ;; If file path is absolute, prepend it with protocol
  1850. ;; component - "file://".
  1851. (if (not (file-name-absolute-p raw-path)) raw-path
  1852. (concat "file://" (expand-file-name raw-path))))
  1853. (t raw-path)))
  1854. ;; Extract attributes from parent's paragraph.
  1855. (attributes
  1856. (let ((attr (mapconcat
  1857. 'identity
  1858. (org-element-property
  1859. :attr_html (org-export-get-parent-element link))
  1860. " ")))
  1861. (if attr (concat " " attr) "")))
  1862. protocol)
  1863. (cond
  1864. ;; Image file.
  1865. ((and (or (eq t org-e-html-inline-images)
  1866. (and org-e-html-inline-images (not desc)))
  1867. (org-export-inline-image-p link org-e-html-inline-image-rules))
  1868. (org-e-html-link--inline-image link desc info))
  1869. ;; Radio target: Transcode target's contents and use them as
  1870. ;; link's description.
  1871. ((string= type "radio")
  1872. (let ((destination (org-export-resolve-radio-link link info)))
  1873. (when destination
  1874. (format "<a href=\"#%s\"%s>%s</a>"
  1875. (org-export-solidify-link-text path)
  1876. attributes
  1877. (org-export-data (org-element-contents destination) info)))))
  1878. ;; Links pointing to an headline: Find destination and build
  1879. ;; appropriate referencing command.
  1880. ((member type '("custom-id" "fuzzy" "id"))
  1881. (let ((destination (if (string= type "fuzzy")
  1882. (org-export-resolve-fuzzy-link link info)
  1883. (org-export-resolve-id-link link info))))
  1884. (case (org-element-type destination)
  1885. ;; ID link points to an external file.
  1886. (plain-text
  1887. (assert (org-uuidgen-p path))
  1888. (let ((fragment (concat "ID-" path))
  1889. ;; Treat links to ".org" files as ".html", if needed.
  1890. (path (funcall --link-org-files-as-html-maybe
  1891. destination info)))
  1892. (format "<a href=\"%s#%s\"%s>%s</a>"
  1893. path fragment attributes (or desc destination))))
  1894. ;; Fuzzy link points nowhere.
  1895. ((nil)
  1896. (format "<i>%s</i>"
  1897. (or desc
  1898. (org-export-data
  1899. (org-element-property :raw-link link) info))))
  1900. ;; Fuzzy link points to an invisible target.
  1901. (keyword nil)
  1902. ;; Link points to an headline.
  1903. (headline
  1904. (let ((href
  1905. ;; What href to use?
  1906. (cond
  1907. ;; Case 1: Headline is linked via it's CUSTOM_ID
  1908. ;; property. Use CUSTOM_ID.
  1909. ((string= type "custom-id")
  1910. (org-element-property :custom-id destination))
  1911. ;; Case 2: Headline is linked via it's ID property
  1912. ;; or through other means. Use the default href.
  1913. ((member type '("id" "fuzzy"))
  1914. (format "sec-%s"
  1915. (mapconcat 'number-to-string
  1916. (org-export-get-headline-number
  1917. destination info) "-")))
  1918. (t (error "Shouldn't reach here"))))
  1919. ;; What description to use?
  1920. (desc
  1921. ;; Case 1: Headline is numbered and LINK has no
  1922. ;; description or LINK's description matches
  1923. ;; headline's title. Display section number.
  1924. (if (and (org-export-numbered-headline-p destination info)
  1925. (or (not desc)
  1926. (string= desc (org-element-property
  1927. :raw-value destination))))
  1928. (mapconcat 'number-to-string
  1929. (org-export-get-headline-number
  1930. destination info) ".")
  1931. ;; Case 2: Either the headline is un-numbered or
  1932. ;; LINK has a custom description. Display LINK's
  1933. ;; description or headline's title.
  1934. (or desc (org-export-data (org-element-property
  1935. :title destination) info)))))
  1936. (format "<a href=\"#%s\"%s>%s</a>"
  1937. (org-export-solidify-link-text href) attributes desc)))
  1938. ;; Fuzzy link points to a target. Do as above.
  1939. (t
  1940. (let ((path (org-export-solidify-link-text path)) number)
  1941. (unless desc
  1942. (setq number (cond
  1943. ((org-e-html-standalone-image-p destination info)
  1944. (org-export-get-ordinal
  1945. (assoc 'link (org-element-contents destination))
  1946. info 'link 'org-e-html-standalone-image-p))
  1947. (t (org-export-get-ordinal destination info))))
  1948. (setq desc (when number
  1949. (if (atom number) (number-to-string number)
  1950. (mapconcat 'number-to-string number ".")))))
  1951. (format "<a href=\"#%s\"%s>%s</a>"
  1952. path attributes (or desc "FIXME")))))))
  1953. ;; Coderef: replace link with the reference name or the
  1954. ;; equivalent line number.
  1955. ((string= type "coderef")
  1956. (let ((fragment (concat "coderef-" path)))
  1957. (format "<a href=\"#%s\" %s%s>%s</a>"
  1958. fragment
  1959. (format (concat "class=\"coderef\""
  1960. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  1961. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  1962. fragment fragment)
  1963. attributes
  1964. (format (org-export-get-coderef-format path desc)
  1965. (org-export-resolve-coderef path info)))))
  1966. ;; Link type is handled by a special function.
  1967. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  1968. (funcall protocol (org-link-unescape path) desc 'html))
  1969. ;; External link with a description part.
  1970. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  1971. ;; External link without a description part.
  1972. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  1973. ;; No path, only description. Try to do something useful.
  1974. (t (format "<i>%s</i>" desc)))))
  1975. ;;;; Paragraph
  1976. (defun org-e-html-paragraph (paragraph contents info)
  1977. "Transcode a PARAGRAPH element from Org to HTML.
  1978. CONTENTS is the contents of the paragraph, as a string. INFO is
  1979. the plist used as a communication channel."
  1980. (let* ((style nil) ; FIXME
  1981. (class (cdr (assoc style '((footnote . "footnote")
  1982. (verse . nil)))))
  1983. (extra (if class (format " class=\"%s\"" class) ""))
  1984. (parent (org-export-get-parent paragraph)))
  1985. (cond
  1986. ((and (eq (org-element-type parent) 'item)
  1987. (= (org-element-property :begin paragraph)
  1988. (org-element-property :contents-begin parent)))
  1989. ;; leading paragraph in a list item have no tags
  1990. contents)
  1991. ((org-e-html-standalone-image-p paragraph info)
  1992. ;; standalone image
  1993. contents)
  1994. (t (format "<p%s>\n%s</p>" extra contents)))))
  1995. ;;;; Plain List
  1996. (defun org-e-html-begin-plain-list (type &optional arg1)
  1997. (case type
  1998. (ordered
  1999. (format "<ol%s>" (if arg1 ; FIXME
  2000. (format " start=\"%d\"" arg1)
  2001. "")))
  2002. (unordered "<ul>")
  2003. (descriptive "<dl>")))
  2004. (defun org-e-html-end-plain-list (type)
  2005. (case type
  2006. (ordered "</ol>")
  2007. (unordered "</ul>")
  2008. (descriptive "</dl>")))
  2009. (defun org-e-html-plain-list (plain-list contents info)
  2010. "Transcode a PLAIN-LIST element from Org to HTML.
  2011. CONTENTS is the contents of the list. INFO is a plist holding
  2012. contextual information."
  2013. (let* (arg1 ;; FIXME
  2014. (type (org-element-property :type plain-list)))
  2015. (format "%s\n%s%s"
  2016. (org-e-html-begin-plain-list type)
  2017. contents (org-e-html-end-plain-list type))))
  2018. ;;;; Plain Text
  2019. (defun org-e-html-convert-special-strings (string)
  2020. "Convert special characters in STRING to HTML."
  2021. (let ((all org-e-html-special-string-regexps)
  2022. e a re rpl start)
  2023. (while (setq a (pop all))
  2024. (setq re (car a) rpl (cdr a) start 0)
  2025. (while (string-match re string start)
  2026. (setq string (replace-match rpl t nil string))))
  2027. string))
  2028. (defun org-e-html-encode-plain-text (text)
  2029. "Convert plain text characters to HTML equivalent.
  2030. Possible conversions are set in `org-export-html-protect-char-alist'."
  2031. (mapc
  2032. (lambda (pair)
  2033. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  2034. org-e-html-protect-char-alist)
  2035. text)
  2036. (defun org-e-html-plain-text (text info)
  2037. "Transcode a TEXT string from Org to HTML.
  2038. TEXT is the string to transcode. INFO is a plist holding
  2039. contextual information."
  2040. (let ((output text))
  2041. ;; Protect following characters: <, >, &.
  2042. (setq output (org-e-html-encode-plain-text output))
  2043. ;; Handle smart quotes. Be sure to provide original string since
  2044. ;; OUTPUT may have been modified.
  2045. (when (plist-get info :with-smart-quotes)
  2046. (setq output (org-export-activate-smart-quotes output :html info text)))
  2047. ;; Handle special strings.
  2048. (when (plist-get info :with-special-strings)
  2049. (setq output (org-e-html-convert-special-strings output)))
  2050. ;; Handle break preservation if required.
  2051. (when (plist-get info :preserve-breaks)
  2052. (setq output
  2053. (replace-regexp-in-string
  2054. "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
  2055. ;; Return value.
  2056. output))
  2057. ;; Planning
  2058. (defun org-e-html-planning (planning contents info)
  2059. "Transcode a PLANNING element from Org to HTML.
  2060. CONTENTS is nil. INFO is a plist used as a communication
  2061. channel."
  2062. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2063. (format
  2064. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2065. (mapconcat
  2066. 'identity
  2067. (delq nil
  2068. (list
  2069. (let ((closed (org-element-property :closed planning)))
  2070. (when closed
  2071. (format span-fmt org-closed-string
  2072. (org-translate-time
  2073. (org-element-property :raw-value closed)))))
  2074. (let ((deadline (org-element-property :deadline planning)))
  2075. (when deadline
  2076. (format span-fmt org-deadline-string
  2077. (org-translate-time
  2078. (org-element-property :raw-value deadline)))))
  2079. (let ((scheduled (org-element-property :scheduled planning)))
  2080. (when scheduled
  2081. (format span-fmt org-scheduled-string
  2082. (org-translate-time
  2083. (org-element-property :raw-value scheduled)))))))
  2084. " "))))
  2085. ;;;; Property Drawer
  2086. (defun org-e-html-property-drawer (property-drawer contents info)
  2087. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2088. CONTENTS is nil. INFO is a plist holding contextual
  2089. information."
  2090. ;; The property drawer isn't exported but we want separating blank
  2091. ;; lines nonetheless.
  2092. "")
  2093. ;;;; Quote Block
  2094. (defun org-e-html-quote-block (quote-block contents info)
  2095. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2096. CONTENTS holds the contents of the block. INFO is a plist
  2097. holding contextual information."
  2098. (format "<blockquote>\n%s</blockquote>" contents))
  2099. ;;;; Quote Section
  2100. (defun org-e-html-quote-section (quote-section contents info)
  2101. "Transcode a QUOTE-SECTION element from Org to HTML.
  2102. CONTENTS is nil. INFO is a plist holding contextual information."
  2103. (let ((value (org-remove-indentation
  2104. (org-element-property :value quote-section))))
  2105. (when value (format "<pre>\n%s</pre>" value))))
  2106. ;;;; Section
  2107. (defun org-e-html-section (section contents info)
  2108. "Transcode a SECTION element from Org to HTML.
  2109. CONTENTS holds the contents of the section. INFO is a plist
  2110. holding contextual information."
  2111. (let ((parent (org-export-get-parent-headline section)))
  2112. ;; Before first headline: no container, just return CONTENTS.
  2113. (if (not parent) contents
  2114. ;; Get div's class and id references.
  2115. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2116. (1- org-e-html-toplevel-hlevel)))
  2117. (section-number
  2118. (mapconcat
  2119. 'number-to-string
  2120. (org-export-get-headline-number parent info) "-")))
  2121. ;; Build return value.
  2122. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2123. class-num
  2124. (or (org-element-property :custom-id parent) section-number)
  2125. contents)))))
  2126. ;;;; Radio Target
  2127. (defun org-e-html-radio-target (radio-target text info)
  2128. "Transcode a RADIO-TARGET object from Org to HTML.
  2129. TEXT is the text of the target. INFO is a plist holding
  2130. contextual information."
  2131. (let ((id (org-export-solidify-link-text
  2132. (org-element-property :value radio-target))))
  2133. (org-e-html--anchor id text)))
  2134. ;;;; Special Block
  2135. (defun org-e-html-special-block (special-block contents info)
  2136. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2137. CONTENTS holds the contents of the block. INFO is a plist
  2138. holding contextual information."
  2139. (format "<div class=\"%s\">\n%s\n</div>"
  2140. (downcase (org-element-property :type special-block))
  2141. contents))
  2142. ;;;; Src Block
  2143. (defun org-e-html-src-block (src-block contents info)
  2144. "Transcode a SRC-BLOCK element from Org to HTML.
  2145. CONTENTS holds the contents of the item. INFO is a plist holding
  2146. contextual information."
  2147. (let ((lang (org-element-property :language src-block))
  2148. (caption (org-export-get-caption src-block))
  2149. (attr (org-export-read-attribute :attr_html src-block))
  2150. (code (org-e-html-format-code src-block info)))
  2151. (cond
  2152. (lang
  2153. (format "<div class=\"org-src-container\">\n%s%s\n</div>"
  2154. (if (not caption) ""
  2155. (format "<label class=\"org-src-name\">%s</label>"
  2156. (org-export-data caption info)))
  2157. (format "\n<pre class=\"src src-%s\">%s</pre>" lang code)))
  2158. ((plist-get attr :textarea)
  2159. (let ((cols (or (plist-get attr :width) 80))
  2160. (rows (or (plist-get attr :height) (org-count-lines code))))
  2161. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
  2162. cols rows code)))
  2163. (t (format "<pre class=\"example\">\n%s</pre>" code)))))
  2164. ;;;; Statistics Cookie
  2165. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  2166. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2167. CONTENTS is nil. INFO is a plist holding contextual information."
  2168. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2169. (format "<code>%s</code>" cookie-value)))
  2170. ;;;; Strike-Through
  2171. (defun org-e-html-strike-through (strike-through contents info)
  2172. "Transcode STRIKE-THROUGH from Org to HTML.
  2173. CONTENTS is the text with strike-through markup. INFO is a plist
  2174. holding contextual information."
  2175. (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist)) "%s")
  2176. contents))
  2177. ;;;; Subscript
  2178. (defun org-e-html-subscript (subscript contents info)
  2179. "Transcode a SUBSCRIPT object from Org to HTML.
  2180. CONTENTS is the contents of the object. INFO is a plist holding
  2181. contextual information."
  2182. (format "<sub>%s</sub>" contents))
  2183. ;;;; Superscript
  2184. (defun org-e-html-superscript (superscript contents info)
  2185. "Transcode a SUPERSCRIPT object from Org to HTML.
  2186. CONTENTS is the contents of the object. INFO is a plist holding
  2187. contextual information."
  2188. (format "<sup>%s</sup>" contents))
  2189. ;;;; Tabel Cell
  2190. (defun org-e-html-table-cell (table-cell contents info)
  2191. "Transcode a TABLE-CELL element from Org to HTML.
  2192. CONTENTS is nil. INFO is a plist used as a communication
  2193. channel."
  2194. (let* ((table-row (org-export-get-parent table-cell))
  2195. (table (org-export-get-parent-table table-cell))
  2196. (cell-attrs
  2197. (if (not org-e-html-table-align-individual-fields) ""
  2198. (format (if (and (boundp 'org-e-html-format-table-no-css)
  2199. org-e-html-format-table-no-css)
  2200. " align=\"%s\"" " class=\"%s\"")
  2201. (org-export-table-cell-alignment table-cell info)))))
  2202. (when (or (not contents) (string= "" (org-trim contents)))
  2203. (setq contents "&nbsp;"))
  2204. (cond
  2205. ((and (org-export-table-has-header-p table info)
  2206. (= 1 (org-export-table-row-group table-row info)))
  2207. (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
  2208. contents (cdr org-e-html-table-header-tags)))
  2209. ((and org-e-html-table-use-header-tags-for-first-column
  2210. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2211. (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
  2212. contents (cdr org-e-html-table-header-tags)))
  2213. (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
  2214. contents (cdr org-e-html-table-data-tags))))))
  2215. ;;;; Table Row
  2216. (defun org-e-html-table-row (table-row contents info)
  2217. "Transcode a TABLE-ROW element from Org to HTML.
  2218. CONTENTS is the contents of the row. INFO is a plist used as a
  2219. communication channel."
  2220. ;; Rules are ignored since table separators are deduced from
  2221. ;; borders of the current row.
  2222. (when (eq (org-element-property :type table-row) 'standard)
  2223. (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
  2224. (rowgroup-tags
  2225. (cond
  2226. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2227. ((not (= 1 (org-export-table-row-group table-row info)))
  2228. '("<tbody>" . "\n</tbody>"))
  2229. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2230. ((org-export-table-has-header-p
  2231. (org-export-get-parent-table table-row) info)
  2232. '("<thead>" . "\n</thead>"))
  2233. ;; Case 2: Row is from first and only row group.
  2234. (t '("<tbody>" . "\n</tbody>")))))
  2235. (concat
  2236. ;; Begin a rowgroup?
  2237. (when (org-export-table-row-starts-rowgroup-p table-row info)
  2238. (car rowgroup-tags))
  2239. ;; Actual table row
  2240. (concat "\n" (eval (car org-e-html-table-row-tags))
  2241. contents
  2242. "\n"
  2243. (eval (cdr org-e-html-table-row-tags)))
  2244. ;; End a rowgroup?
  2245. (when (org-export-table-row-ends-rowgroup-p table-row info)
  2246. (cdr rowgroup-tags))))))
  2247. ;;;; Table
  2248. (defun org-e-html-table-first-row-data-cells (table info)
  2249. (let ((table-row
  2250. (org-element-map
  2251. table 'table-row
  2252. (lambda (row)
  2253. (unless (eq (org-element-property :type row) 'rule) row))
  2254. info 'first-match))
  2255. (special-column-p (org-export-table-has-special-column-p table)))
  2256. (if (not special-column-p) (org-element-contents table-row)
  2257. (cdr (org-element-contents table-row)))))
  2258. (defun org-e-html-table--table.el-table (table info)
  2259. (when (eq (org-element-property :type table) 'table.el)
  2260. (require 'table)
  2261. (let ((outbuf (with-current-buffer
  2262. (get-buffer-create "*org-export-table*")
  2263. (erase-buffer) (current-buffer))))
  2264. (with-temp-buffer
  2265. (insert (org-element-property :value table))
  2266. (goto-char 1)
  2267. (re-search-forward "^[ \t]*|[^|]" nil t)
  2268. (table-generate-source 'html outbuf))
  2269. (with-current-buffer outbuf
  2270. (prog1 (org-trim (buffer-string))
  2271. (kill-buffer) )))))
  2272. (defun org-e-html-table (table contents info)
  2273. "Transcode a TABLE element from Org to HTML.
  2274. CONTENTS is the contents of the table. INFO is a plist holding
  2275. contextual information."
  2276. (case (org-element-property :type table)
  2277. ;; Case 1: table.el table. Convert it using appropriate tools.
  2278. (table.el (org-e-html-table--table.el-table table info))
  2279. ;; Case 2: Standard table.
  2280. (t
  2281. (let* ((label (org-element-property :name table))
  2282. (caption (org-export-get-caption table))
  2283. (attributes (mapconcat #'identity
  2284. (org-element-property :attr_html table)
  2285. " "))
  2286. (alignspec
  2287. (if (and (boundp 'org-e-html-format-table-no-css)
  2288. org-e-html-format-table-no-css)
  2289. "align=\"%s\"" "class=\"%s\""))
  2290. (table-column-specs
  2291. (function
  2292. (lambda (table info)
  2293. (mapconcat
  2294. (lambda (table-cell)
  2295. (let ((alignment (org-export-table-cell-alignment
  2296. table-cell info)))
  2297. (concat
  2298. ;; Begin a colgroup?
  2299. (when (org-export-table-cell-starts-colgroup-p
  2300. table-cell info)
  2301. "\n<colgroup>")
  2302. ;; Add a column. Also specify it's alignment.
  2303. (format "\n<col %s/>" (format alignspec alignment))
  2304. ;; End a colgroup?
  2305. (when (org-export-table-cell-ends-colgroup-p
  2306. table-cell info)
  2307. "\n</colgroup>"))))
  2308. (org-e-html-table-first-row-data-cells table info) "\n"))))
  2309. (table-attributes
  2310. (let ((table-tag (plist-get info :html-table-tag)))
  2311. (concat
  2312. (and (string-match "<table\\(.*\\)>" table-tag)
  2313. (match-string 1 table-tag))
  2314. (and label (format " id=\"%s\""
  2315. (org-export-solidify-link-text label)))))))
  2316. ;; Remove last blank line.
  2317. (setq contents (substring contents 0 -1))
  2318. (format "<table%s>\n%s\n%s\n%s\n</table>"
  2319. table-attributes
  2320. (if (not caption) ""
  2321. (format "<caption>%s</caption>"
  2322. (org-export-data caption info)))
  2323. (funcall table-column-specs table info)
  2324. contents)))))
  2325. ;;;; Target
  2326. (defun org-e-html-target (target contents info)
  2327. "Transcode a TARGET object from Org to HTML.
  2328. CONTENTS is nil. INFO is a plist holding contextual
  2329. information."
  2330. (let ((id (org-export-solidify-link-text
  2331. (org-element-property :value target))))
  2332. (org-e-html--anchor id)))
  2333. ;;;; Timestamp
  2334. (defun org-e-html-timestamp (timestamp contents info)
  2335. "Transcode a TIMESTAMP object from Org to HTML.
  2336. CONTENTS is nil. INFO is a plist holding contextual
  2337. information."
  2338. (let ((value (org-e-html-plain-text
  2339. (org-export-translate-timestamp timestamp) info)))
  2340. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  2341. (replace-regexp-in-string "--" "&ndash;" value))))
  2342. ;;;; Underline
  2343. (defun org-e-html-underline (underline contents info)
  2344. "Transcode UNDERLINE from Org to HTML.
  2345. CONTENTS is the text with underline markup. INFO is a plist
  2346. holding contextual information."
  2347. (format (or (cdr (assq 'underline org-e-html-text-markup-alist)) "%s")
  2348. contents))
  2349. ;;;; Verbatim
  2350. (defun org-e-html-verbatim (verbatim contents info)
  2351. "Transcode VERBATIM from Org to HTML.
  2352. CONTENTS is nil. INFO is a plist holding contextual
  2353. information."
  2354. (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist)) "%s")
  2355. (org-element-property :value verbatim)))
  2356. ;;;; Verse Block
  2357. (defun org-e-html-verse-block (verse-block contents info)
  2358. "Transcode a VERSE-BLOCK element from Org to HTML.
  2359. CONTENTS is verse block contents. INFO is a plist holding
  2360. contextual information."
  2361. ;; Replace each newline character with line break. Also replace
  2362. ;; each blank line with a line break.
  2363. (setq contents (replace-regexp-in-string
  2364. "^ *\\\\\\\\$" "<br/>\n"
  2365. (replace-regexp-in-string
  2366. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
  2367. ;; Replace each white space at beginning of a line with a
  2368. ;; non-breaking space.
  2369. (while (string-match "^[ \t]+" contents)
  2370. (let* ((num-ws (length (match-string 0 contents)))
  2371. (ws (let (out) (dotimes (i num-ws out)
  2372. (setq out (concat out "&nbsp;"))))))
  2373. (setq contents (replace-match ws nil t contents))))
  2374. (format "<p class=\"verse\">\n%s</p>" contents))
  2375. ;;; Filter Functions
  2376. (defun org-e-html-final-function (contents backend info)
  2377. (if (not org-e-html-pretty-output) contents
  2378. (with-temp-buffer
  2379. (html-mode)
  2380. (insert contents)
  2381. (indent-region (point-min) (point-max))
  2382. (buffer-substring-no-properties (point-min) (point-max)))))
  2383. ;;; End-user functions
  2384. ;;;###autoload
  2385. (defun org-e-html-export-as-html
  2386. (&optional subtreep visible-only body-only ext-plist)
  2387. "Export current buffer to an HTML buffer.
  2388. If narrowing is active in the current buffer, only export its
  2389. narrowed part.
  2390. If a region is active, export that region.
  2391. When optional argument SUBTREEP is non-nil, export the sub-tree
  2392. at point, extracting information from the headline properties
  2393. first.
  2394. When optional argument VISIBLE-ONLY is non-nil, don't export
  2395. contents of hidden elements.
  2396. When optional argument BODY-ONLY is non-nil, only write code
  2397. between \"<body>\" and \"</body>\" tags.
  2398. EXT-PLIST, when provided, is a property list with external
  2399. parameters overriding Org default settings, but still inferior to
  2400. file-local settings.
  2401. Export is done in a buffer named \"*Org E-HTML Export*\", which
  2402. will be displayed when `org-export-show-temporary-export-buffer'
  2403. is non-nil."
  2404. (interactive)
  2405. (let ((outbuf
  2406. (org-export-to-buffer
  2407. 'e-html "*Org E-HTML Export*"
  2408. subtreep visible-only body-only ext-plist)))
  2409. ;; Set major mode.
  2410. (with-current-buffer outbuf (nxml-mode))
  2411. (when org-export-show-temporary-export-buffer
  2412. (switch-to-buffer-other-window outbuf))))
  2413. ;;;###autoload
  2414. (defun org-e-html-export-to-html
  2415. (&optional subtreep visible-only body-only ext-plist pub-dir)
  2416. "Export current buffer to a HTML file.
  2417. If narrowing is active in the current buffer, only export its
  2418. narrowed part.
  2419. If a region is active, export that region.
  2420. When optional argument SUBTREEP is non-nil, export the sub-tree
  2421. at point, extracting information from the headline properties
  2422. first.
  2423. When optional argument VISIBLE-ONLY is non-nil, don't export
  2424. contents of hidden elements.
  2425. When optional argument BODY-ONLY is non-nil, only write code
  2426. between \"<body>\" and \"</body>\" tags.
  2427. EXT-PLIST, when provided, is a property list with external
  2428. parameters overriding Org default settings, but still inferior to
  2429. file-local settings.
  2430. When optional argument PUB-DIR is set, use it as the publishing
  2431. directory.
  2432. Return output file's name."
  2433. (interactive)
  2434. (let* ((extension (concat "." org-e-html-extension))
  2435. (file (org-export-output-file-name extension subtreep pub-dir))
  2436. (org-export-coding-system org-e-html-coding-system))
  2437. (org-export-to-file
  2438. 'e-html file subtreep visible-only body-only ext-plist)))
  2439. ;;;###autoload
  2440. (defun org-e-html-publish-to-html (plist filename pub-dir)
  2441. "Publish an org file to HTML.
  2442. FILENAME is the filename of the Org file to be published. PLIST
  2443. is the property list for the given project. PUB-DIR is the
  2444. publishing directory.
  2445. Return output file name."
  2446. (org-e-publish-org-to 'e-html filename ".html" plist pub-dir))
  2447. ;;; FIXME
  2448. ;;;; org-format-table-html
  2449. ;;;; org-format-org-table-html
  2450. ;;;; org-format-table-table-html
  2451. ;;;; org-table-number-fraction
  2452. ;;;; org-table-number-regexp
  2453. ;;;; org-e-html-table-caption-above
  2454. ;;;; org-e-html-with-timestamp
  2455. ;;;; org-e-html-html-helper-timestamp
  2456. ;;;; org-export-as-html-and-open
  2457. ;;;; org-export-as-html-batch
  2458. ;;;; org-export-as-html-to-buffer
  2459. ;;;; org-replace-region-by-html
  2460. ;;;; org-export-region-as-html
  2461. ;;;; org-export-as-html
  2462. ;;;; (org-export-directory :html opt-plist)
  2463. ;;;; (plist-get opt-plist :html-extension)
  2464. ;;;; org-e-html-toplevel-hlevel
  2465. ;;;; org-e-html-special-string-regexps
  2466. ;;;; org-e-html-inline-images
  2467. ;;;; org-e-html-inline-image-extensions
  2468. ;;;; org-e-html-protect-char-alist
  2469. ;;;; org-e-html-table-use-header-tags-for-first-column
  2470. ;;;; org-e-html-todo-kwd-class-prefix
  2471. ;;;; org-e-html-tag-class-prefix
  2472. ;;;; org-e-html-footnote-separator
  2473. ;;;; org-export-preferred-target-alist
  2474. ;;;; org-export-solidify-link-text
  2475. ;;;; class for anchors
  2476. ;;;; org-export-with-section-numbers, body-only
  2477. ;;;; org-export-mark-todo-in-toc
  2478. ;;;; org-e-html-format-org-link
  2479. ;;;; (caption (and caption (org-xml-encode-org-text caption)))
  2480. ;;;; alt = (file-name-nondirectory path)
  2481. ;;;; org-export-time-stamp-file'
  2482. (provide 'org-e-html)
  2483. ;;; org-e-html.el ends here