Skip to content

Enhancement: Removing unused @chaset at-rulers and possible encoding convertions #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iAdramelk opened this issue Aug 12, 2014 · 13 comments

Comments

@iAdramelk
Copy link
Member

Never used @charset at-rules myself and not really understand why somebody may want to make css files with different @charset values (importing css from external libraries perhaps?), but specificaition allows it.

Good idea will probably to do the following: If any of imported files have @charset, then convert file to UTF-8 from this charset and remove @charset at-rule.

But it is not really a urgent feature, it can be done sometimes later.

@MoOx
Copy link
Contributor

MoOx commented Aug 12, 2014

It happened many times for me to have to deploy utf8 CSS (that contain for example utf8 chars for :before or :after) on server that only serve windows latin or iso-whatever by default.

I think we should just put one at the top (see my example before) if one @charset is detected somewhere since this plugin already open files as utf8 (by default)

If encoding option if different than a charset in one file, we can just throw a warning & try conversion but this will not work if you want to convert utf8 to window latin1 or iso-* (you will loose some stuff).

I'm not sure removing the charset is a good idea, but handling conversion is a nice one.

@iAdramelk
Copy link
Member Author

I think that simplest way is to think about any file without @charset as file in UTF-8. And if file explicitly says that it is in not in UTF-8, then we just need to convert it from that charset to UTF-8 before including.

But you are probably right, if we removed @charset from anywhere in the files, we have to declare our own in the beginning of the document.

Something like this:

  1. If none of the files have @charset do nothing.
  2. Then we meet first file with @charset:
    • Read file in declared encoding.
    • Convert it to UTF-8 if necessary.
    • Remove file's @charset declaration.
    • Add @charset UTF-8 to the top of the root file.

@MoOx
Copy link
Contributor

MoOx commented Aug 12, 2014

Exactly. I'll update this a bit

  1. If none of the files have @charset do nothing.
  2. Then we meet first file with @charset that's not utf8:
    • Read file in declared encoding.
    • Convert it to UTF-8.
    • Remove file's @charset declaration.
    • Add @charset UTF-8 to the top of the root file.

@MoOx
Copy link
Contributor

MoOx commented Aug 12, 2014

One thing I think we won't need to handle is conversion, this will be done automatically because we will read with declared encoding (eg: read @imported file & if @charset detected, re-read it with this encoding)

@iAdramelk
Copy link
Member Author

I think that original is more bulletproof. :) Consider this situation:

  1. Server is configured to serve files as "latin1".
  2. Parent file don't have @charset.
  3. Included file have @charset "utf8" for special characters.

If we leave @charset there it is, it will not work (it have to be first line of the file). If we just remove it, then server will serve file as "latin1". So to make it work we have to add @charset "utf8" to the beginning of the file.

@MoOx
Copy link
Contributor

MoOx commented Aug 12, 2014

Good point.
So:

  1. If none of the files have @charset do nothing.
  2. Then we meet first file with @charset:
    • if not utf8, (re)read file in declared encoding.
    • remove file's @charset declaration.
    • add @charset UTF-8 to the top of the root file.

@iAdramelk
Copy link
Member Author

Yes, exactly.

@TrySound
Copy link
Member

TrySound commented Jan 9, 2016

@MoOx Does this make sense now?

@MoOx
Copy link
Contributor

MoOx commented Jan 10, 2016

Why not now?

@TrySound
Copy link
Member

cssnext issue was closed and I always use only utf-8 :)

@MoOx
Copy link
Contributor

MoOx commented Jan 11, 2016

Yeah but you are not alone? What is the problem of keeping this issue open?

@TrySound
Copy link
Member

@MoOx Will be fixed in 10 or more version ... :)

@MoOx
Copy link
Contributor

MoOx commented Jan 27, 2016

Nobody asked for this in a while, I guess we can close...

@MoOx MoOx closed this as completed Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants