[Redactor] How to disable data-* parameters when upload file?

Hi,

I’m using Redactor 3 for a customer, and when he’s uploading a file, on the generated html there is :

<p><a href="assets/uploads/2020/myfile.png" data-file="assets/uploads/2020/myfile.png" data-name="myfile.png">myfile.png</a></p>

I want to have something like this :

<p><a href="assets/uploads/2020/myfile.png">myfile.png</a></p>

Or best and more flexible, is there a way to set a template for the generated link ?

There’s no template or configuration for that - that’s meant for Redactor internally to track the source file (that could theoretically be an asset ID of sorts).

I’ve made a note to look into this to see if there’s a way to disable that or to filter it out on save to leave the cleanest possible markup.

Just to provide some feedback, redactor.js does currently offer an option to disable the data-image on images, but not the data-file or data-name attributes on file links.

I’ll keep the internal feature request open to look at a custom cleanup function of sorts that strips it on save.

Thanks for the feedback :slight_smile:
I have asked because I get issues on a website because of this data attribute : I have to remove them manually to solved it.
So on option to removed them globally could be useful :slight_smile:

It would be possible to clean it up server side with a snippet that parses the content (regex or domdocument based perhaps) but I don’t readily have an example of that. This code on StackOverflow may serve as an example, except you’re looking for attributes data-file, data-image rather than style: https://stackoverflow.com/a/3026411/1277345

Out of curiosity though, what sort of issues is this causing in your front-end? Is it being interpreted by some javascript library or something like that?

The problem is when my customer upload a file with special character (space or accent) within Redactor, the data-file attribute doesn’t parse it correctly and don’t close the double quote of the data-file atrribute.
Example :

 <a href="assets/uploads/Courrier distribution.pdf" data-file="assets/uploads/Courrier&#8230;</a>

That is why I asked for a way to modify the template.