summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--autoload/polyglot.vim5
-rw-r--r--heuristics.yaml9
-rwxr-xr-xscripts/build8
-rw-r--r--tests/extensions.vim8
4 files changed, 21 insertions, 9 deletions
diff --git a/autoload/polyglot.vim b/autoload/polyglot.vim
index 325287fc..d8ee601f 100644
--- a/autoload/polyglot.vim
+++ b/autoload/polyglot.vim
@@ -372,9 +372,12 @@ func! polyglot#DetectHtmlFiletype()
endif
for lnum in range(1, min([line("$"), 50]))
let line = getline(lnum)
- if line =~# '{{.*}}\|{%-\=\s*\(end.*\|extends\|block\|macro\|set\|if\|for\|include\|trans\)\(\<\|\>\)'
+ if line =~# '{{.*}}\|{%-\=\s*\(end.*\|extends\|block\|macro\|set\|if\|for\|include\|trans\)\(\<\|\>\)\|{#\s\+'
set ft=jinja.html | return
endif
+ if line =~# '\(\<\|\>\)DTD\s\+XHTML\s'
+ set ft=xhtml | return
+ endif
endfor
set ft=html | return
endfunc
diff --git a/heuristics.yaml b/heuristics.yaml
index 7cc6a273..60df69b5 100644
--- a/heuristics.yaml
+++ b/heuristics.yaml
@@ -181,7 +181,10 @@ rules:
pattern: '^(%|<[%&].*>)'
filetype: mason
- lines: 50
- pattern: '{{.*}}|{%-?\s*(end.*|extends|block|macro|set|if|for|include|trans)\b'
- filetype: jinja.html
+ rules:
+ - pattern: '{{.*}}|{%-?\s*(end.*|extends|block|macro|set|if|for|include|trans)\b|{#\s+'
+ filetype: jinja.html
+ - pattern: '\bDTD\s+XHTML\s'
+ filetype: xhtml
- filetype: html
-
+ fallback: true
diff --git a/scripts/build b/scripts/build
index 8b507fef..47a7e51a 100755
--- a/scripts/build
+++ b/scripts/build
@@ -317,7 +317,7 @@ def rule_to_code(rule)
EOS
end
- if (rule.keys - ["filetype", "override", "set", "extensions"]).size > 0
+ if (rule.keys - ["filetype", "override", "set", "extensions", "fallback"]).size > 0
raise "Unknown rule: #{JSON.generate(rule)}"
end
@@ -335,7 +335,11 @@ def rule_to_code(rule)
end
if rule.has_key?("filetype")
- return "set ft=#{rule["filetype"]} | return"
+ if rule.has_key?("fallback")
+ return "set ft=#{rule["filetype"]} | return"
+ else
+ return "setf FALLBACK #{rule["filetype"]} | return"
+ end
end
if rule.has_key?("extensions")
diff --git a/tests/extensions.vim b/tests/extensions.vim
index d792ac3c..d6f63407 100644
--- a/tests/extensions.vim
+++ b/tests/extensions.vim
@@ -356,6 +356,8 @@ call TestExtension("tt2html", "html.tt2", "<html>")
call TestExtension("html", "empty.html", "")
call TestExtension("mason", "mason1.html", "% my $planet = 42;")
call TestExtension("mason", "mason2.html", "<%filter></%filter>")
-call TestExtension("jinja.html", "jinja.html", "{{ item.href }}")
-call TestExtension("jinja.html", "jinja.html", "{% for item in navigation %}{% endfor %}")
-call TestExtension("jinja.html", "jinja.html", "{% block head %}")
+call TestExtension("jinja.html", "jinja1.html", "{{ item.href }}")
+call TestExtension("jinja.html", "jinja2.html", "{% for item in navigation %}{% endfor %}")
+call TestExtension("jinja.html", "jinja3.html", "{% block head %}")
+call TestExtension("jinja.html", "jinja4.html", "{# some comment #}")
+call TestExtension("xhtml", "xhtml.html", "<DTD XHTML ")