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

refactor/perf(post): use state machine to escape swig tag #4780

Merged
merged 1 commit into from
Sep 21, 2021

Conversation

SukkaW
Copy link
Member

@SukkaW SukkaW commented Sep 20, 2021

What does it do?

Replace regexp with the state machine.

How to test

git clone -b post-render-escape-swig https://github.com/sukkaw/hexo.git
cd hexo
npm install
npm test

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@SukkaW SukkaW mentioned this pull request Sep 20, 2021
@SukkaW SukkaW marked this pull request as draft September 20, 2021 22:17
Comment on lines -37 to +48
const restored = str.replace(rSwigPlaceHolder, _restoreContent(this.cache));
if (restored === str) return restored;
return this.restoreAllSwigTags(restored); // self-recursive for nexted escaping
const restored = str.replace(rSwigPlaceHolder, _restoreContent(this.stored));
return restored;
Copy link
Member Author

@SukkaW SukkaW Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self-recursive escaping is firstly introduced by @seaoak in #2321 trying to mitigate a back_tick_code inside a swig tag issue when the year is 2016. Since then, Hexo's post rendering mechanics has changed dramatically. When #2321 being merged in 2019, there is no longer required self-recursive as nested escaping will never happen. After this change, the unit test case still passed.

@SukkaW SukkaW marked this pull request as ready for review September 20, 2021 22:56
@SukkaW SukkaW merged commit 0c979bf into hexojs:master Sep 21, 2021
@stevenjoezhang
Copy link
Member

The rendering of left curly brackets has been changed in this pull request, which will affect the display of mathematical formulas (\begin{equation} becomes \beginequation})

Unit tests: https://github.com/hexojs/hexo/tree/post-render

@SukkaW
Copy link
Member Author

SukkaW commented Sep 24, 2021

The rendering of left curly brackets has been changed in this pull request, which will affect the display of mathematical formulas (\begin{equation} becomes \beginequation})

Unit tests: https://github.com/hexojs/hexo/tree/post-render

Ouch. I thought I have solved the issue. I will look into it now.

SukkaW added a commit to SukkaW/hexo that referenced this pull request Sep 24, 2021
@SukkaW SukkaW mentioned this pull request Sep 24, 2021
2 tasks
SukkaW added a commit that referenced this pull request Sep 24, 2021
@stevenjoezhang
Copy link
Member

There is another issue, the following markdown document will cause a rendering error

Disable rendering of Nunjucks tag `{{ }}`/`{% %}` and [tag plugins](/docs/tag-plugins) when enabled

See https://github.com/hexojs/site/runs/3680904140

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.

None yet

2 participants