org-e-html.el 101 KB

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