Fix encoding of text values

- respect newlines
- encode only chars that need it