From ef6307a64e387f97f9cd1575db6d357bf35844b1 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Fri, 2 Apr 2021 04:32:32 -0400 Subject: [PATCH] Do not escape double quotes in tiddler DIVs to save space (#5383) * double quotes are no longer escaped in html bodies * changed tiddlyweb's html-div-tiddler; documentation French version still needs a translation though --- core/modules/utils/utils.js | 9 +++++++++ core/modules/widgets/view.js | 7 +++++++ core/templates/html-div-tiddler.tid | 2 +- editions/tw5.com/tiddlers/widgets/ViewWidget.tid | 1 + plugins/tiddlywiki/tiddlyweb/html-div-tiddler.tid | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index f3167fdfa..ecae23ec8 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -515,6 +515,15 @@ exports.htmlEncode = function(s) { } }; +// Converts like htmlEncode, but forgets the double quote for brevity +exports.htmlTextEncode = function(s) { + if(s) { + return s.toString().replace(/&/mg,"&").replace(//mg,">"); + } else { + return ""; + } +}; + // Converts all HTML entities to their character equivalents exports.entityDecode = function(s) { var converter = String.fromCodePoint || String.fromCharCode, diff --git a/core/modules/widgets/view.js b/core/modules/widgets/view.js index 30da34147..fed369771 100755 --- a/core/modules/widgets/view.js +++ b/core/modules/widgets/view.js @@ -65,6 +65,9 @@ ViewWidget.prototype.execute = function() { case "htmlencoded": this.text = this.getValueAsHtmlEncoded(); break; + case "htmltextencoded": + this.text = this.getValueAsHtmlTextEncoded(); + break; case "urlencoded": this.text = this.getValueAsUrlEncoded(); break; @@ -160,6 +163,10 @@ ViewWidget.prototype.getValueAsHtmlEncoded = function() { return $tw.utils.htmlEncode(this.getValueAsText()); }; +ViewWidget.prototype.getValueAsHtmlTextEncoded = function() { + return $tw.utils.htmlTextEncode(this.getValueAsText()); +}; + ViewWidget.prototype.getValueAsUrlEncoded = function() { return encodeURIComponent(this.getValueAsText()); }; diff --git a/core/templates/html-div-tiddler.tid b/core/templates/html-div-tiddler.tid index 6e3001cf5..640fe766b 100644 --- a/core/templates/html-div-tiddler.tid +++ b/core/templates/html-div-tiddler.tid @@ -5,5 +5,5 @@ title: $:/core/templates/html-div-tiddler This template is used for saving tiddlers as an HTML DIV tag with attributes representing the tiddler fields. -->``> -
`<$view field="text" format="htmlencoded" />`
+
`<$view field="text" format="htmltextencoded" />`
` diff --git a/editions/tw5.com/tiddlers/widgets/ViewWidget.tid b/editions/tw5.com/tiddlers/widgets/ViewWidget.tid index 3efdb98cb..c8910261e 100644 --- a/editions/tw5.com/tiddlers/widgets/ViewWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ViewWidget.tid @@ -29,6 +29,7 @@ The following formats can be specified in the `format` attribute: |!Format |!Description | |''text'' |Plain text (default) | |''htmlencoded'' |The field is displayed with HTML encoding | +|''htmltextencoded'' |The field is displayed with HTML encoding, only double quotes (") are not escaped. This creates a more compact htmlencoding appropriate for html text content, but //not// for attributes. | |''urlencoded'' |The field is displayed with URL encoding | |''doubleurlencoded'' |The field is displayed with double URL encoding | |''htmlwikified'' |The field is wikified according to the mode attribute and the resulting HTML returned as plain text (ie HTML elements will appear in plain text) | diff --git a/plugins/tiddlywiki/tiddlyweb/html-div-tiddler.tid b/plugins/tiddlywiki/tiddlyweb/html-div-tiddler.tid index 95e2a21b2..ff27343fc 100644 --- a/plugins/tiddlywiki/tiddlyweb/html-div-tiddler.tid +++ b/plugins/tiddlywiki/tiddlyweb/html-div-tiddler.tid @@ -5,5 +5,5 @@ title: $:/core/templates/html-div-tiddler This template is used for saving tiddlers as an HTML DIV tag with attributes representing the tiddler fields. This version includes the tiddler changecount as the field `revision`. -->`` revision="`<>`" bag="default"> -
`<$view field="text" format="htmlencoded" />`
+
`<$view field="text" format="htmltextencoded" />`
`