Sorry, we don't support your browser.  Install a modern browser
This post is closed.

Remove unnecessary escapes in blocks JSON data#518

Text in blocks data is currently saved to files with a lot of unnecessary escapes. It seems to escape all non-ASCII characters (why in the name of UTF-8?), and characters like forward slashes (making HTML very verbose).

Here’s a paragraph saved by a Writer field:

<p>L’étrange <em>“petit”</em> café?!</p>

When saved as a text block, it then looks like this (extracting the JSON string only):

"<p>L\u2019\u00e9trange <em>\u201cpetit\u201d<\/em> caf\u00e9?!<\/p>"

But it could be escaped much less aggressively. In fact, none of the characters there needs escaping in a JSON string, only newlines and " would need escaping! So ideally it would be saved as:

"<p>L’étrange <em>“petit”</em> café?!</p>"

Ultimately that doesn’t change things much, except that it takes a tiny bit more space on disk (not really a problem) and makes it hard to check content in text files (which can be a problem for development / debugging / user support).

7 months ago

It gets much worse with non-latin scripts.

Writer field output:

<p>秀逸な画像からの除外</p><p>مذكرات الشاب إنديانا جونز</p>

Blocks text output:

"<p>\u79c0\u9038\u306a\u753b\u50cf\u304b\u3089\u306e\u9664\u5916<\/p><p>\u0645\u0630\u0643\u0631\u0627\u062a \u0627\u0644\u0634\u0627\u0628 \u0625\u0646\u062f\u064a\u0627\u0646\u0627 \u062c\u0648\u0646\u0632<\/p>"
7 months ago

In pretty: true mode, the blocks field already behaves like that.

I’ve created a PR to use this also in the default mode: https://github.com/getkirby/kirby/pull/5099

7 months ago
1
Changed the status to
In progress
6 months ago
Changed the status to
In upcoming releases
6 months ago
1

Thanks a bunch Lukas!

6 months ago
Changed the status to
Completed
6 months ago