Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions progs/convert/html/tmhtml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,9 @@
(title (tmhtml-find-title doc))
(css `(h:style (@ (type "text/css")) ,(tmhtml-css-header)))
(xhead '())
;; Use a single string for the JavaScript code block
(js-inline `((h:script (@ (type "text/javascript"))
"(function () {\"use strict\"; window.addEventListener(\"load\", function () { var box, div, link, namespaceURI; namespaceURI = 'http://www.w3.org/1998/Math/MathML'; if (document.body.getElementsByTagNameNS(namespaceURI, 'math')[0]) { document.body.insertAdjacentHTML('afterbegin', '<div style=\\\"border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px;\\\"><math xmlns=\\\"' + namespaceURI + '\\\"><mspace height=\\\"23px\\\" width=\\\"77px\\\"></mspace></math></div>'); div = document.body.firstChild; box = div.firstChild.firstChild.getBoundingClientRect(); document.body.removeChild(div); if (Math.abs(box.height - 23) > 1 || Math.abs(box.width - 77) > 1) { link = document.createElement('link'); link.href = 'https://fred-wang.github.io/mathml.css/mathml.css'; link.rel = 'stylesheet'; document.head.appendChild(link); } } }); })();")))
(scripts `((h:script (@ (type "text/javascript")))
(h:script "document.querySelectorAll('style').forEach(style => style.remove());")))
(body (append scripts (tmhtml doc))))
(body (tmhtml doc)))
(set! tmhtml-site-version
(with-extract doc "html-site-version"))

(set! title
(cond ((with-extract doc "html-title")
Expand All @@ -234,17 +231,57 @@
(href ,(with-extract doc "html-css"))
(type "text/css"))))
(else css)))

;; Add your JS inline to the <head> section
(set! xhead (append xhead js-inline))

(if (with-extract doc "html-head-javascript-src")
(let* ((src (with-extract doc "html-head-javascript-src"))
(script `(h:script (@ (language "javascript")
(src ,src)))))
(set! xhead (append xhead (list script)))))
(if (with-extract doc "html-head-javascript")
(let* ((code (with-extract doc "html-head-javascript"))
(script `(h:script (@ (language "javascript")) ,code)))
(set! xhead (append xhead (list script)))))
(if (with-extract doc "html-head-favicon")
(let* ((code (with-extract doc "html-head-favicon"))
(icon `(h:link (@ (rel "icon") (href ,code)))))
(set! xhead (append xhead (list icon)))))
(if (and (not (func? css 'h:link))
(string-ends? (get-preference "texmacs->html:css-stylesheet")
".css"))
(with src (get-preference "texmacs->html:css-stylesheet")
(with link-css `(h:link (@ (rel "stylesheet")
(href ,src)
(type "text/css")))
(set! xhead (append xhead (list link-css))))))
(if (tm-func? (with-extract* doc "html-extra-css") 'tuple)
(for (src (cdr (with-extract* doc "html-extra-css")))
(with link-css `(h:link (@ (rel "stylesheet")
(href ,src)
(type "text/css")))
(set! xhead (append xhead (list link-css))))))
(if (tm-func? (with-extract* doc "html-extra-javascript-src") 'tuple)
(for (src (cdr (with-extract* doc "html-extra-javascript-src")))
(with script `(h:script (@ (language "javascript")
(src ,src)
(defer "<implicit>")))
(set! xhead (append xhead (list script))))))
(if (tm-func? (with-extract* doc "html-extra-javascript") 'tuple)
(for (code (cdr (with-extract* doc "html-extra-javascript")))
(with script `(h:script (@ (language "javascript")
(defer "<implicit>")) ,code)
(set! xhead (append xhead (list script))))))
(if tmhtml-mathjax?
(let* ((site "https://cdn.jsdelivr.net/")
(loc "npm/mathjax@3/es5/tex-mml-chtml.js")
(src (string-append site loc))
(script `(h:script (@ (language "javascript") (src ,src)))))
(set! xhead (append xhead (list script)))))

(if (or (in? "tmdoc" styles)
(in? "tmweb" styles) (in? "tmweb2" styles)
(in? "mmxdoc" styles) (in? "magix-web" styles)
(in? "max-web" styles) (in? "node-web" styles))
(set! body (tmhtml-tmdoc-post body)))
(if tmhtml-css?
(set! body (tmhtml-css-post body)))
`(h:html
(h:head
(h:title ,@(tmhtml title))
Expand Down