GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 395 forks source link

Class gets lost on edit of link #557

Closed jnnkB closed 3 years ago

jnnkB commented 4 years ago

I recently discoverd, that if I have a link with a certain class and I change the link or make it external, the class gets lost. Is this intended behavior?

anthonyjb commented 4 years ago

Can you provide an example please.

jnnkB commented 4 years ago

I created a tool to upload files like PDF's and create a link for them. The link looks like this:

<a class="uploaded-file" href="/url/of/file.pdf">Name of File</a>

If I than edit the link by making it external, the class disappears. Unfortunately this breaks my website because I use the class to than check which documents can be deleted and which I have to keep and because the class is missing the document gets deleted.

tokpl commented 3 years ago

https://github.com/GetmeUK/ContentTools/blob/master/build/content-tools.js#L9740

You must change these lines of code: content-tools.js

FROM

          if (detail.href) {
            a = new HTMLString.Tag('a', detail);
            element.content = element.content.format(from, to, a);
            element.content.optimize();
          }

TO

          if (detail.href) {
            a = new HTMLString.Tag('a', detail);
            a.attr("class",$(".ct--pseudo-select").parent().attr("class"))
            element.content = element.content.format(from, to, a);
            element.content.optimize();
          }
anthonyjb commented 3 years ago

This issue is addressed in the latest release: https://github.com/GetmeUK/ContentTools/releases/tag/1.6.13

anthonyjb commented 3 years ago

@tokpl thanks for pointing me at the code that needed addressing, I took a different approach but it was really helpful to have a starting point.

@jnnkB thanks fort the error report.