org-e-html.el 104 KB

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