Function: web-mode-scan-elements
web-mode-scan-elements is a natively compiled function defined in
web-mode.el.
Signature
(web-mode-scan-elements REG-BEG REG-END)
Source Code
;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
;;---- LEXER PARTS -------------------------------------------------------------
(defun web-mode-scan-elements (reg-beg reg-end)
(save-excursion
(let (part-beg part-end flags limit close-expr props tname tbeg tend element-content-type (regexp web-mode-dom-regexp) part-close-tag char)
;;(message "scan-elements: reg-beg(%S) reg-end(%S)" reg-beg reg-end)
(goto-char reg-beg)
(while (web-mode-dom-rsf regexp reg-end)
;;(message "%S: %S (%S %S)" (point) (match-string-no-properties 0) reg-beg reg-end)
(setq flags 0
tnameraw (match-string-no-properties 1)
tname (downcase tnameraw)
char (aref tname 0)
tbeg (match-beginning 0)
tend nil
element-content-type nil
limit reg-end
part-beg nil
part-end nil
props nil
close-expr nil
part-close-tag nil)
;;(message "tname[%S] tbeg(%S) point(%S)" tname tbeg (point))
(cond
((member tname '("/>" ">")) ;;jsx fragment #952
(setq tname "_fragment_"
tend (point))
(if (eq char ?\/)
(setq props (list 'tag-name tname 'tag-type 'end)
flags (logior flags 20)) ;; 16 + 4
(setq props (list 'tag-name tname 'tag-type 'start)
flags (logior flags 16))
) ;if
)
((not (member char '(?\! ?\?)))
(cond
((or (string-match-p "-" tname)
(let ((case-fold-search nil))
(string-match-p "^/?[[:upper:]][[:lower:]]" tnameraw)))
(setq flags (logior flags 2)))
;;((string-match-p ":" tname)
;; (setq flags (logior flags 32)))
((string-match-p "[._:]" tname)
(setq flags (logior flags 32)))
)
(cond
((eq char ?\/)
(setq props (list 'tag-name (substring tname 1) 'tag-type 'end)
flags (logior flags 4)
limit (if (> reg-end (line-end-position)) (line-end-position) reg-end))
)
((web-mode-element-is-void tname)
;;(message "void: tag=%S" tname)
(setq props (list 'tag-name tname 'tag-type 'void)))
(t
(setq props (list 'tag-name tname 'tag-type 'start)))
) ;cond
) ; not <! <?
((and (eq char ?\!) (eq (aref tname 1) ?\-))
(setq close-expr "-->"
props '(tag-type comment)))
((string= tname "?xml")
(setq ;;regexp web-mode-tag-regexp2
close-expr "?>"
props '(tag-type declaration)))
((string= tname "![cdata[")
(setq close-expr "]]>"
props '(tag-type cdata)))
((string= tname "!doctype")
(setq ;;regexp web-mode-tag-regexp2
props '(tag-type doctype)))
) ;cond - special tags
(cond
(tend
)
((and (null close-expr) (eq (char-after) ?\>))
(setq flags (logior flags 16)
tend (1+ (point)))
;;(message "end=%S" tend)
)
((and (null close-expr)
(looking-at "[ ]\\(class\\|id\\|href\\|style\\)=\"[[:alnum:]_=:/?;#. -]*\">"))
(let ((beg (1+ (point)))
(end (+ (point) (length (match-string-no-properties 0)))))
(setq flags (logior flags 17)
tend end)
(put-text-property beg (1+ beg) 'tag-attr-beg 0)
(put-text-property beg (1- end) 'tag-attr t)
(put-text-property (- end 2) (1- end) 'tag-attr-end (length (match-string-no-properties 1)))
) ;let
)
((null close-expr)
(setq flags (logior flags (web-mode-attr-skip reg-end)))
(when (> (logand flags 8) 0)
(setq props (plist-put props 'tag-type 'void)))
(setq tend (point)))
((web-mode-dom-sf close-expr limit t)
(setq tend (point)))
(t
(setq tend (line-end-position)))
) ;cond
(cond
((string= tname "style")
(let (style)
(setq style (buffer-substring-no-properties tbeg tend)
part-close-tag "</style>")
(cond
((string-match-p " lang[ ]*=[ ]*[\"']stylus" style)
(setq element-content-type "stylus"))
((string-match-p " lang[ ]*=[ ]*[\"']sass" style)
(setq element-content-type "sass"))
(t
(setq element-content-type "css"))
) ;cond
) ;let
) ;style
((string= tname "script")
(let (script)
(setq script (buffer-substring-no-properties tbeg tend)
part-close-tag "</script>")
(cond
((string-match-p " type[ ]*=[ ]*[\"']text/\\(jsx\\|babel\\)" script)
(setq element-content-type "jsx"))
((string-match-p " type[ ]*=[ ]*[\"']text/\\(markdown\\|template\\)" script)
(setq element-content-type "markdown"))
((string-match-p " type[ ]*=[ ]*[\"']text/ruby" script)
(setq element-content-type "ruby"))
((seq-some (lambda (x)
(string-match-p (concat "type[ ]*=[ ]*[\"']" x) script))
web-mode-script-template-types)
(setq element-content-type "html"
part-close-tag nil))
((string-match-p " type[ ]*=[ ]*[\"']application/\\(ld\\+json\\|json\\)" script)
(setq element-content-type "json"))
((string-match-p " lang[ ]*=[ ]*[\"']\\(typescript\\|ts\\)" script)
(setq element-content-type "typescript"))
(t
(setq element-content-type "javascript"))
) ;cond
) ;let
) ;script
((string= tname "i18n")
(setq element-content-type "javascript"
part-close-tag "</i18n>"))
((and (string= tname "template") (string-match-p " lang" (buffer-substring-no-properties tbeg tend)))
(let (template)
(setq template (buffer-substring-no-properties tbeg tend)
part-close-tag "</template>")
(cond
((string-match-p " lang[ ]*=[ ]*[\"']pug" template)
(setq element-content-type "pug"))
(t
(setq element-content-type "html"))
) ;cond
) ;let
) ;style
((and (string= web-mode-engine "archibus")
(string= tname "sql"))
(setq element-content-type "sql"
part-close-tag "</sql>"))
)
(add-text-properties tbeg tend props)
(put-text-property tbeg (1+ tbeg) 'tag-beg flags)
(put-text-property (1- tend) tend 'tag-end t)
(when (and part-close-tag
(web-mode-dom-sf part-close-tag reg-end t)
(setq part-beg tend)
(setq part-end (match-beginning 0))
(> part-end part-beg))
(put-text-property part-beg part-end 'part-side
(intern element-content-type web-mode-obarray))
(setq tend part-end)
) ;when
(goto-char tend)
) ;while
)))