-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(format/html): normalize casing for directive (#5266)
- Loading branch information
Showing
14 changed files
with
109 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::borrow::Cow; | ||
|
||
use crate::prelude::*; | ||
use biome_formatter::write; | ||
use biome_formatter::{Format, FormatResult}; | ||
use biome_html_syntax::HtmlLanguage; | ||
use biome_rowan::{Language, SyntaxToken}; | ||
use biome_string_case::StrLikeExtension; | ||
|
||
use crate::{HtmlFormatter, context::HtmlFormatContext}; | ||
|
||
// TODO: deduplicate with CSS formatter's version of this, move to `biome_formatter`. | ||
pub(crate) struct FormatTokenAsLowercase<L: Language> { | ||
token: SyntaxToken<L>, | ||
} | ||
|
||
impl<L: Language> From<SyntaxToken<L>> for FormatTokenAsLowercase<L> { | ||
fn from(value: SyntaxToken<L>) -> Self { | ||
Self { token: value } | ||
} | ||
} | ||
|
||
impl Format<HtmlFormatContext> for FormatTokenAsLowercase<HtmlLanguage> { | ||
fn fmt(&self, f: &mut HtmlFormatter) -> FormatResult<()> { | ||
let original = self.token.text_trimmed(); | ||
match original.to_ascii_lowercase_cow() { | ||
Cow::Borrowed(_) => write!(f, [self.token.format()]), | ||
Cow::Owned(lowercase) => write!( | ||
f, | ||
[format_replaced( | ||
&self.token, | ||
&dynamic_text(&lowercase, self.token.text_trimmed_range().start()), | ||
)] | ||
), | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod children; | ||
pub mod formatters; | ||
pub mod metadata; |
1 change: 1 addition & 0 deletions
1
crates/biome_html_formatter/tests/specs/html/directive/lowercase.html
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<!doctype html> |
32 changes: 32 additions & 0 deletions
32
crates/biome_html_formatter/tests/specs/html/directive/lowercase.html.snap
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
info: directive/lowercase.html | ||
--- | ||
# Input | ||
|
||
```html | ||
<!doctype html> | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Indent width: 2 | ||
Line ending: LF | ||
Line width: 80 | ||
Attribute Position: Auto | ||
Bracket same line: false | ||
Whitespace sensitivity: css | ||
Indent script and style: false | ||
----- | ||
|
||
```html | ||
<!doctype html> | ||
``` |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...matter/tests/specs/html/example.html.snap → .../specs/html/directive/uppercase.html.snap
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
1 change: 1 addition & 0 deletions
1
crates/biome_html_formatter/tests/specs/html/directive/uppercase2.html
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<!DOCTYPE HTML> |
32 changes: 32 additions & 0 deletions
32
crates/biome_html_formatter/tests/specs/html/directive/uppercase2.html.snap
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
info: directive/uppercase2.html | ||
--- | ||
# Input | ||
|
||
```html | ||
<!DOCTYPE HTML> | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Indent width: 2 | ||
Line ending: LF | ||
Line width: 80 | ||
Attribute Position: Auto | ||
Bracket same line: false | ||
Whitespace sensitivity: css | ||
Indent script and style: false | ||
----- | ||
|
||
```html | ||
<!DOCTYPE html> | ||
``` |
54 changes: 0 additions & 54 deletions
54
...html_formatter/tests/specs/prettier/html/doctype_declarations/html4.01_frameset.html.snap
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
...e_html_formatter/tests/specs/prettier/html/doctype_declarations/html4.01_strict.html.snap
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
..._formatter/tests/specs/prettier/html/doctype_declarations/html4.01_transitional.html.snap
This file was deleted.
Oops, something went wrong.