Allow special characters in Lua prefix and suffix

--lua-suffix='});^M' didn't work, so taking this approach instead
This commit is contained in:
Kim Alvefur 2023-07-31 08:32:38 +02:00
parent c4de13e874
commit 03560a3d84

View File

@ -57,7 +57,15 @@ func NewLuaEncoder(prefs LuaPreferences) Encoder {
"\\", "\\\\",
"\177", "\\127",
)
return &luaEncoder{prefs.DocPrefix, prefs.DocSuffix, prefs.UnquotedKeys, escape}
unescape := strings.NewReplacer(
"\\'", "'",
"\\\"", "\"",
"\\n", "\n",
"\\r", "\r",
"\\t", "\t",
"\\\\", "\\",
)
return &luaEncoder{unescape.Replace(prefs.DocPrefix), unescape.Replace(prefs.DocSuffix), prefs.UnquotedKeys, escape}
}
func (le *luaEncoder) PrintDocumentSeparator(writer io.Writer) error {