Skip to content

Commit

Permalink
early return
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Jan 17, 2024
1 parent 8fd34c9 commit 5dd70e8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/hexo/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class PostRenderEscape {
* @returns string
*/
escapeAllSwigTags(str: string) {
if (!/(\{\{.+?\}\})|(\{#.+?#\})|(\{%.+?%\})/.test(str)) {
return str;
}
let state = STATE_PLAINTEXT;
let buffer = '';
let output = '';
Expand All @@ -85,13 +88,13 @@ class PostRenderEscape {
if (state === STATE_PLAINTEXT) { // From plain text to swig
if (char === '{') {
// check if it is a complete tag {{ }}
if (next_char === '{' && /\{\{.+?\}\}/.test(str)) {
if (next_char === '{') {
state = STATE_SWIG_VAR;
idx++;
} else if (next_char === '#' && /\{#.+?#\}/.test(str)) {
} else if (next_char === '#') {
state = STATE_SWIG_COMMENT;
idx++;
} else if (next_char === '%' && /\{%.+?%\}/.test(str)) {
} else if (next_char === '%') {
state = STATE_SWIG_TAG;
idx++;
swig_tag_name = '';
Expand Down

0 comments on commit 5dd70e8

Please sign in to comment.