Skip to content

Commit

Permalink
further improve html/mathml import:
Browse files Browse the repository at this point in the history
accept no-namespace math tag (as per html5)
accept mathml-only (files and "paste as html")
better handle various imports to wide
add many math html entities
  • Loading branch information
slowphil committed Dec 28, 2022
1 parent a5cd683 commit a4f9bc9
Show file tree
Hide file tree
Showing 4 changed files with 630 additions and 13 deletions.
23 changes: 22 additions & 1 deletion TeXmacs/progs/convert/html/htmltm.scm
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@
(if (sxhtml-list? (xpath-parent env))
'()
'((next-line))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Unlike previously, Mathml nodes in HTML5 have no namespace prefix
;; => xmltm.scm prefixes them with h:
;; Yet, the import code in mathtm.scm expects m: prefix : replace prefix (hacky)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (htmltm-math env a c)
(with cm `(m:math (@ ,@a) ,(replace-nsprefix-in-stree c "h:" "m:"))
`(,(mathtm-as-serial env cm))
))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MathJax extension
Expand Down Expand Up @@ -433,7 +444,7 @@
(tm-define (htmltm-as-serial root)
;; As htmltm, but returns a serial node.
;; Actually also initializes the dynamic enviroment.
;; FIXME: move the htmlinitialization elsewhere for symmetry with htmltm.
;; FIXME: move the html initialization elsewhere for symmetry with htmltm.
(define (sub env)
(htmltm-serial (htmltm-preserve-space? env)
(htmltm env (cleanup-root env root))))
Expand Down Expand Up @@ -565,6 +576,9 @@
;;; Extensions
(mathjax (handler :collapse :inline htmltm-mathjax))

;;; Math tag in HTML5 (no namespace prefix)
(math (handler :mixed :block htmltm-math))

;; Tags present in the previous converter
;; Unknown: FIG FN NOTE AU LANG PERSON
;; ABBREV instead of ABBR
Expand Down Expand Up @@ -609,6 +623,13 @@
(else
st))) ; unexpected entry

(define (replace-nsprefix-in-stree st from to)
(cond ((and (nnull? st) (symbol? st) (string-starts? (symbol->string st) from))
(string->symbol (string-append to
(string-drop (symbol->string st) (string-length from)))))
((list? st) (map (lambda (x) (replace-nsprefix-in-stree x from to)) st))
(else st)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Post processing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
1 change: 1 addition & 0 deletions TeXmacs/progs/convert/html/init-html.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
((format-test? s pos "<body") #t)
((format-test? s pos "<title") #t)
((format-test? s pos "<!doctype html") #t)
((format-test? s pos "<math") #t)
((format-test? s pos "<?xml ")
(html-recognizes-at? s (format-skip-line s pos)))
((format-test? s pos "<!doctype ")
Expand Down

0 comments on commit a4f9bc9

Please sign in to comment.