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

Fixes for protection string when there are empty attributes #2

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const prettify = (html, config) => {
const ignore = validated_config.ignore.length > 0
trim = validated_config.trim

const protectionString = config?.protection_string || '_&i-£___£%_';
const protectionString = config?.protection_string || '_!i-£___£%_';

/* Protect ignored elements. */
if (ignore) {
Expand Down
20 changes: 10 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ export const ignoreElement = (html, ignore, mode, protectionString) => {
const protectElement = (match, capture, protectionString) => {
return match.replace(capture, (match) => {
return match
.replace(/</g, protectionString + 'lt')
.replace(/>/g, protectionString + 'gt')
.replace(/\n/g, protectionString + 'nl')
.replace(/\r/g, protectionString + 'cr')
.replace(/\s/g, protectionString + 'ws')
.replace(/</g, '-' + protectionString + 'lt-')
.replace(/>/g, '-' + protectionString + 'gt-')
.replace(/\n/g, '-' + protectionString + 'nl-')
.replace(/\r/g, '-' + protectionString + 'cr-')
.replace(/\s/g, '-' + protectionString + 'ws-')
})
}

Expand Down Expand Up @@ -128,11 +128,11 @@ export const trimify = (html, trim) => {
const unprotectElement = (match, capture, protectionString) => {
return match.replace(capture, (match) => {
return match
.replace(new RegExp(protectionString + 'lt', "g"), '<')
.replace(new RegExp(protectionString + 'gt', "g"), '>')
.replace(new RegExp(protectionString + 'nl', "g"), '\n')
.replace(new RegExp(protectionString + 'cr', "g"), '\r')
.replace(new RegExp(protectionString + 'ws', "g"), ' ')
.replace(new RegExp('-' + protectionString + 'lt-', "g"), '<')
.replace(new RegExp('-' + protectionString + 'gt-', "g"), '>')
.replace(new RegExp('-' + protectionString + 'nl-', "g"), '\n')
.replace(new RegExp('-' + protectionString + 'cr-', "g"), '\r')
.replace(new RegExp('-' + protectionString + 'ws-', "g"), ' ')
})
}

Expand Down