endif
enddef
-# Distinguish between HTML, XHTML and Django
+# Distinguish between HTML, XHTML, Django and Angular
export def FThtml()
var n = 1
+
+ # Test if the filename follows the Angular component template convention
+ if expand('%:t') =~ '^.*\.component\.html$'
+ setf htmlangular
+ return
+ endif
+
while n < 40 && n <= line("$")
+ # Check for Angular
+ if getline(n) =~ '@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content\|{{.*}}'
+ setf htmlangular
+ return
+ endif
+
+ # Check for XHTML
if getline(n) =~ '\<DTD\s\+XHTML\s'
setf xhtml
return
endif
+ # Check for Django
if getline(n) =~ '{%\s*\(autoescape\|block\|comment\|csrf_token\|cycle\|debug\|extends\|filter\|firstof\|for\|if\|ifchanged\|include\|load\|lorem\|now\|query_string\|regroup\|resetcycle\|spaceless\|templatetag\|url\|verbatim\|widthratio\|with\)\>\|{#\s\+'
setf htmldjango
return
--- /dev/null
+" 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
hoon: ['file.hoon'],
hostconf: ['/etc/host.conf', 'any/etc/host.conf'],
hostsaccess: ['/etc/hosts.allow', '/etc/hosts.deny', 'any/etc/hosts.allow', 'any/etc/hosts.deny'],
- html: ['file.html', 'file.htm', 'file.cshtml', 'file.component.html'],
+ html: ['file.html', 'file.htm', 'file.cshtml'],
+ htmlangular: ['file.component.html'],
htmlm4: ['file.html.m4'],
httest: ['file.htt', 'file.htb'],
hurl: ['file.hurl'],
call assert_equal('', &filetype)
filetype detect
call assert_equal('sh', &filetype)
- close!
+ " close the swapfile
+ bw!
endfunc
" Test for ':filetype indent on' and ':filetype indent off' commands
filetype off
endfunc
+func Test_html_file()
+ filetype on
+
+ " HTML Angular
+ let content = ['@for (item of items; track item.name) {', ' <li> {{ item.name }}</li>', '} @empty {', ' <li> There are no items.</li>', '}']
+ call writefile(content, 'Xfile.html', 'D')
+ split Xfile.html
+ call assert_equal('htmlangular', &filetype)
+ bwipe!
+
+ " Django Template
+ let content = ['{% if foobar %}',
+ \ ' <ul>',
+ \ ' {% for question in list %}',
+ \ ' <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>',
+ \ ' {% endfor %}',
+ \ ' </ul>',
+ \ '{% else %}',
+ \ ' <p>No polls are available.</p>',
+ \ '{% endif %}']
+ call writefile(content, 'Xfile.html', 'D')
+ split Xfile.html
+ call assert_equal('htmldjango', &filetype)
+ bwipe!
+
+ " regular HTML
+ let content = ['<!DOCTYPE html>', '<html>', ' <head>Foobar</head>', ' <body>Content', ' </body>', '</html>']
+ call writefile(content, 'Xfile.html', 'D')
+ split Xfile.html
+ call assert_equal('html', &filetype)
+ bwipe!
+
+ filetype off
+endfunc
+
func Test_m_file()
filetype on