-
Notifications
You must be signed in to change notification settings - Fork 123
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
Allow special tags to be self-closing #1101
Allow special tags to be self-closing #1101
Conversation
441d658
to
c97b9e2
Compare
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.
Only a minor comment that would help document the change better. Looks generally okay to me with tests passing as well. Blast radius (if any) would be small since this only affects a new feature (special tags). I assumed that Tokenizer.prototype._stateInSelfClosingTag
is a patched function.
this._sectionStart = this._index + 1; | ||
if (this._special > 2) { | ||
/* | ||
We intentionally fail if the special tag in question is |
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.
Minor: Would really help to document/comment what "fail" imply when you set this._special = SPECIAL_NONE
.
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.
Updated
Will update back if there are changes besides rebasing on the latest!
c97b9e2
to
1d0925e
Compare
1d0925e
to
4d44772
Compare
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.
Since there's no such thing as self closing tags in the HTML specs, should we just allow script and style tags to be self closing too?
In the generated HTML they would all be expanded out to the valid <script></script>
and <special></special>
forms anyway.
I'm open to either; What do you think? @crphang |
Looks fine to me, not 100% sure if there will be no issues, but seems like it will make the code simpler here |
4d44772
to
2ff592b
Compare
Updated to allow |
@marvinchin could you help with the review of this? 🙇 |
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.
Mostly LGTM :) Just some comments might help other developers understand what's happening better.
Also, please explicitly request a review from me when your code is ready so I know when to look at it (even for re-reviews!)
@@ -261,6 +261,22 @@ Tokenizer.prototype._stateBeforeSpecial = function(c) { | |||
this._special = result + 1; | |||
}; | |||
|
|||
/** | |||
* Removes the special state if the special tag was self-closed. |
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.
Can we explicitly state that this is an altered version of the _stateInSelfClosingTag
defined in htmlparser
? I think it might help other developers new to this part of the codebase understand what's going on better.
this._cbs.onselfclosingtag(); | ||
this._state = TEXT; | ||
this._sectionStart = this._index + 1; | ||
// Allow all special tags (including script & style tags) to be self-closed |
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.
Let's explain why we allow this despite the spec not allowing it. I think just stating the fact that the original htmlparser allows it is sufficient.
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.
To clarify, did you mean the original htmlparser disallows it
( that is the case, we're breaking away from the parser's default behaviour here )?
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.
Oops, I actually thought that the original htmlparser allowed it, since the changes we made didn't seem to affect any of the logic specific to script/style tags. After taking a closer look at the rest of the changes in our patches, it seems like you are right 🙂
Will do 👍 Thanks for looking through this! |
2ff592b
to
9e1fea6
Compare
9e1fea6
to
7c1aef1
Compare
broken currently |
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.
LGTM :)
acad179
to
9359c19
Compare
Fixed, updated #1049's cheerio test site call with |
Unlike the html script and style special tags, plugin authors may want injected special tags to be able to be self-closing as well. This can help unify the syntax used in the plugin, which makes for better author usability of the plugin. Let’s allow injected special tags to be self-closing. Let’s also do so for the script and style tags, which would be expanded to their normal form after rendering.
9359c19
to
bb6284a
Compare
* 'master' of https://github.com/MarkBind/markbind: Update test files (MarkBind#1138) Remove OK button from modals (MarkBind#1134) Add start from line number functionality to code blocks (MarkBind#1115) Allow special tags to be self-closing (MarkBind#1101) Simplify baseUrl resolving process (MarkBind#1087) Remove redundant file writing (MarkBind#1090) Bump acorn from 5.7.3 to 5.7.4 (MarkBind#1121) Bump acorn from 7.1.0 to 7.1.1 in /src/lib/markbind (MarkBind#1120) Unify markdown-it parser variants (MarkBind#1056) Remove dynamic include feature (MarkBind#1037) Fix flex shrink not applying in content wrapper (MarkBind#1135) Escape Nunjucks for special tags (MarkBind#1049) Update documentation on icon slot for boxes (MarkBind#1123)
…x-pageNav * 'master' of https://github.com/MarkBind/markbind: Update test files (MarkBind#1138) Remove OK button from modals (MarkBind#1134) Add start from line number functionality to code blocks (MarkBind#1115) Allow special tags to be self-closing (MarkBind#1101) Simplify baseUrl resolving process (MarkBind#1087) Remove redundant file writing (MarkBind#1090) Bump acorn from 5.7.3 to 5.7.4 (MarkBind#1121) Bump acorn from 7.1.0 to 7.1.1 in /src/lib/markbind (MarkBind#1120) Unify markdown-it parser variants (MarkBind#1056) Remove dynamic include feature (MarkBind#1037) Fix flex shrink not applying in content wrapper (MarkBind#1135) Escape Nunjucks for special tags (MarkBind#1049) Update documentation on icon slot for boxes (MarkBind#1123) Convert code in boxes to code block (MarkBind#1086)
Unlike the html script and style special tags, plugin authors may want injected special tags to be able to be self-closing as well. This can help unify the syntax used in the plugin, which makes for better author usability of the plugin. Let’s allow injected special tags to be self-closing. Let’s also do so for the script and style tags, which would be expanded to their normal form after rendering.
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Documentation update
• [x] Enhancement to an existing feature
Resolves #1099
What is the rationale for this request?
Allow injected special tags to be self-closing as well, while preserving the contrary for
script/style
tags ( according to html5 spec ).What changes did you make? (Give an overview)
Is there anything you'd like reviewers to focus on?
na
Testing instructions:
npm run test
Proposed commit message: (wrap lines at 72 characters)
Allow special tags to be self-closing
Unlike the html script and style special tags, plugin authors may want
injected special tags to be able to be self-closing as well.
This can help unify the syntax used in the plugin, which makes for
better author usability of the plugin.
Let’s allow injected special tags to be self-closing.
Let’s also do so for the script and style tags, which would be
expanded to their normal form after rendering.