Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Syntastic is unable to recognize HTML templates and throws syntax errors #240

Closed
distracteddev opened this issue Apr 28, 2012 · 17 comments
Closed

Comments

@distracteddev
Copy link

If the following is found in the head element of a HTML page, Syntastic will complain about the html tags not being allowed within the tag. Can we some how modify the HTML checker to either detect the scripts type attribute and simply not parse the following. Or, if possible, parses it using a handlebars syntax checker? (if one exists).

Code placed in comment below since code-formatting was being fussy.

@distracteddev
Copy link
Author

<script type="text/x-handlebars" data-template-name="posts">
    {{#each content}}
    <div class="row">
        <section class="post columns eight centered mock">
            <section class="post-header">
                <h2>{{title}}</h2>
                <h5>{{sub_title}}</h5>
                {{#each tags}}
                    <p>{{this}}</p>
                {{/each}}
                <p class="post-body">{{body}}</p>
            </section>
        </section>
    </div>
    {{/each}}
</script>

@achur
Copy link

achur commented Jun 27, 2012

+1 also have needed to turn off syntastic for html due to this

@wizonesolutions
Copy link

+1 Syntastic complains about tags when using the Handlebars built into Meteor as well.

@et
Copy link
Contributor

et commented Jan 31, 2013

Syntastic is just following the spec. See 4.3.1.2 Restrictions for contents of script elements where a LESS-THAN (<) character is not allowed.

Let it serve merely as a suggestion to organize your handlebar templates better.

@scrooloose
Copy link
Collaborator

We havent found a decent way to check html yet really. Tidy is pretty clunky and we already filter out a lot of the useless errors.

If it is driving insane, you can chuck this in your vimrc: let syntastic_mode_map = { 'passive_filetypes': ['html'] }

that will make is so html files are only checked if you explicitly run :SyntasticCheck. I'm guessing this is what @distracteddev has done already.

Yeah, any alternative syntax checker suggestions/pull-requests for html are welcome for sure.

@mattparrilla
Copy link

+1 I understand there is no current solution, just want to keep myself in the loop for this particular thread! I'm in my first week using syntastic--it's fantastic!

@gs
Copy link
Contributor

gs commented Jun 18, 2013

+1 the same problem with eruby file

<% @matching.each do |match| %> <%= render :partial => 'content_row', :locals => { :name => match.mapped.name, :claim_url => match.yelp_attributes[:claim_url] } %> <% end %>

@gs
Copy link
Contributor

gs commented Jun 18, 2013

I solved the issue for eruby files by changing the syntastic/syntax_checkers/eruby/eruby.vim to
let makeprg = 'erb -xT - ' . fname . ' \| ruby -c'

@lcd047
Copy link
Collaborator

lcd047 commented Jun 18, 2013

@gs: This looks like a job for a separate checker, rather than patching the existing one. You probably need to put shellescape(fnameescape()) around fname though.

@gs
Copy link
Contributor

gs commented Jun 18, 2013

@lcd047: thx for your response!!

your hint worked good for me and I have now custom syntax checker :)

I will create specific eruby issue and submit pull-request

@fourcolors
Copy link

I would really like a solution to this too. For now I'm just putting it into passive mode.

@lcd047
Copy link
Collaborator

lcd047 commented Jan 30, 2014

@fourcolors There is now a handlebars checker.

If this is not what you mean, than please open a new report explaining what you did, what you expected to happen, and what happened instead.

@rafi
Copy link

rafi commented Sep 26, 2014

Ignore specific tidy errors:

let g:syntastic_html_tidy_ignore_errors = [
    \  'plain text isn''t allowed in <head> elements',
    \  '<base> escaping malformed URI reference',
    \  'discarding unexpected <body>',
    \  '<script> escaping malformed URI reference',
    \  '</head> isn''t allowed in <body> elements'
    \ ]

Ignore all of tidy's warnings:

let g:syntastic_html_tidy_quiet_messages = { "level" : "warnings" }

I tried changing makeprg in syntax_checkers/html/tidy.vim with:

    let fname = "'" . escape(expand('%'), "\\'") . "'"
    let makeprg = 'cat '.shellescape(fnameescape(fname)).' | sed ''s/{{\(\(.\)\?.*\?\)}}//g'' | /usr/bin/tidy'

...it did not like it at all. couldn't find anything helpful in debug.

@lcd047
Copy link
Collaborator

lcd047 commented Sep 26, 2014

@rafi You have an unbalanced } in your sed pattern. You can still do it like this if you insist. However, as I pointed out elsewhere, it wouldn't really do you much good.

@rafi
Copy link

rafi commented Sep 26, 2014

@lcd047 thanks for taking the time and implement my hack :) I missed a { actually, and it's better with an empty replacement: s/{{\(\(.\)\?.*\?\)}}//g. Together with ignoring attribute empty warnings, e.g.

let g:syntastic_html_tidy_ignore_errors = [
    \  '<html> attribute "lang" lacks value'
    \ ]

This is much better than the previous situation where tidy would totally lose its head around <head> :) and I ignored a bunch of errors I previously mentioned.

@KaoruDev
Copy link

KaoruDev commented May 2, 2015

@rafi thx! this worked for my ejs files:

let g:syntastic_html_tidy_ignore_errors = [
     \   '<img> escaping malformed URI reference'
     \ ]

@ldong
Copy link

ldong commented Sep 15, 2015

let g:syntastic_html_tidy_ignore_errors = [ '<template> is not recognized!' ]

Source: https://gist.github.com/khanghoang/345cd55541eb00952fe4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests