org-e-html.el 101 KB

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