-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the need to prune raw tags, simplify logic of replacement
- Loading branch information
Showing
9 changed files
with
26 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,14 @@ | ||
const START_ESCAPE_STR = '{% raw %}'; | ||
const END_ESCAPE_STR = '{% endraw %}'; | ||
const REGEX = new RegExp('{% *raw *%}(.*?){% *endraw *%}', 'gs'); // eslint-disable-line no-useless-escape | ||
|
||
function addEscapeTags(match) { | ||
return `${START_ESCAPE_STR}${match}${END_ESCAPE_STR}`; | ||
} | ||
|
||
function removeEscapeTags(_, p1) { | ||
return p1; | ||
} | ||
const REGEX = new RegExp('{% *raw *%}(.*?){% *endraw *%}', 'gs'); | ||
|
||
function preEscapeRawTags(pageData) { | ||
return pageData.replace(REGEX, addEscapeTags); | ||
return pageData.replace(REGEX, `${START_ESCAPE_STR}$&${END_ESCAPE_STR}`); | ||
} | ||
|
||
module.exports = { | ||
renderEscaped(nunjucks, pageData, variableMap = {}, options = {}) { | ||
const escapedPage = preEscapeRawTags(pageData); | ||
return nunjucks.renderString(escapedPage, variableMap, options); | ||
}, | ||
|
||
/** | ||
* RemoveNunjucksEscapes removes raw tags from page data when processing | ||
* Downstream calls to nunjuckUtils.renderEscaped will be essentially the same as nunjucks.renderString | ||
* This ensures that we remove {{ and }} from the final output which prevents problem with Vue | ||
*/ | ||
removeNunjucksEscapes(pageData) { | ||
return pageData.replace(REGEX, removeEscapeTags); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters