org-e-html.el 105 KB

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