ox-html.el 115 KB

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