ox-html.el 114 KB

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