ox-html.el 113 KB

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