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

Fix formatting related to the <menu> element #2114

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_toke
};

//To be used for <p> tag special case:
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];

Beautifier.prototype._do_optional_end_element = function(parser_token) {
Expand All @@ -788,7 +788,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {

} else if (parser_token.tag_name === 'li') {
// An li element’s end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.
result = result || this._tag_stack.try_pop('li', ['ol', 'ul']);
result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);

} else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
// A dd element’s end tag may be omitted if the dd element is immediately followed by another dd element or a dt element, or if there is no more content in the parent element.
Expand Down
32 changes: 32 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,14 @@ exports.test_data = {
' <li>test content',
'</ol>'
]
}, {
unchanged: [
'<menu>',
' <li>test content',
' <li>test content',
' <li>test content',
'</menu>'
]
}, {
unchanged: [
'<ol>',
Expand All @@ -1773,6 +1781,30 @@ exports.test_data = {
' test content',
'</ol>'
]
}, {
unchanged: [
'<menu>',
' <li>',
' test content',
' <li>',
' <ol>',
' <li> level 1 check',
' <li>',
' <menu>',
' <li> level 2 check',
' <li>',
' <ul>',
' <li> level 3 check',
' </ul>',
' <li>',
' test content',
' </menu>',
' </ol>',
' <li> test content',
' <li>',
' test content',
'</menu>'
]
}, {
unchanged: [
'<dl>',
Expand Down