Skip to content

Added: setting for unescaping special chars (#46)#47

Open
signebedi wants to merge 2 commits intomatthiask:mainfrom
signebedi:special-char-encoding-branch
Open

Added: setting for unescaping special chars (#46)#47
signebedi wants to merge 2 commits intomatthiask:mainfrom
signebedi:special-char-encoding-branch

Conversation

@signebedi
Copy link

Based on discussion in #46. I added a default setting called "unescape_special_chars".

DEFAULT_SETTINGS = {
    ...
    "unescape_special_chars": False, # see discussion https://github.com/matthiask/html-sanitizer/issues/46
}

When true, special characters are added back to the HTML immediately before returning:

        # see discussion https://github.com/matthiask/html-sanitizer/issues/46
        if self.unescape_special_chars:
            html = ( html
                    .replace("&", "&")
                    .replace("&lt;", "<")
                    .replace("&gt;", ">")
            )

I welcome feedback. This is a minimalist change intended only to give end users the ability to retain some of the special characters that are stripped out during the sanitation process. If I have broken assumptions, or if I have missed other special characters, please feel free to make note of these and I am happy to make further changes before the code is merged.

@signebedi signebedi marked this pull request as ready for review June 14, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant