diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-24 09:24:13 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-24 09:24:13 +0200 |
commit | 6b4da2753814cc61cd842c589d829f03cd7ca98d (patch) | |
tree | 52beb70126e19a93eab504217b7ecd2354473b35 | |
parent | c284af58fa13ad9fdd831f57d31dc4688977ae94 (diff) | |
download | vim-polyglot-6b4da2753814cc61cd842c589d829f03cd7ca98d.tar.gz vim-polyglot-6b4da2753814cc61cd842c589d829f03cd7ca98d.zip |
Improve html heuristics
-rw-r--r-- | autoload/polyglot.vim | 5 | ||||
-rw-r--r-- | heuristics.yaml | 9 | ||||
-rwxr-xr-x | scripts/build | 8 | ||||
-rw-r--r-- | tests/extensions.vim | 8 |
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 ") |