From cd7a29c51e827e388f97da1555c822ffdce2845c Mon Sep 17 00:00:00 2001 From: bordun Date: Sun, 27 Dec 2020 14:52:14 +0100 Subject: [PATCH 1/2] html property: allow "href" attribute on "a" elements --- CHANGELOG.md | 7 ++++++- src/client/widgets/common/widget.js | 20 +++++++++++++------- src/client/widgets/frames/html.js | 12 ++---------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dec9095e..3352dcc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog +## 1.8.2 + +- widgets + - html property: allow "href" attribute on "a" elements + ## 1.8.1 - bug fixes - - script: stops triggering osc messages under some circumstances + - script: stops triggering osc messages under some circumstances ## 1.8.0 diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index f8c045a2..e146b1f1 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -1042,13 +1042,7 @@ class Widget extends EventEmitter { updateHtml(){ - var extraHtml = this.getProp('html') !== '' ? sanitizeHtml(this.getProp('html'), { - allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe'), - allowedAttributes: { - '*': [ 'title', 'class', 'style', 'type'], - 'img': [ 'src' , 'title', 'class', 'style', 'width', 'height'] - } - }) : null + var extraHtml = this.getProp('html') !== '' ? sanitizeHtml(this.getProp('html'), Widget.sanitizeHtmlOptions) : null if (this.extraHtml) { if (!extraHtml) { @@ -1111,6 +1105,18 @@ class Widget extends EventEmitter { } +Widget.sanitizeHtmlOptions = { + allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe'), + allowedAttributes: { + '*': [ 'title', 'class', 'style'], + 'img': [ 'src' , 'title', 'class', 'style', 'width', 'height'], + 'a': ['href', 'target'] + }, + transformTags: { + 'a': sanitizeHtml.simpleTransform('a', {target: '_blank'}) + } +} + Widget.parsersContexts = {} Widget.cssVariables = [ diff --git a/src/client/widgets/frames/html.js b/src/client/widgets/frames/html.js index c5f9118a..1803c7fe 100644 --- a/src/client/widgets/frames/html.js +++ b/src/client/widgets/frames/html.js @@ -4,14 +4,6 @@ var Widget = require('../common/widget'), sanitizeHtml = require('sanitize-html'), StaticProperties = require('../mixins/static_properties') -var sanitizeOptions = { - allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe'), - allowedAttributes: { - '*': [ 'title', 'class', 'style'], - 'img': [ 'src' , 'title', 'class', 'style', 'width', 'height'] - } -} - class Html extends StaticProperties(Widget, {bypass: true}) { static description() { @@ -43,7 +35,7 @@ class Html extends StaticProperties(Widget, {bypass: true}) { `}) this.noValueState = true - + if (!this.getProp('border')) this.container.classList.add('noborder') this.frame = DOM.get(this.widget, '.frame')[0] @@ -57,7 +49,7 @@ class Html extends StaticProperties(Widget, {bypass: true}) { var newHtml = this.frame.cloneNode(false) - newHtml.innerHTML = sanitizeHtml(this.getProp('html'), sanitizeOptions) + newHtml.innerHTML = sanitizeHtml(this.getProp('html'), Widget.sanitizeHtmlOptions) morph(this.frame, newHtml) From e8bc6a6d77c0ca8887515406d809c329fa2adb3a Mon Sep 17 00:00:00 2001 From: bordun Date: Sun, 3 Jan 2021 12:07:29 +0100 Subject: [PATCH 2/2] menu: fix displaying new lines in labels/values --- CHANGELOG.md | 4 ++++ src/client/widgets/basics/menu-base.js | 3 ++- src/scss/widgets/basics.scss | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3352dcc3..925e3fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,13 @@ ## 1.8.2 +- bug fixes + - menu: allow manual line breaks ("`\n`") in labels / values + - widgets - html property: allow "href" attribute on "a" elements + ## 1.8.1 - bug fixes diff --git a/src/client/widgets/basics/menu-base.js b/src/client/widgets/basics/menu-base.js index 1a980668..b653982f 100644 --- a/src/client/widgets/basics/menu-base.js +++ b/src/client/widgets/basics/menu-base.js @@ -49,8 +49,9 @@ class MenuBase extends Widget { var string = this.getProp('label') === 'auto' ? '%value' : this.getProp('label'), i = this.selected + if (i > -1 && string) { - this.text.innerHTML = iconify(String(string).replace(/%value/g, JSON.stringify(this.value)).replace(/%key/g, this.keys[i])) + this.text.innerHTML = iconify(String(string).replace(/%value/g, typeof this.value === 'string' ? this.value : JSON.stringify(this.value)).replace(/%key/g, this.keys[i])) } else { this.text.innerHTML = '' } diff --git a/src/scss/widgets/basics.scss b/src/scss/widgets/basics.scss index e6132fd5..6cfbd373 100644 --- a/src/scss/widgets/basics.scss +++ b/src/scss/widgets/basics.scss @@ -280,7 +280,7 @@ .item { - + white-space: pre; z-index: 1; overflow: hidden; div {