diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/ftplugin/htmlangular.vim | 12 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 17 |
2 files changed, 27 insertions, 2 deletions
diff --git a/runtime/ftplugin/htmlangular.vim b/runtime/ftplugin/htmlangular.vim new file mode 100644 index 0000000000..b181b203d0 --- /dev/null +++ b/runtime/ftplugin/htmlangular.vim @@ -0,0 +1,12 @@ +" Vim filetype plugin file +" Language: Angular HTML Template +" Maintainer: Dennis van den Berg <dennis@vdberg.dev> +" Last Change: 2024 Jul 8 + +" Only use this filetype plugin when no other was loaded. +if exists("b:did_ftplugin") + finish +endif + +" Use HTML and Angular template ftplugins +runtime! ftplugin/html.vim diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 85c8d4c9dc..8a217a4ac2 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -710,9 +710,22 @@ function M.haredoc(path, _) end --- @type vim.filetype.mapfn -function M.html(_, bufnr) +function M.html(path, bufnr) + -- Test if the filename follows the Angular component template convention + local filename = fn.fnamemodify(path, ':t') + if filename:find('%.component%.html$') then + return 'htmlangular' + end + for _, line in ipairs(getlines(bufnr, 1, 40)) do - if matchregex(line, [[\<DTD\s\+XHTML\s]]) then + if + matchregex( + line, + [[@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content\|{{.*}}]] + ) + then + return 'htmlangular' + elseif matchregex(line, [[\<DTD\s\+XHTML\s]]) then return 'xhtml' elseif matchregex( |