org-e-html.el 101 KB

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