Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextPlugin removes source code HTML on save #667

Open
Noah3141 opened this issue Jan 30, 2024 · 5 comments
Open

TextPlugin removes source code HTML on save #667

Noah3141 opened this issue Jan 30, 2024 · 5 comments
Labels

Comments

@Noah3141
Copy link

Noah3141 commented Jan 30, 2024

I have had something similar occur in two separate projects.

In one, I was making modifications to the source HTML, like adding another style attribute to a tag, and my new attribute would be gone on save, leaving only the previous state of the tag.

In the current one, all tag attributes are getting purged on TextPlugin save.

In both these cases the TextPlugins were created within placeholder fields in the following manner:

block_text_plugin: TextPlugin = add_plugin(
    placeholder=subsection_placeholder,
    plugin_type=text_plugin,
    language="en-us",
    target=block_plugin,
    body=block["body"],
)

Where block['body'] contains HTML elements, including some <ol style="list-style-type:lower-alpha">.

Before: <ol style="list-style-type:lower-roman">
After: <ol>

djangocms-text-ckeditor 5.1.5

@fsbraun
Copy link
Sponsor Member

fsbraun commented Jan 30, 2024

djangocms-text-ckeditor sanitizes any HTML before safe. You might need to configure the sanitizer. See here: https://github.com/django-cms/djangocms-text-ckeditor#configurable-sanitizer

@Noah3141
Copy link
Author

Noah3141 commented Jan 30, 2024

It seems like it would certainly be the root cause, but I can't seem to get the settings to take effect:

I managed to get the global setting,

TEXT_HTML_SANITIZE = False

to turn it off altogether to work (i.e. keep list styles), but I suspect I want a bit more precision.

Specifically providing "style" inside the settings.py did not preserve the style attributes.

TEXT_ADDITIONAL_ATTRIBUTES = ('style',)

So, now I'm trying the custom parser. I have it successfully hooked up, because I can see its print statements when made within the parse function

from djangocms_text_ckeditor.sanitizer import AllowTokenParser


Keep = bool
class ListAttributeParser(AllowTokenParser):
    def parse(self, attribute: str, val: str) -> Keep:
        if attribute == "style": 
            print(val) # -->  list-style-type:lower-roman
            return True
        else: return False

I did add:

   'basicEntities': False,
   'entities': False,

(They are not duplicate keys)

@fsbraun
Copy link
Sponsor Member

fsbraun commented Jan 31, 2024

Does it work? I must say, I am not an expert of htmllib.

@Noah3141
Copy link
Author

I have not gotten the custom parser to work, no. Switching True/False with each other didn't seem to have an effect.

Copy link

stale bot commented May 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants