org-e-html.el 101 KB

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