threedaymonk / htmlbeautifier

A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates.
MIT License
333 stars 58 forks source link

Undefined local variable #4

Closed paulmsmith closed 11 years ago

paulmsmith commented 11 years ago

Hello,

Hope you're well. I'm seeing an error when running the gem. It was working fine but has now started producing this:

/Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/lib/htmlbeautifier/parser.rb:58:in `rescue in dispatch': undefined local variable or method `match' for #<HtmlBeautifier::HtmlParser:0x007f8124d84260> on line 369 (RuntimeError)
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/lib/htmlbeautifier/parser.rb:42:in `dispatch'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/lib/htmlbeautifier/parser.rb:28:in `scan'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/lib/htmlbeautifier/beautifier.rb:20:in `scan'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/bin/htmlbeautifier:5:in `beautify'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/bin/htmlbeautifier:13:in `block (2 levels) in <top (required)>'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/bin/htmlbeautifier:12:in `open'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/bin/htmlbeautifier:12:in `block in <top (required)>'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/bin/htmlbeautifier:10:in `each'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bundler/gems/htmlbeautifier-2be0d969f30e/bin/htmlbeautifier:10:in `<top (required)>'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bin/htmlbeautifier:19:in `load'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bin/htmlbeautifier:19:in `<main>'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'

I'm using this in my gem file:

gem "htmlbeautifier", git: "https://github.com/threedaymonk/htmlbeautifier.git", branch: "ie-cc"

I wonder if some of my mark-up is causing it but have no idea how to track it down. Any help would be massively appreciated. :)

threedaymonk commented 11 years ago

Can you make a minimal input file that shows this behaviour?

paulmsmith commented 11 years ago

Hi thanks for getting back to me. I basically run this:

htmlbeautifier build/*/*.html

On this set of files. (http://files.airfront.co.uk/directory/08_temp/build.zip)

Thanks again for this gem its awesome.

threedaymonk commented 11 years ago

I narrowed the problem down to one line in one file (templates/icons.html):

<p class="group"><span data-icon="<" aria-hidden="true"></span> icon character code "<strong><</strong>"</p>

This isn't valid HTML. If you change the two instances of < to &lt;, it should work.

I've improved the error reporting slightly: it now tells you the filename that failed, and it doesn't blank a file on error.

paulmsmith commented 11 years ago

Legend! Of course! Thank you. I owe you a beer/coffee!