;; 1: basic ;;

;;

;;_ ;; 2: ignore empty tags (or emit warning if html-close-tag-enforce-xhtml) ;; ;; ;; 3.1 ;;
_ ;; 3.2 ;;

_ ;; 3.3 ;;

_

;; 3: quoted special characters ;; 3.1 /'\">'/>">_ ;; 3.2 "/>\'/">'>_ ;; 4: ;; ;; ;; _ ;; 5 ;; ;;
Text_ ;; 6: CDATA-sections and comments ;; 6.1 ;; ]]> _ ;; 6.2 ;; --> _ ;; 6.3 ;; --> ;; ]]> _ ;; 6.4 ;; _ ;; 6.5.1 ;; ;; _ ;; 6.6 ;;
_ ;; 6.7 ;;
]]> _ ;; 7: enforce xhtml 1.0 ;; 7.1 ;;
_ ;; 7.2 ;;

_ ;; undo the changes: ;; ;; 8: an element that is sometimes empty, sometimes not ;; 8.1 ;;

first para

second para

third block

fourth

_ ;; 8.2 ;;

_ ;; 8.3 ;;
text
_ ;; undo the changes: ;; 9: ;; 9.1

this is important _ ;; ;; 9.2

text

_ ;; undo the change (defvar html-close-tag-enforce-xhtml nil "Tell the user to use empty-element tags \(i.e. \) or add an end-tag \(i.e.

text

\) as required by xhtml 1.0.") (defvar html-close-tag-extra-empty-tags '() "List of (names of) extra tags which are not closed.") (defvar html-close-tag-ignore-nesting nil "If this is t, ignore \"Invalid nesting\" \(things like Text\). Note that this only makes sense if you know that the nesting is wrong and you declared all extra \"empty\" elements \(with `html-close-tag-extra-empty-tags'\) and there's nothing else wrong and you don't want to fix it. If you have to use this it will most often result in \"Nothing to do\" or a wrong end-tag.") (defun html-close-tag-empty-html-tag-p (name) "Returns whether the tag with `name' doesn't have to be closed in HTML 4." (string-match (eval-when-compile (concat "^\\(" (regexp-opt '("area" "base" "basefont" ;; deprecated in HTML 4 "br" "col" "frame" "hr" "img" "input" "isindex" ;; deprecated in HTML 4 "link" "meta" "param")) "\\)$")) (downcase name))) (defun html-close-tag-in-comment-or-cdata-section-p () "Returns t if point is in a comment or CDATA section." (interactive) (save-excursion (if (not (re-search-backward ;;\1=startComment;\2=endComment;\3=startCDATA;\4=endCDATA ;;\5=brokenEndComment "\\(\\)\\|\\(\\)\\|\\(--[ \t\r\n]*>\\)" nil t)) nil (if (match-string 5) (error (concat "%s: Don't use whitespace between \"--\" and '>' " "because it's not supported by xhtml.") (what-line)) (or (match-string 1) (match-string 3)))))) (defun html-close-tag() "Insert end-tag for element which doesn't have one. Ignores elements which have EMPTY content model in HTML 4 (if `html-close-tag-enforce-xhtml' is non-nil, it will produce a warning). Tries to support xhtml 1.0 and HTML, and by setting a few variables \(probably specific to a file; see C-h i m Emacs RET m Variables RET) you can often make this work. Note that if you want to edit well-formed sgml+xml you might be better off with psgml-mode (which includes an sgml/xml parser and can thus validate against a dtd and do other nice stuff): http://www.lysator.liu.se/projects/about_psgml.html Comments: - When matching start-tags and end-tags case is ignored (i.e.

is considered to be the end-tag of

) - Emits an error if the nesting of elements is wrong (regardless of `html-close-tag-enforce-xhtml') This can be turned off with `html-close-tag-ignore-nesting' (but use of this is discouraged; it rarely fixes the problem) - If a tag is not configured to be EMPTY (i.e.

,

  • ,
    ,
    ,