Skip to content

Commit bcc4213

Browse files
authored
Merge pull request #2115 from cexbrayat/feat/2113-inline-custom-elements-behavior
Add option to disable custom elements inlining
2 parents 9859430 + 495c8c3 commit bcc4213

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ HTML Beautifier Options:
371371
-M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]
372372
-i, --wrap-attributes-indent-size Indent wrapped attributes to after N characters [indent-size] (ignored if wrap-attributes is "aligned")
373373
-d, --inline List of tags to be considered inline tags
374+
--inline_custom_elements Inline custom elements [true]
374375
-U, --unformatted List of tags (defaults to inline) that should not be reformatted
375376
-T, --content_unformatted List of tags (defaults to pre) whose content should not be reformatted
376377
-E, --extra_liners List of tags (defaults to [head,body,/html] that should have an extra newline before them.

Diff for: js/src/cli.js

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ var path = require('path'),
116116
// HTML-only
117117
"max_char": Number, // obsolete since 1.3.5
118118
"inline": [String, Array],
119+
"inline_custom_elements": [Boolean],
119120
"unformatted": [String, Array],
120121
"content_unformatted": [String, Array],
121122
"indent_inner_html": [Boolean],
@@ -168,6 +169,7 @@ var path = require('path'),
168169
"i": ["--wrap_attributes_indent_size"],
169170
"W": ["--max_char"], // obsolete since 1.3.5
170171
"d": ["--inline"],
172+
// no shorthand for "inline_custom_elements"
171173
"U": ["--unformatted"],
172174
"T": ["--content_unformatted"],
173175
"I": ["--indent_inner_html"],

Diff for: js/src/html/beautifier.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to g
656656

657657
parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
658658
parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
659-
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_name.includes("-") || parser_token.tag_start_char === '{';
659+
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
660660

661661
return parser_token;
662662
};

Diff for: js/src/html/options.js

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function Options(options) {
6161
// obsolete inline tags
6262
'acronym', 'big', 'strike', 'tt'
6363
]);
64+
this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
6465
this.void_elements = this._get_array('void_elements', [
6566
// HTLM void elements - aka self-closing tags - aka singletons
6667
// https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements

Diff for: test/data/html/tests.js

+26
Original file line numberDiff line numberDiff line change
@@ -3813,6 +3813,32 @@ exports.test_data = {
38133813
'</span>'
38143814
]
38153815
}]
3816+
}, {
3817+
name: "Disables custom elements inlining with inline_custom_elements=false",
3818+
description: "https://github.com/beautify-web/js-beautify/issues/2113",
3819+
options: [
3820+
{ name: "inline_custom_elements", value: "false" }
3821+
],
3822+
tests: [{
3823+
input: [
3824+
'<span>',
3825+
' <span>',
3826+
' <span>The time for this result is 1:02</span',
3827+
' ><time-dot>.</time-dot',
3828+
' ><time-decimals>27</time-decimals>',
3829+
' </span>',
3830+
'</span>'
3831+
],
3832+
output: [
3833+
'<span>',
3834+
' <span>',
3835+
' <span>The time for this result is 1:02</span>',
3836+
' <time-dot>.</time-dot>',
3837+
' <time-decimals>27</time-decimals>',
3838+
' </span>',
3839+
'</span>'
3840+
]
3841+
}]
38163842
}, {
38173843
name: "New Test Suite"
38183844
}]

0 commit comments

Comments
 (0)