-
Notifications
You must be signed in to change notification settings - Fork 358
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
allow svg element #646
allow svg element #646
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested a rewrite of your README section to better capture the use case as suggested by the original issue. Feel free to change it if you find any details left out.
CHANGELOG.md
Outdated
@@ -2,6 +2,10 @@ | |||
|
|||
## UNRELEASED | |||
|
|||
- Clarified the use of SVGs with a new test and changes to documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved under the other unreleased heading. We will change the 'UNRELEASED' to a version number when we publish all the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done.
README.md
Outdated
@@ -265,6 +265,19 @@ allowedAttributes: { | |||
|
|||
With `multiple: true`, several allowed values may appear in the same attribute, separated by spaces. Otherwise the attribute must exactly match one and only one of the allowed values. | |||
|
|||
#### "What if I want to prevent attributes and tags from being truly lowercase?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### "What if I want to prevent attributes and tags from being truly lowercase?" | |
#### "What if I want to maintain the original case for SVG elements and attributes?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the change
README.md
Outdated
@@ -265,6 +265,19 @@ allowedAttributes: { | |||
|
|||
With `multiple: true`, several allowed values may appear in the same attribute, separated by spaces. Otherwise the attribute must exactly match one and only one of the allowed values. | |||
|
|||
#### "What if I want to prevent attributes and tags from being truly lowercase?" | |||
|
|||
if you got any tag like `linearGradient` and you want to prevent that tag from being lowercased so you have to pass `lowerCaseTags: false` in `parser` option and same for if you want to prevent any attribute like `viewBox` in svg tag from being lowercased so you have to pass `lowerCaseAttributeNames: false` in parser option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you got any tag like `linearGradient` and you want to prevent that tag from being lowercased so you have to pass `lowerCaseTags: false` in `parser` option and same for if you want to prevent any attribute like `viewBox` in svg tag from being lowercased so you have to pass `lowerCaseAttributeNames: false` in parser option. | |
If you're incorporating SVG elements like `linearGradient` into your content and notice that they're not rendering as expected due to case sensitivity issues, it's essential to prevent `sanitize-html` from converting element and attribute names to lowercase. This situation often arises when SVGs fail to display correctly because their case-sensitive tags, such as `linearGradient` and attributes like `viewBox`, are inadvertently lowercased. | |
To address this, ensure you set `lowerCaseTags: false` and `lowerCaseAttributeNames: false` in the parser options of your sanitize-html configuration. This adjustment stops the library from altering the case of your tags and attributes, preserving the integrity of your SVG content. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the changes.
Thanks for doing this! Small comments. |
In this PR I have added a test case for the SVG element to prevent the element from lowercased and same for the attributes.