ox-html.el 114 KB

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