ox-html.el 114 KB

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