ox-html.el 117 KB

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