Skip to content

Commit 7e2d060

Browse files
committed
Fix detecting jinja templates, #553
1 parent 3a298c9 commit 7e2d060

File tree

4 files changed

+12
-244
lines changed

4 files changed

+12
-244
lines changed

autoload/polyglot.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ func! polyglot#DetectHtmlFiletype()
370370
if line =~# '^\(%\|<[%&].*>\)'
371371
set ft=mason | return
372372
endif
373+
for lnum in range(1, min([line("$"), 50]))
374+
let line = getline(lnum)
375+
if line =~# '{{.*}}\|{%-\=\s*\(end.*\|extends\|block\|macro\|set\|if\|for\|include\|trans\)\(\<\|\>\)'
376+
set ft=jinja.html | return
377+
endif
378+
endfor
373379
set ft=html | return
374380
endfunc
375381

heuristics.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,8 @@ rules:
180180
- lines: 1
181181
pattern: '^(%|<[%&].*>)'
182182
filetype: mason
183+
- lines: 50
184+
pattern: '{{.*}}|{%-?\s*(end.*|extends|block|macro|set|if|for|include|trans)\b'
185+
filetype: jinja.html
183186
- filetype: html
184187

scripts/test_filetypes.vim

Lines changed: 0 additions & 244 deletions
This file was deleted.

tests/extensions.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,6 @@ call TestExtension("tt2html", "html.tt2", "<html>")
356356
call TestExtension("html", "empty.html", "")
357357
call TestExtension("mason", "mason1.html", "% my $planet = 42;")
358358
call TestExtension("mason", "mason2.html", "<%filter></%filter>")
359+
call TestExtension("jinja.html", "jinja.html", "{{ item.href }}")
360+
call TestExtension("jinja.html", "jinja.html", "{% for item in navigation %}{% endfor %}")
361+
call TestExtension("jinja.html", "jinja.html", "{% block head %}")

0 commit comments

Comments
 (0)