Wrong encoding for partial

感情迁移 提交于 2019-12-22 00:31:08

问题


I am running compass watch my_project on Windows XP.

  • index.scss:

    @charset "UTF-8";
    @import 'partial';
    // ...
    
  • _partial.scss:

    p:before {
        content: '•';
    }
    
  • config.rb:

    encoding = "utf-8"
    
  • Generated index.css:

    @charset "UTF-8";
    /* line 1, ../sass/_partial.scss */
    p:before {
      content: 'ÔÇó';
    }
    // ...
    

How do I make Compass/Sass interpret the partial as UTF-8? Is there perhaps an environment variable that I can set to change default character encoding used by Ruby (compass is a Ruby app)?


回答1:


On my Windows 7 machine, it worked to add the following line to my project's config.rb

Encoding.default_external = 'utf-8'

Also found a great GUI for compass / less / JS compression: http://koala-app.com/




回答2:


Maybe it is not a direct answer, but even if you can't make Compass/Sass interpret UTF as you want, you may simply try to use unicode escape:

p:before {
    content: "\2022";
}

Where 2022 is hexadecimal code for your symbol. To get this code I executed this in irb:

irb> "•"[0].ord.to_s(16)
=> "2022"

Probably not a good solution if you have a lot of unicode chars, but at least a workaround. For example, FontAwesome uses it in its stylesheets.




回答3:


Apart from escaping the character (predictable, but tedious) as suggested by @NIA, there are two other ways around this:

  1. Add @charset "utf-8"; to the top of _partial.scss
  2. Save _partial.scss as "UTF-8 with BOM".

Judging by what I've read so far, this seems to be a generic Ruby/WIN issue with incorrect encoding detection/fallback when building strings read from files on disk.



来源:https://stackoverflow.com/questions/14501003/wrong-encoding-for-partial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!