ox-html.el 102 KB

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