Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Preview dialog - Dompurify parsing error with image shortcode
Textpattern 4.9-dev latest (and 4.9-beta1), PHP 8.3
Is there any reason why a shortcode with image code cannot be previewed with both “Sanitize” and “Tags” enabled?
Shortcode:
<txp:images id='<txp:yield name="id" />' break=''>
<figure class="article-img" itemprop="image" itemscope itemtype="http://schema.org/ImageObject">
<picture>
<img src="<txp:image_url thumbnail='1' />" srcset="<txp:image_url /> 2x" alt="<txp:image_info type='alt' />" itemprop="url contentUrl"><txp:hide><txp:image_info type='w' />w</txp:hide>
</picture>
<figcaption itemprop="caption"><txp:image_info type="caption" escape="tidy, textile" /></figcaption>
</figure>
</txp:images>
Steps to reproduce:
- create a shortcode form with above content, named it
my_images
. - insert image(s) in article using above shortcode:
<txp::my_images id="324,45,856" />
- preview article in dialog widget
- enable tag parsing, wait for rendering; the preview remains “greyed out”
Error in browser console (pointing to `textpattern.js:1415:109`):
Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'node.replaceWith(wrapNode).remove')
Note:
- this is a very simplified shortcode stripping out as much as possible. Most of my other shortcode(s) seem to render correctly.
- check OFF “Sanitize“, enable tag parsing works correctly
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
Related to this, I guess. DOMPurify has introduced some breaking changes that I need to grok yet. Otherwise, we’d have to switch back to 3.1.5 I’m afraid. Thanks for the report.
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
etc wrote #338039:
Related to this, I guess. DOMPurify has introduced some breaking changes that I need to grok yet. Otherwise, we’d have to switch back to 3.1.5 I’m afraid. Thanks for the report.
Not sure, as those are related to the latest DOMPurify, I see the same issue with Textpattern 4.9-beta1.
Here is another shortcode that triggers the error (again reduce to the bare minimum):
<txp:file_download_list id='<txp:yield name="id" />'>
<span itemscope itemtype="https://schema.org/DataDownload"><a href="<txp:file_download_link />" itemprop="url contentUrl"><span itemprop="name"><txp:file_download_name title /></span></a></span>
</txp:file_download_list>
(as used on the Sandspace page)
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
You are probably right, it must be my silly attempt to visualise elements with sanitised attributes (like itemscope
etc). BTW, how should it be done? For example, after clean-up
<span itemscope itemtype="https://schema.org/DataDownload">Download me!</span>
becomes
<span>Download me!</span>
But on Text preview they look the same. How should we warn the user that some (potentially harmful) attributes have been removed?
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
Conundrum…
On the one hand the content of a shortcode should be considered “safe” I think (approved by higher level people, can only be modified by people with the right privileges). The only way to send something naughty to the shortcode content is trough its attributes, which you can see when previewing the page in the dialog box (with only “sanitise” enabled)
<txp::shortcode_name attribute="value" other-attribute="value" />
On the other hand, the logic of tag parsing with “sanitise” enabled would suggest to neuter and flag those potentially problematic attributes. But the user reviewing the article expects the tag to be rendered.
Hmm. Thinking loud – is it possible to display both the rendered tag(sanitised) and its full source? That might be expensive performance wise, no idea. The reviewer can of course see the same by checking the source code tab of the dialog box – but for a long article that might not be all that easy.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
Oleg, after your latest code changes over the WE, it works much better. The shortcodes
are rendered as expected, no more browser console spam. TY.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
phiw13 wrote #338079:
Oleg, after your latest code changes over the WE, it works much better. The
shortcodes
are rendered as expected, no more browser console spam. TY.
Much better.
There is only one behavior that could annoy redactors: links are opened in the same window (users lose the Textpattern interface)…
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
Fair point, will change, thanks.
Another point I’m thinking of: do we need to see (faded out) representations of (normally invisible) sanitized elements (scripts, styles etc) in text preview? They can be annoying, but, on the other hand, partly explain why the orange warning is flashing.
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
etc wrote #338082:
Another point I’m thinking of: do we need to see (faded out) representations of (normally invisible) sanitized elements (scripts, styles etc) in text preview? They can be annoying, but, on the other hand, partly explain why the orange warning is flashing.
The point of that sanitised view is to show all potentially dangerous unsafe elements within the article body, so I would argue that yes, that is useful to editors.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
Your latest commit is perfect!
Thank you lot. The target="_new"
attribute injected to links within the preview article dialog makes sens with the “preview” link (eye icon).
Just an idea rising into my brain:
Could it be possible (as the availability of a custom.css for the admin interface) to offer us a css file into order to style some aspect of the dialog content? I think of short codes which could gain some specific’s layout. I tried to inject CSS into :host{} in order to interact with the Shadow DOM without any success…
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
Pat64 wrote #338089:
Could it be possible (as the availability of a custom.css for the admin interface) to offer us a css file into order to style some aspect of the dialog content? I think of short codes which could gain some specific’s layout. I tried to inject CSS into :host{} in order to interact with the Shadow DOM without any success…
I’d love to, but injecting css rules into shadow dom is rather cumbersome (on purpose). Currently, the rules are stored in textpattern/preview.css
, which you can edit as desired. The diagnostics would complain about modified files, though. Should we simply exclude it from checksums? Or should it be made part of the theme, or something else?
To enable styling shortcodes and txp tags, some extra markup is necessary, will think about it.
Offline
Re: Preview dialog - Dompurify parsing error with image shortcode
etc wrote #338090:
I’d love to, but injecting css rules into shadow dom is rather cumbersome (on purpose). Currently, the rules are stored in
textpattern/preview.css
, which you can edit as desired. The diagnostics would complain about modified files, though. Should we simply exclude it from checksums? Or should it be made part of the theme, or something else?
Simply excluding it from checksums would be enough, I think.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline