org-e-html.el 105 KB

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