-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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(post/tag): render tag before content #4171
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ef9c9b
refactor(post): render tag before content
SukkaW 32d5638
test(post): add cases for issue #3346
SukkaW 54d45e3
refactor(post): simplify the <escape> regex pattern
SukkaW 1b0819a
refactor(tag): add extra blankline in tag.run()
SukkaW 1bc7e78
refactor(tag): remove escape
SukkaW 3bdf42d
fix(tag): simplify error handle
SukkaW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ const stripIndent = require('strip-indent'); | |
const { cyan } = require('chalk'); | ||
const nunjucks = require('nunjucks'); | ||
const Promise = require('bluebird'); | ||
const placeholder = '\uFFFC'; | ||
const rPlaceholder = /(?:<|<)!--\uFFFC(\d+)--(?:>|>)/g; | ||
|
||
class NunjucksTag { | ||
constructor(name, fn) { | ||
|
@@ -77,7 +75,7 @@ class NunjucksBlock extends NunjucksTag { | |
} | ||
|
||
run(context, args, body) { | ||
return this._run(context, args, trimBody(body)); | ||
return this._run(context, args, trimBody(body)) + '\n'; | ||
} | ||
} | ||
|
||
|
@@ -111,7 +109,7 @@ class NunjucksAsyncBlock extends NunjucksBlock { | |
body = () => result || ''; | ||
|
||
this._run(context, args, trimBody(body)).then(result => { | ||
callback(err, result); | ||
callback(err, result && `${result}\n`); | ||
}); | ||
}); | ||
} | ||
|
@@ -228,15 +226,8 @@ class Tag { | |
options = {}; | ||
} | ||
|
||
const cache = []; | ||
|
||
const escapeContent = str => `<!--${placeholder}${cache.push(str) - 1}-->`; | ||
|
||
str = str.replace(/<pre><code.*>[\s\S]*?<\/code><\/pre>/gm, escapeContent); | ||
Comment on lines
-231
to
-235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hexo only uses In |
||
|
||
return Promise.fromCallback(cb => { this.env.renderString(str, options, cb); }) | ||
.catch(err => Promise.reject(formatNunjucksError(err, str))) | ||
.then(result => result.replace(rPlaceholder, (_, index) => cache[index])); | ||
.catch(err => Promise.reject(formatNunjucksError(err, str))); | ||
} | ||
} | ||
|
||
|
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why add
\n
?Look at the following test cases, which one is expected?
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 extra
\n
is to separete a Nunjucks tag from immediate-after content.So I expect two
\n
at the end.Please refer the above comment #4171 (comment)