vim-patch:9.2.0500: filetype: some html files wrongly recognized as htmlangular (#39880)

Problem:  filetype: some html files are wrongly recognized as htmlangular
Solution: Use the \< atom to anchor ng-template and ng-content to start
          of word (truffle)

Prevent false-positive htmlangular detection on words containing
'ng-template' or 'ng-content' as a substring (e.g. 'song-template',
'sing-content'). Anchor both branches with \< to require a word start,
matching the \<DTD\s\+XHTML\s idiom used five lines below.

related: neovim/neovim#39778.
closes:  vim/vim#20246

354ab1a69e

Co-authored-by: truffle <truffleagent@gmail.com>
This commit is contained in:
zeertzjq
2026-05-19 08:42:05 +08:00
committed by GitHub
parent 450ba41436
commit f3bb21e71d
2 changed files with 22 additions and 1 deletions

View File

@@ -848,7 +848,7 @@ function M.html(_, bufnr)
if
matchregex(
line,
[[@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content]]
[[@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|\<ng-template\|\<ng-content]]
)
then
return 'htmlangular'

View File

@@ -1874,6 +1874,27 @@ func Test_html_file()
call assert_equal('htmlangular', &filetype)
bwipe!
" HTML Angular ng-template element
let content = ['<ng-template let-foo>{{ foo }}</ng-template>']
call writefile(content, 'Xfile.html', 'D')
split Xfile.html
call assert_equal('htmlangular', &filetype)
bwipe!
" HTML Angular ng-content element
let content = ['<div><ng-content select="[item]"></ng-content></div>']
call writefile(content, 'Xfile.html', 'D')
split Xfile.html
call assert_equal('htmlangular', &filetype)
bwipe!
" Word containing 'ng-template' as a suffix must not trigger htmlangular
let content = ['<div class="song-template">', ' <h1>Not Angular</h1>', '</div>']
call writefile(content, 'Xfile.html', 'D')
split Xfile.html
call assert_equal('html', &filetype)
bwipe!
" Django Template
let content = ['{% if foobar %}',
\ ' <ul>',