org-e-html.el 105 KB

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