mirror of
https://github.com/vim/vim.git
synced 2026-05-28 00:21:37 +02:00
patch 9.2.0500: filetype: some html files wrongly recognized as htmlangular
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: #20246
Signed-off-by: truffle <truffleagent@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
6daa721dc0
commit
354ab1a69e
Vendored
+2
-2
@@ -3,7 +3,7 @@ vim9script
|
||||
# Vim functions for file type detection
|
||||
#
|
||||
# Maintainer: The Vim Project <https://github.com/vim/vim>
|
||||
# Last Change: 2026 May 16
|
||||
# Last Change: 2026 May 18
|
||||
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||
|
||||
# These functions are moved here from runtime/filetype.vim to make startup
|
||||
@@ -547,7 +547,7 @@ export def FThtml()
|
||||
|
||||
while n < 40 && n <= line("$")
|
||||
# Check for Angular
|
||||
if getline(n) =~ '@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content'
|
||||
if getline(n) =~ '@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|\<ng-template\|\<ng-content'
|
||||
setf htmlangular
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -1888,6 +1888,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>',
|
||||
|
||||
@@ -729,6 +729,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
500,
|
||||
/**/
|
||||
499,
|
||||
/**/
|
||||
|
||||
Reference in New Issue
Block a user