Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Haml + commonmarker issue #1185

@renatolond

Description

@renatolond

Hey, thanks for Haml, it's great!

I've been using haml in roda and today I ran into an issue that I'm not sure if it's a misconfiguration, but I can't seem to find a way to fix it.

I'm using haml templates and inside one of them I use a markdown fragment.

I've managed to isolate the issue in this reduced example:

%p
  Hello world!
  :markdown
    [github](https://github.com)

Running this gives:

❯ haml render --require commonmarker --require tilt/commonmarker foo.haml                                                              [17:39:34]
/home/renatolond/.rvm/gems/ruby-3.4.1/gems/commonmarker-2.0.4-x86_64-linux/lib/commonmarker.rb:38:in 'Commonmarker.to_html': text must be UTF-8 encoded; got ASCII-8BIT! (TypeError)

      raise TypeError, "text must be UTF-8 encoded; got #{text.encoding}!" unless text.encoding.name == "UTF-8"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/tilt-2.6.0/lib/tilt/commonmarker.rb:41:in 'block in <top (required)>'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/tilt-2.6.0/lib/tilt/template.rb:593:in 'Tilt::StaticTemplate#prepare'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/tilt-2.6.0/lib/tilt/template.rb:126:in 'Tilt::Template#initialize'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/filters/tilt_base.rb:8:in 'Class#new'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/filters/tilt_base.rb:8:in 'Haml::Filters::TiltBase.render'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/filters/tilt_base.rb:39:in 'Haml::Filters::TiltBase#static_compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/filters/tilt_base.rb:34:in 'Haml::Filters::TiltBase#compile_with_tilt'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/filters/markdown.rb:7:in 'Haml::Filters::Markdown#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/filters.rb:62:in 'Haml::Filters#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:71:in 'Haml::Compiler#compile_filter'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:42:in 'Haml::Compiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:59:in 'block in Haml::Compiler#compile_children'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:20:in 'block (2 levels) in Haml::Compiler::ChildrenCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:49:in 'Haml::Compiler::ChildrenCompiler#moving_lineno'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:20:in 'block in Haml::Compiler::ChildrenCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:17:in 'Array#each'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:17:in 'Haml::Compiler::ChildrenCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:59:in 'Haml::Compiler#compile_children'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:87:in 'block in Haml::Compiler#compile_tag'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/tag_compiler.rb:26:in 'Haml::Compiler::TagCompiler#compile_contents'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/tag_compiler.rb:17:in 'Haml::Compiler::TagCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:87:in 'Haml::Compiler#compile_tag'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:50:in 'Haml::Compiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:59:in 'block in Haml::Compiler#compile_children'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:20:in 'block (2 levels) in Haml::Compiler::ChildrenCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:49:in 'Haml::Compiler::ChildrenCompiler#moving_lineno'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:20:in 'block in Haml::Compiler::ChildrenCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:17:in 'Array#each'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler/children_compiler.rb:17:in 'Haml::Compiler::ChildrenCompiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:59:in 'Haml::Compiler#compile_children'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:36:in 'Haml::Compiler#compile'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/compiler.rb:26:in 'Haml::Compiler#call'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/temple-0.10.3/lib/temple/engine.rb:51:in 'block in Temple::Engine#call'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/temple-0.10.3/lib/temple/engine.rb:51:in 'Array#each'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/temple-0.10.3/lib/temple/engine.rb:51:in 'Enumerable#inject'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/temple-0.10.3/lib/temple/engine.rb:51:in 'Temple::Engine#call'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/cli.rb:91:in 'Haml::CLI#generate_code'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/lib/haml/cli.rb:15:in 'Haml::CLI#render'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/thor-1.3.2/lib/thor.rb:538:in 'Thor.dispatch'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/thor-1.3.2/lib/thor/base.rb:584:in 'Thor::Base::ClassMethods#start'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/gems/haml-6.3.0/exe/haml:6:in '<top (required)>'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/bin/haml:25:in 'Kernel#load'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/bin/haml:25:in '<main>'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/bin/ruby_executable_hooks:22:in 'Kernel#eval'
        from /home/renatolond/.rvm/gems/ruby-3.4.1/bin/ruby_executable_hooks:22:in '<main>'

It seems the file is read as UTF-8 (in lib/haml/cli.rb, inside the generate_code function, I can see that tmeplate.encoding is #<Encoding:UTF-8>), however, it seems the child node is ASCII.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions