ox-html.el 107 KB

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