1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-15 09:47:20 +00:00

Put files in mhtml-mode when they have <!DOCTYPE, case-insensitive

* lisp/files.el (magic-fallback-mode-alist): Match "DOCTYPE" in a
case-insensitive way before putting files in mhtml-mode. See
https://html.spec.whatwg.org/multipage/syntax.html#the-doctype for the
standard reference.
* test/lisp/files-tests.el (files-test-magic-mode-alist-doctype): Add
a test (bug#43511).
This commit is contained in:
Daniel Martín 2020-09-19 19:15:48 +02:00 committed by Lars Ingebrigtsen
parent 7222e975be
commit c9f845a53c
2 changed files with 13 additions and 1 deletions

View File

@ -3067,7 +3067,7 @@ If FUNCTION is nil, then it is not called. (That is a way of saying
"\\(?:!DOCTYPE[ \t\r\n]+[^>]*>[ \t\r\n]*<[ \t\r\n]*" comment-re "*\\)?"
"[Hh][Tt][Mm][Ll]"))
. mhtml-mode)
("<!DOCTYPE[ \t\r\n]+[Hh][Tt][Mm][Ll]" . mhtml-mode)
("<![Dd][Oo][Cc][Tt][Yy][Pp][Ee][ \t\r\n]+[Hh][Tt][Mm][Ll]" . mhtml-mode)
;; These two must come after html, because they are more general:
("<\\?xml " . xml-mode)
(,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)")

View File

@ -1365,5 +1365,17 @@ See <https://debbugs.gnu.org/36401>."
(should (equal (parse-colon-path "/foo//bar/baz")
'("/foo/bar/baz/"))))
(ert-deftest files-test-magic-mode-alist-doctype ()
"Test that DOCTYPE and variants put files in mhtml-mode."
(with-temp-buffer
(goto-char (point-min))
(insert "<!DOCTYPE html>")
(normal-mode)
(should (eq major-mode 'mhtml-mode))
(erase-buffer)
(insert "<!doctype html>")
(normal-mode)
(should (eq major-mode 'mhtml-mode))))
(provide 'files-tests)
;;; files-tests.el ends here