Using encoding declarations (charset=, encoding=, @charset) for auto-detection
When both “Auto-Detect” and “Refer to encoding declaration” are activated in the Format preferences pane, CotEditor reads the following types of encoding declarations (if present) — charset=, encoding=, @charset — when opening a file. If written properly, these declarations will be used to determine the file's character encoding.
A declaration can be anywhere in the document, the one either in comment area or in a plain sentence is detected. When you want to use a phrase such as “charset=UTF-8” even though your document's encoding is not UTF-8, you need to put an actual encoding declaration prior to the phrase, or, turn off “Refer to encoding declaration” in the Format preferences.
- To make auto-detection of character encoding work, you have to put an equal character (“=”, no other characters) right after “charset” or “encoding.”
- The encoding name which comes after “charset=” or “encoding=” can be without double-quotes (") around.
- In the case there are multiple encoding declarations in your document, CotEditor uses the first one to determine the character encoding.
- When the encoding is declared as Shift JIS (written like charset="Shift_JIS"), CotEditor chooses the prioritized one (the upper one in the encoding list) between Japanese (Shift JIS) and Japanese (Shift JIS X0213).
=> Setting the priority of encoding auto-detection
See also