From 2e73ebb133c0fbc2514459c23809964588bf901d Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 10 Apr 2026 19:20:08 +0100 Subject: [PATCH] feat(md/fmt): better formatting for some cases --- .../src/markdown/auxiliary/document.rs | 14 +- .../src/markdown/auxiliary/inline_image.rs | 2 +- .../src/markdown/auxiliary/inline_italic.rs | 18 +- .../src/markdown/auxiliary/newline.rs | 37 +++- .../src/markdown/auxiliary/quote_prefix.rs | 8 + .../src/markdown/auxiliary/reference_image.rs | 28 ++- .../auxiliary/reference_link_label.rs | 19 +- .../src/markdown/lists/block_list.rs | 59 +++++- .../src/markdown/lists/inline_item_list.rs | 38 +++- crates/biome_markdown_formatter/src/shared.rs | 7 + .../tests/quick_test.rs | 22 ++- .../tests/specs/markdown/blockquote.md.snap | 10 +- .../tests/specs/markdown/hard_line.md.snap | 3 +- .../tests/specs/markdown/inline_image.md | 2 + .../tests/specs/markdown/inline_image.md.snap | 4 + .../tests/specs/markdown/inline_italic.md | 18 ++ .../specs/markdown/inline_italic.md.snap | 36 ++++ .../tests/specs/markdown/inline_links.md | 2 + .../tests/specs/markdown/inline_links.md.snap | 4 + .../tests/specs/markdown/newline.md | 6 + .../tests/specs/markdown/newline.md.snap | 26 +++ .../prettier/markdown/blockquote/code.md.snap | 22 +-- .../markdown/blockquote/nested.md.snap | 28 --- .../markdown/blockquote/notext-end.md.snap | 25 ++- .../markdown/code/additional-space.md.snap | 4 +- .../markdown/code/mdn-auth-api.md.snap | 103 ----------- .../markdown/code/mdn-background-1.md.snap | 65 ------- .../markdown/code/mdn-background-2.md.snap | 50 ------ .../markdown/code/mdn-background-3.md.snap | 65 ------- .../markdown/code/mdn-background-4.md.snap | 63 ------- .../markdown/code/mdn-background-5.md.snap | 55 ------ .../markdown/code/mdn-background-6.md.snap | 78 -------- .../markdown/code/mdn-background-7.md.snap | 92 ---------- .../markdown/code/mdn-background-8.md.snap | 168 ------------------ .../markdown/code/mdn-background-9.md.snap | 56 ------ .../markdown/code/mdn-filter-1.md.snap | 59 ------ .../markdown/code/mdn-filter-2.md.snap | 50 ------ .../markdown/code/mdn-font-face-1.md.snap | 67 ------- .../markdown/code/mdn-font-face-2.md.snap | 62 ------- .../code/mdn-grid-auto-columns.md.snap | 56 ------ .../prettier/markdown/code/mdn-import.md.snap | 55 ------ .../markdown/code/mdn-mask-image.md.snap | 45 ----- .../markdown/code/mdn-padding-1.md.snap | 51 ------ .../markdown/code/mdn-padding-2.md.snap | 60 ------- .../markdown/code/mdn-transform.md.snap | 76 -------- .../markdown/code/mdn-unicode-range.md.snap | 77 -------- .../markdown/link/encodedLink.md.snap | 10 +- .../unbalanced-mismatched-braces.md.snap | 6 +- .../unbalanced-object-close-only.md.snap | 8 +- .../unbalanced-object-open-only.md.snap | 8 +- .../unbalanced-template-close-only.md.snap | 8 +- .../unbalanced-template-open-only.md.snap | 8 +- .../markdown/list/combined-lists.md.snap | 7 +- .../prettier/markdown/list/issue-7846.md.snap | 4 +- .../markdown/long-table/long-table.md.snap | 4 +- .../markdown/markdown/real-world-case.md.snap | 34 ++-- .../multiparser-json/invalid-json.md.snap | 7 +- .../spec/commonmark-0.30-example-337.md.snap | 30 ---- .../markdown/spec/example-187.md.snap | 10 +- .../markdown/spec/example-189.md.snap | 10 +- .../markdown/spec/example-211.md.snap | 9 +- .../markdown/spec/example-220.md.snap | 10 +- .../prettier/markdown/spec/example-48.md.snap | 5 +- .../markdown/spec/example-543.md.snap | 28 --- .../prettier/markdown/spec/example-65.md.snap | 30 ---- .../prettier/markdown/spec/example-85.md.snap | 36 ---- .../markdown/table/issue-15572.md.snap | 38 ---- .../wiki-link/extra-brackets-leading.md.snap | 35 ---- .../wiki-link/extra-brackets-trailing.md.snap | 35 ---- .../markdown/wiki-link/extra-brackets.md.snap | 35 ---- crates/biome_markdown_parser/src/lexer/mod.rs | 16 +- 71 files changed, 421 insertions(+), 1905 deletions(-) create mode 100644 crates/biome_markdown_formatter/tests/specs/markdown/newline.md create mode 100644 crates/biome_markdown_formatter/tests/specs/markdown/newline.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/nested.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-auth-api.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-1.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-2.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-3.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-4.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-5.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-6.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-7.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-8.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-9.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-1.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-2.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-1.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-2.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-grid-auto-columns.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-import.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-mask-image.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-1.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-2.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-transform.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-unicode-range.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/commonmark-0.30-example-337.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-543.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-65.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-85.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/table/issue-15572.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-leading.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-trailing.md.snap delete mode 100644 crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets.md.snap diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/document.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/document.rs index dd44b87f9c9b..c618c900fb87 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/document.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/document.rs @@ -1,3 +1,4 @@ +use crate::markdown::lists::block_list::FormatMdBlockListOptions; use crate::prelude::*; use biome_formatter::write; use biome_markdown_syntax::{MdDocument, MdDocumentFields}; @@ -16,6 +17,17 @@ impl FormatNodeRule for FormatMdDocument { write!(f, [bom.format()])?; } - write!(f, [value.format(), format_removed(&eof_token?)]) + write!( + f, + [ + value + .format() + .with_options(FormatMdBlockListOptions { trim: true }), + format_removed(&eof_token?) + ] + )?; + + // when trimming, we remove the last newline, so we add it back here + write!(f, [hard_line_break()]) } } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_image.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_image.rs index 15b22896b422..690814781cc2 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_image.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_image.rs @@ -33,7 +33,7 @@ impl FormatNodeRule for FormatMdInlineImage { destination .format() .with_options(FormatMdFormatInlineItemListOptions { - print_mode: TextPrintMode::Trim(TrimMode::All) + print_mode: TextPrintMode::Trim(TrimMode::AutoLinkLike) }) ] )?; diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_italic.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_italic.rs index 9a45d8329446..adab1beb4881 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_italic.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_italic.rs @@ -1,6 +1,8 @@ use crate::prelude::*; use biome_formatter::write; -use biome_markdown_syntax::{MarkdownSyntaxKind, MdInlineItalic, MdInlineItalicFields}; +use biome_markdown_syntax::{ + MarkdownSyntaxKind, MdInlineItalic, MdInlineItalicFields, MdReferenceImage, +}; use biome_rowan::AstNode; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdInlineItalic; @@ -29,6 +31,18 @@ impl FormatNodeRule for FormatMdInlineItalic { return format_verbatim_node(node.syntax()).fmt(f); } + // Inside reference images the alt text doubles as the reference label. + // Normalizing `*` → `_` would change the label and break reference resolution. + // E.g. `![foo *bar*]` with `[foo *bar*]: url` must keep `*`. + if node + .syntax() + .ancestors() + .skip(1) + .any(|a| MdReferenceImage::can_cast(a.kind())) + { + return write!(f, [l_fence.format(), content.format(), r_fence.format()]); + } + let prev_is_alphanum = l_fence .prev_token() .and_then(|t| t.text_trimmed().chars().last()) @@ -39,7 +53,7 @@ impl FormatNodeRule for FormatMdInlineItalic { .is_some_and(|c| c.is_alphanumeric()); // See https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis - // Prefer `_` but use `*` when adjacent to alphanumeric + // Prefer `_` but use `*` when adjacent to alphanumeric, // For example, `a_b_c` won't parse `b` as italic, but `a*b*c` will). let target_kind = if prev_is_alphanum || next_is_alphanum { MarkdownSyntaxKind::STAR diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/newline.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/newline.rs index 8fb6b5b158fb..aebd7f8fb942 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/newline.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/newline.rs @@ -1,9 +1,40 @@ use crate::prelude::*; -use biome_markdown_syntax::MdNewline; +use biome_formatter::{FormatRuleWithOptions, write}; +use biome_markdown_syntax::{MdHeader, MdNewline}; +use biome_rowan::AstNode; #[derive(Debug, Clone, Default)] -pub(crate) struct FormatMdNewline; +pub(crate) struct FormatMdNewline { + should_remove: bool, +} impl FormatNodeRule for FormatMdNewline { fn fmt_fields(&self, node: &MdNewline, f: &mut MarkdownFormatter) -> FormatResult<()> { - node.value_token().format().fmt(f) + if self.should_remove { + return write!(f, [format_removed(&node.value_token()?)]); + } + + let after_header = node + .syntax() + .prev_sibling() + .is_some_and(|s| MdHeader::can_cast(s.kind())); + + if after_header { + let token = node.value_token()?; + write!(f, [format_removed(&token), hard_line_break()]) + } else { + node.value_token().format().fmt(f) + } + } +} + +pub(crate) struct FormatMdNewlineOptions { + pub(crate) should_remove: bool, +} + +impl FormatRuleWithOptions for FormatMdNewline { + type Options = FormatMdNewlineOptions; + + fn with_options(mut self, options: Self::Options) -> Self { + self.should_remove = options.should_remove; + self } } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/quote_prefix.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/quote_prefix.rs index ed8e848eb2c5..6d69587138a4 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/quote_prefix.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/quote_prefix.rs @@ -16,6 +16,14 @@ impl FormatNodeRule for FormatMdQuotePrefix { if let Some(post_marker_space_token) = post_marker_space_token { write!(f, [post_marker_space_token.format()])?; + } else { + let marker = marker_token?; + let next_has_text = marker + .next_token() + .is_some_and(|t| t.text().starts_with(|c: char| !c.is_whitespace())); + if next_has_text { + write!(f, [space()])?; + } } Ok(()) diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_image.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_image.rs index 9c442f23cfae..1b362ee8df14 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_image.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_image.rs @@ -1,10 +1,32 @@ use crate::prelude::*; -use biome_markdown_syntax::MdReferenceImage; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_markdown_syntax::{MdReferenceImage, MdReferenceImageFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdReferenceImage; impl FormatNodeRule for FormatMdReferenceImage { fn fmt_fields(&self, node: &MdReferenceImage, f: &mut MarkdownFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let MdReferenceImageFields { + excl_token, + l_brack_token, + alt, + r_brack_token, + label, + } = node.as_fields(); + + write!( + f, + [ + excl_token.format(), + l_brack_token.format(), + alt.format(), + r_brack_token.format() + ] + )?; + + if let Some(label) = label { + write!(f, [label.format()])?; + } + + Ok(()) } } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_link_label.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_link_label.rs index d66293c4ba5e..f0878e199c24 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_link_label.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/reference_link_label.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -use biome_markdown_syntax::MdReferenceLinkLabel; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_markdown_syntax::{MdReferenceLinkLabel, MdReferenceLinkLabelFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdReferenceLinkLabel; impl FormatNodeRule for FormatMdReferenceLinkLabel { @@ -9,6 +9,19 @@ impl FormatNodeRule for FormatMdReferenceLinkLabel { node: &MdReferenceLinkLabel, f: &mut MarkdownFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let MdReferenceLinkLabelFields { + l_brack_token, + label, + r_brack_token, + } = node.as_fields(); + + write!( + f, + [ + l_brack_token.format(), + label.format(), + r_brack_token.format() + ] + ) } } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/block_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/block_list.rs index cf1efe186e84..41eea02e6c6a 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/block_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/block_list.rs @@ -1,10 +1,63 @@ +use crate::markdown::auxiliary::newline::FormatMdNewlineOptions; use crate::prelude::*; -use biome_markdown_syntax::MdBlockList; +use biome_formatter::FormatRuleWithOptions; +use biome_markdown_syntax::{AnyMdBlock, AnyMdLeafBlock, MdBlockList}; + #[derive(Debug, Clone, Default)] -pub(crate) struct FormatMdBlockList; +pub(crate) struct FormatMdBlockList { + /// When true, it removes all leading newlines and trailing newlines + trim: bool, +} impl FormatRule for FormatMdBlockList { type Context = MarkdownFormatContext; fn fmt(&self, node: &MdBlockList, f: &mut MarkdownFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut joiner = f.join(); + + if !self.trim { + return f.join().entries(node.iter().formatted()).finish(); + } + + let mut iter = node.iter(); + + // Count trailing newlines using next_back + let mut trailing_count = 0; + while let Some(AnyMdBlock::AnyMdLeafBlock(AnyMdLeafBlock::MdNewline(_))) = iter.next_back() + { + trailing_count += 1; + } + + // we don't need the iter anymore + drop(iter); + + // Single forward pass in document order + let mut still_leading = true; + let content_count = node.len() - trailing_count; + for (index, node) in node.iter().enumerate() { + if let AnyMdBlock::AnyMdLeafBlock(AnyMdLeafBlock::MdNewline(newline)) = node { + let is_leading = still_leading; + let is_trailing = index >= content_count; + joiner.entry(&newline.format().with_options(FormatMdNewlineOptions { + should_remove: is_leading || is_trailing, + })); + } else { + still_leading = false; + joiner.entry(&node.format()); + } + } + + joiner.finish() + } +} + +pub(crate) struct FormatMdBlockListOptions { + pub(crate) trim: bool, +} + +impl FormatRuleWithOptions for FormatMdBlockList { + type Options = FormatMdBlockListOptions; + + fn with_options(mut self, options: Self::Options) -> Self { + self.trim = options.trim; + self } } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/inline_item_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/inline_item_list.rs index ca8e39e09786..730203a9851d 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/inline_item_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/inline_item_list.rs @@ -13,7 +13,9 @@ pub(crate) struct FormatMdInlineItemList { impl FormatRule for FormatMdInlineItemList { type Context = MarkdownFormatContext; fn fmt(&self, node: &MdInlineItemList, f: &mut MarkdownFormatter) -> FormatResult<()> { - if self.print_mode.is_normalize_words() { + if self.print_mode.is_auto_link_like() { + return self.fmt_auto_link_like(node, f); + } else if self.print_mode.is_normalize_words() { return self.fmt_normalize_words(node, f); } else if self.print_mode.is_all() { return self.fmt_trim_all(node, f); @@ -91,6 +93,40 @@ impl FormatRule for FormatMdInlineItemList { } impl FormatMdInlineItemList { + /// If the first and last [MdTextual] are `<` and `>` respectively, + /// they are removed. Otherwise falls back to [TrimMode::All]. + fn fmt_auto_link_like( + &self, + node: &MdInlineItemList, + f: &mut MarkdownFormatter, + ) -> FormatResult<()> { + let items: Vec<_> = node.iter().collect(); + + let starts_with_lt = matches!(items.first(), Some(AnyMdInline::MdTextual(t)) if t.value_token().is_ok_and(|tok| tok.text() == "<")); + let ends_with_gt = matches!(items.last(), Some(AnyMdInline::MdTextual(t)) if t.value_token().is_ok_and(|tok| tok.text() == ">")); + + let is_auto_link = starts_with_lt && ends_with_gt && items.len() > 2; + + if !is_auto_link { + return self.fmt_trim_all(node, f); + } + + let mut joiner = f.join(); + for (index, item) in items.iter().enumerate() { + if (index == 0 || index == items.len() - 1) + && let AnyMdInline::MdTextual(text) = item + { + joiner.entry(&text.format().with_options(FormatMdTextualOptions { + should_remove: true, + ..Default::default() + })); + continue; + } + joiner.entry(&item.format()); + } + joiner.finish() + } + /// Strips leading and trailing whitespace/hard-lines around the content. /// Items between the first and last non-empty nodes are kept as-is; /// items outside those boundaries are removed. diff --git a/crates/biome_markdown_formatter/src/shared.rs b/crates/biome_markdown_formatter/src/shared.rs index cdd508d9fc25..1d42eceb50b5 100644 --- a/crates/biome_markdown_formatter/src/shared.rs +++ b/crates/biome_markdown_formatter/src/shared.rs @@ -35,6 +35,9 @@ pub(crate) enum TrimMode { Start, /// Trim start and end of the list All, + /// If the first and last [MdTextual] are `<` and `>` respectively, they are trimmed. + /// If no link has been detected, if falls back to [Self::All] + AutoLinkLike, /// This mode works similarly to [TrimMode::All], however, text that contains /// words and have more than trailing/leading spaces are normalized to one NormalizeWords, @@ -56,6 +59,10 @@ impl TextPrintMode { matches!(self, Self::Trim(TrimMode::NormalizeWords)) } + pub(crate) const fn is_auto_link_like(&self) -> bool { + matches!(self, Self::Trim(TrimMode::AutoLinkLike)) + } + pub(crate) const fn is_pristine(&self) -> bool { matches!(self, Self::Pristine) } diff --git a/crates/biome_markdown_formatter/tests/quick_test.rs b/crates/biome_markdown_formatter/tests/quick_test.rs index aff502a887a5..50a5004fbb97 100644 --- a/crates/biome_markdown_formatter/tests/quick_test.rs +++ b/crates/biome_markdown_formatter/tests/quick_test.rs @@ -4,7 +4,7 @@ use biome_markdown_parser::parse_markdown; #[ignore] #[test] fn quick_test() { - let source = ""; + let source = "foo \nbar without empty line after "; let parse = parse_markdown(source); // Print CST @@ -13,10 +13,24 @@ fn quick_test() { eprintln!("{:#?}", parse.tree()); let options = MdFormatOptions::default(); - let result = - biome_formatter::format_node(&parse.syntax(), MdFormatLanguage::new(options), false); + let result = biome_formatter::format_node( + &parse.syntax(), + MdFormatLanguage::new(options.clone()), + false, + ); // Print formatted output let formatted = result.unwrap(); - eprintln!("Formatted:\n{}", formatted.print().unwrap().as_code()); + let output = formatted.print().unwrap(); + eprintln!("Formatted:\n{}", output.as_code()); + + // Now re-parse the formatted output and show its CST + let reparse = parse_markdown(output.as_code()); + eprintln!("\n--- Re-parsed CST ---"); + eprintln!("{:#?}", reparse.tree()); + + let result2 = + biome_formatter::format_node(&reparse.syntax(), MdFormatLanguage::new(options), false); + let output2 = result2.unwrap(); + eprintln!("Re-formatted:\n{}", output2.print().unwrap().as_code()); } diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/blockquote.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/blockquote.md.snap index d8ce92ecb8d4..017c591ae4db 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/blockquote.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/markdown/blockquote.md.snap @@ -65,7 +65,7 @@ info: markdown/blockquote.md > quote with multiple words on a single line ->no space after marker +> no space after marker > extra space after marker @@ -77,17 +77,17 @@ info: markdown/blockquote.md > > second paragraph ->> nested quote +> > nested quote > > nested quote with space ->>> triple nested +> > > triple nested > > > triple nested with spaces > first level ->> second level ->>> third level +> > second level +> > > third level > quote with **bold** and _italic_ diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md.snap index 1e9dfc46d71e..aa16ab1a82ed 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md.snap @@ -38,5 +38,6 @@ here foo bar with empty line after foo -bar without empty line after +bar without empty line after + ``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md b/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md index d26d641412fe..edf727a05ff3 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md @@ -25,3 +25,5 @@ ![alt with **bold** and *italic*](image.png) ![alt with `code`](image.png) + +![alt with `code`]() diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md.snap index 3a67f60dbb74..1929565f96cd 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_image.md.snap @@ -34,6 +34,8 @@ info: markdown/inline_image.md ![alt with `code`](image.png) +![alt with `code`]() + ``` @@ -68,6 +70,8 @@ info: markdown/inline_image.md ![alt with `code`](image.png) +![alt with `code`](url) + ``` # Lines exceeding max width of 80 characters diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md b/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md index 756047b70495..5d711ba27cbe 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md @@ -1,3 +1,21 @@ a*b*c a_b_c + +*foo* + +_foo_ + +(*foo*) + +![foo *bar*] + +[foo *bar*]: train.jpg "train & tracks" + +![*foo* bar][] + +[*foo* bar]: /url "title" + +![foo *bar*][foobar] + +[FOOBAR]: train.jpg "train & tracks" diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md.snap index 4d7b49692037..be76967bf3d1 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_italic.md.snap @@ -10,6 +10,24 @@ a*b*c a_b_c +*foo* + +_foo_ + +(*foo*) + +![foo *bar*] + +[foo *bar*]: train.jpg "train & tracks" + +![*foo* bar][] + +[*foo* bar]: /url "title" + +![foo *bar*][foobar] + +[FOOBAR]: train.jpg "train & tracks" + ``` @@ -20,4 +38,22 @@ a*b*c a_b_c +_foo_ + +_foo_ + +(_foo_) + +![foo *bar*] + +[foo *bar*]: train.jpg "train & tracks" + +![*foo* bar][] + +[*foo* bar]: /url "title" + +![foo *bar*][foobar] + +[FOOBAR]: train.jpg "train & tracks" + ``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md index 8424594d2c9e..4904d1cb076b 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md @@ -9,3 +9,5 @@ text with [inline](link) in the middle [link with **bold**](url) + +[foo]() diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md.snap index 7312ad59c2ec..1849d444b729 100644 --- a/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md.snap @@ -18,6 +18,8 @@ text with [inline](link) in the middle [link with **bold**](url) +[foo]() + ``` @@ -36,4 +38,6 @@ text with [inline](link) in the middle [link with **bold**](url) +[foo]() + ``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/newline.md b/crates/biome_markdown_formatter/tests/specs/markdown/newline.md new file mode 100644 index 000000000000..457cb0c37384 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/newline.md @@ -0,0 +1,6 @@ + + + +### Header + +Newlines at the top should be removed diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/newline.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/newline.md.snap new file mode 100644 index 000000000000..d50dcdd524f4 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/newline.md.snap @@ -0,0 +1,26 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: markdown/newline.md +--- + +# Input + +```md + + + +### Header + +Newlines at the top should be removed + +``` + + +# Formatted + +```md +### Header + +Newlines at the top should be removed + +``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/code.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/code.md.snap index 134219eacb35..327536e6ac42 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/code.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/code.md.snap @@ -29,23 +29,17 @@ info: markdown/blockquote/code.md ```diff --- Prettier +++ Biome -@@ -1,7 +1,6 @@ +@@ -1,5 +1,4 @@ > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: -> --> ```json --> { -+>```json -+>{ + > ```json + > { > "extends": [ - > "unobtrusive", - > "unobtrusive/import", -@@ -11,5 +10,6 @@ - > "env": { +@@ -12,4 +11,5 @@ > "browser": true > } --> } + > } -> ``` -+>} +> +``` ``` @@ -54,8 +48,8 @@ info: markdown/blockquote/code.md ```md > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: ->```json ->{ +> ```json +> { > "extends": [ > "unobtrusive", > "unobtrusive/import", @@ -65,7 +59,7 @@ info: markdown/blockquote/code.md > "env": { > "browser": true > } ->} +> } > ``` ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/nested.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/nested.md.snap deleted file mode 100644 index ed8e46ecc6e7..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/nested.md.snap +++ /dev/null @@ -1,28 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/blockquote/nested.md ---- - -# Input - -```md ->>> 123 - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1 @@ --> > > 123 -+>>> 123 -``` - -# Output - -```md ->>> 123 -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/notext-end.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/notext-end.md.snap index 09ce8c45de43..40fe94ab1e1f 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/notext-end.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/notext-end.md.snap @@ -34,27 +34,24 @@ info: markdown/blockquote/notext-end.md ```diff --- Prettier +++ Biome -@@ -2,15 +2,13 @@ +@@ -2,16 +2,14 @@ > `DOOM` > _b_ -> --> > `A` --> > `B` -+>> `A` -+>> `B` + > > `A` + > > `B` > _a_ -> --> > # foo + > > # foo -> > --> > `a` > `b` -+>> # foo -+>> `a` > `b` -+ + > > `a` > `b` ++ > This is a quote with an italic _across multuple lines > which should just work_. So make sure there is no > if we set + > proseWrap to `never` ``` # Output @@ -64,12 +61,12 @@ info: markdown/blockquote/notext-end.md > `DOOM` > _b_ ->> `A` ->> `B` +> > `A` +> > `B` > _a_ ->> # foo ->> `a` > `b` +> > # foo +> > `a` > `b` > This is a quote with an italic _across multuple lines diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/additional-space.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/additional-space.md.snap index 2e9ee8e87a61..58811d29151b 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/additional-space.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/additional-space.md.snap @@ -71,7 +71,6 @@ info: markdown/code/additional-space.md + ```sh + yarn --version + ``` -\ No newline at end of file ``` # Output @@ -98,7 +97,8 @@ info: markdown/code/additional-space.md To check your version of Yarn and ensure it's installed you can type: ```sh yarn --version - `````` + ``` +``` # Lines exceeding max width of 80 characters ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-auth-api.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-auth-api.md.snap deleted file mode 100644 index e733e848fca5..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-auth-api.md.snap +++ /dev/null @@ -1,103 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-auth-api.md ---- - -# Input - -```md - - - -```javascript - - -// sample arguments for registration -const createCredentialDefaultArgs = { - publicKey: { - // Relying Party (a.k.a. - Service): - rp: { - name: "Acme", }, - // User: - user: { - id: new Uint8Array(16), - name: "carina.p.anand@example.com", displayName: "Carina P. Anand", - }, - pubKeyCredParams: [ - { - type: "public-key", - alg: -7, - }, - ], - attestation: "direct", - timeout: 60000, - challenge: new Uint8Array( -[ - // must be a cryptographically random number sent from a server - 0x8c, 0x0a, 0x26, 0xff, 0x22, 0x91, 0xc1, 0xe9, 0xb9, 0x4e, 0x2e, 0x17, 0x1a, 0x98, 0x6a, 0x73, 0x71, 0x9d, 0x43, 0x48, 0xd5, 0xa7, 0x6a, 0x15, 0x7e, 0x38, - 0x94, 0x52, 0x77, 0x97, 0x0f, 0xef, - ]).buffer, - }, -}; -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,6 @@ -+ -+ -+ - ```javascript - - -``` - -# Output - -```md - - - -```javascript - - -// sample arguments for registration -const createCredentialDefaultArgs = { - publicKey: { - // Relying Party (a.k.a. - Service): - rp: { - name: "Acme", }, - // User: - user: { - id: new Uint8Array(16), - name: "carina.p.anand@example.com", displayName: "Carina P. Anand", - }, - pubKeyCredParams: [ - { - type: "public-key", - alg: -7, - }, - ], - attestation: "direct", - timeout: 60000, - challenge: new Uint8Array( -[ - // must be a cryptographically random number sent from a server - 0x8c, 0x0a, 0x26, 0xff, 0x22, 0x91, 0xc1, 0xe9, 0xb9, 0x4e, 0x2e, 0x17, 0x1a, 0x98, 0x6a, 0x73, 0x71, 0x9d, 0x43, 0x48, 0xd5, 0xa7, 0x6a, 0x15, 0x7e, 0x38, - 0x94, 0x52, 0x77, 0x97, 0x0f, 0xef, - ]).buffer, - }, -}; -``` -``` - -# Lines exceeding max width of 80 characters -``` - 29: 0x8c, 0x0a, 0x26, 0xff, 0x22, 0x91, 0xc1, 0xe9, 0xb9, 0x4e, 0x2e, 0x17, 0x1a, 0x98, 0x6a, 0x73, 0x71, 0x9d, 0x43, 0x48, 0xd5, 0xa7, 0x6a, 0x15, 0x7e, 0x38, -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-1.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-1.md.snap deleted file mode 100644 index b02fa0d4a22e..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-1.md.snap +++ /dev/null @@ -1,65 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-1.md ---- - -# Input - -```md - - - -```css - -.box { - background: - linear-gradient( - 105deg, - rgb(255 255 255 / 20%) 39%, - rgb(51 56 57 / 100%) 96% - ) center center / 400px 200px no-repeat, url(big-star.png) center no-repeat, - rebeccapurple; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,6 @@ -+ -+ -+ - ```css - - .box { -``` - -# Output - -```md - - - -```css - -.box { - background: - linear-gradient( - 105deg, - rgb(255 255 255 / 20%) 39%, - rgb(51 56 57 / 100%) 96% - ) center center / 400px 200px no-repeat, url(big-star.png) center no-repeat, - rebeccapurple; -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 12: ) center center / 400px 200px no-repeat, url(big-star.png) center no-repeat, -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-2.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-2.md.snap deleted file mode 100644 index fd0718f3d401..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-2.md.snap +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-2.md ---- - -# Input - -```md - -```css - - - -background-image: linear-gradient( - to bottom, - rgb(255 255 0 / 50%), - rgb(0 0 255 / 50%) - ), url("catfront.png"); -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - -``` - -# Output - -```md - -```css - - - -background-image: linear-gradient( - to bottom, - rgb(255 255 0 / 50%), - rgb(0 0 255 / 50%) - ), url("catfront.png"); -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-3.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-3.md.snap deleted file mode 100644 index a1334859bb5d..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-3.md.snap +++ /dev/null @@ -1,65 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-3.md ---- - -# Input - -```md - -```css - -.box { - margin: 10px 0; - color: #fff; - background: linear-gradient(90deg, - rgb(131 58 180 / 100%) 0%, - rgb(253 29 29 / 60%) 60%, rgb(252 176 69 / 100%) 100%), radial-gradient(circle, rgb(255 255 255 / 100%) 0%, rgb(0 0 0 / 100%) 28%); - border: 20px dashed black; - padding: 20px; -width: 400px; - background-origin: padding-box, content-box; - background-repeat: no-repeat; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - .box { -``` - -# Output - -```md - -```css - -.box { - margin: 10px 0; - color: #fff; - background: linear-gradient(90deg, - rgb(131 58 180 / 100%) 0%, - rgb(253 29 29 / 60%) 60%, rgb(252 176 69 / 100%) 100%), radial-gradient(circle, rgb(255 255 255 / 100%) 0%, rgb(0 0 0 / 100%) 28%); - border: 20px dashed black; - padding: 20px; -width: 400px; - background-origin: padding-box, content-box; - background-repeat: no-repeat; -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 9: rgb(253 29 29 / 60%) 60%, rgb(252 176 69 / 100%) 100%), radial-gradient(circle, rgb(255 255 255 / 100%) 0%, rgb(0 0 0 / 100%) 28%); -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-4.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-4.md.snap deleted file mode 100644 index 21285625cb3d..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-4.md.snap +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-4.md ---- - -# Input - -```md - -```css - - -.multi-bg-example { - width: 100%; height: 400px; - background-image: url(firefox.png), url(bubbles.png), linear-gradient(to right, rgb(30 - 75 115 / 100%), rgb(255 255 255 / 0%)); - background-repeat: no-repeat, no-repeat, no-repeat; -background-position: - bottom right, - left, - right; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - -``` - -# Output - -```md - -```css - - -.multi-bg-example { - width: 100%; height: 400px; - background-image: url(firefox.png), url(bubbles.png), linear-gradient(to right, rgb(30 - 75 115 / 100%), rgb(255 255 255 / 0%)); - background-repeat: no-repeat, no-repeat, no-repeat; -background-position: - bottom right, - left, - right; -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 7: background-image: url(firefox.png), url(bubbles.png), linear-gradient(to right, rgb(30 -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-5.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-5.md.snap deleted file mode 100644 index 58d7113a3863..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-5.md.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-5.md ---- - -# Input - -```md - - -```css - -.stacked-linear { - background: linear-gradient( - 217deg, - rgb(255 0 0 / 80%), - rgb(255 0 0 / 0%) 70.71% - ), linear-gradient(127deg, rgb(0 255 0 / 80%), rgb(0 255 0 / 0%) 70.71%), - linear-gradient(336deg, rgb(0 0 255 / 80%), rgb(0 0 255 / 0%) 70.71%); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - .stacked-linear { -``` - -# Output - -```md - - -```css - -.stacked-linear { - background: linear-gradient( - 217deg, - rgb(255 0 0 / 80%), - rgb(255 0 0 / 0%) 70.71% - ), linear-gradient(127deg, rgb(0 255 0 / 80%), rgb(0 255 0 / 0%) 70.71%), - linear-gradient(336deg, rgb(0 0 255 / 80%), rgb(0 0 255 / 0%) 70.71%); -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-6.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-6.md.snap deleted file mode 100644 index 4b7c82c73149..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-6.md.snap +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-6.md ---- - -# Input - -```md - -```css - - - -.stacked-radial { - background: - radial-gradient( - circle at 50% 0, - rgb(255 0 0 / 50%), - rgb(255 0 0 / 0%) 70.71% - ), - radial-gradient( - circle at 6.7% 75%, - rgb(0 0 255 / 50%), - rgb(0 0 255 / 0%) 70.71% - ), - radial-gradient( - circle at 93.3% 75%, - rgb(0 255 0 / 50%), - rgb(0 255 0 / 0%) 70.71% - ) beige; - border-radius: 50%; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - -``` - -# Output - -```md - -```css - - - -.stacked-radial { - background: - radial-gradient( - circle at 50% 0, - rgb(255 0 0 / 50%), - rgb(255 0 0 / 0%) 70.71% - ), - radial-gradient( - circle at 6.7% 75%, - rgb(0 0 255 / 50%), - rgb(0 0 255 / 0%) 70.71% - ), - radial-gradient( - circle at 93.3% 75%, - rgb(0 255 0 / 50%), - rgb(0 255 0 / 0%) 70.71% - ) beige; - border-radius: 50%; -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-7.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-7.md.snap deleted file mode 100644 index 1279c7ba9ca2..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-7.md.snap +++ /dev/null @@ -1,92 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-7.md ---- - -# Input - -```md - - -```css - -.multi-repeating-linear { - background: repeating-linear-gradient( - 190deg, - rgb(255 0 0 / 50%) 40px, - rgb(255 153 0 / 50%) 80px, -rgb(255 255 0 / 50%) 120px, - rgb(0 255 0 / 50%) 160px, - rgb(0 0 255 / 50%) 200px, - rgb(75 0 130 / 50%) 240px, - rgb(238 130 238 / 50%) 280px, - rgb(255 0 0 / 50%) 300px - ), repeating-linear-gradient( - -190deg, - rgb(255 0 0 / 50%) 30px, - rgb(255 153 0 / 50%) 60px, - rgb(255 255 0 / 50%) 90px, - rgb(0 255 0 / 50%) 120px, - rgb(0 0 255 / 50%) 150px, - rgb(75 0 130 / 50%) 180px, - rgb(238 130 238 / 50%) 210px, - rgb(255 0 0 / 50%) 230px - ), repeating-linear-gradient(23deg, red 50px, orange 100px, yellow 150px, green - 200px, blue 250px, indigo 300px, violet 350px, red 370px); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - .multi-repeating-linear { -``` - -# Output - -```md - - -```css - -.multi-repeating-linear { - background: repeating-linear-gradient( - 190deg, - rgb(255 0 0 / 50%) 40px, - rgb(255 153 0 / 50%) 80px, -rgb(255 255 0 / 50%) 120px, - rgb(0 255 0 / 50%) 160px, - rgb(0 0 255 / 50%) 200px, - rgb(75 0 130 / 50%) 240px, - rgb(238 130 238 / 50%) 280px, - rgb(255 0 0 / 50%) 300px - ), repeating-linear-gradient( - -190deg, - rgb(255 0 0 / 50%) 30px, - rgb(255 153 0 / 50%) 60px, - rgb(255 255 0 / 50%) 90px, - rgb(0 255 0 / 50%) 120px, - rgb(0 0 255 / 50%) 150px, - rgb(75 0 130 / 50%) 180px, - rgb(238 130 238 / 50%) 210px, - rgb(255 0 0 / 50%) 230px - ), repeating-linear-gradient(23deg, red 50px, orange 100px, yellow 150px, green - 200px, blue 250px, indigo 300px, violet 350px, red 370px); -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 26: ), repeating-linear-gradient(23deg, red 50px, orange 100px, yellow 150px, green -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-8.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-8.md.snap deleted file mode 100644 index 7e1165052f05..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-8.md.snap +++ /dev/null @@ -1,168 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-8.md ---- - -# Input - -```md - - -```css - -.plaid-gradient { - background: repeating-linear-gradient( - 90deg, - transparent, - transparent 50px, - rgb(255 127 0 / 25%) 50px, - rgb(255 127 0 / 25%) 56px, - transparent 56px, - transparent 63px, - rgb(255 127 0 / 25%) 63px, - rgb(255 127 0 / 25%) 69px, -transparent 69px, - transparent 116px, - rgb(255 206 0 / 25%) 116px, - rgb(255 206 0 / 25%) 166px - ), repeating-linear-gradient( - 0deg, - transparent, - transparent 50px, - rgb(255 127 0 / 25%) 50px, - rgb(255 127 0 / 25%) 56px, - transparent 56px, - transparent 63px, - rgb(255 127 0 / 25%) 63px, - rgb(255 127 0 / 25%) 69px, - transparent 69px, - transparent 116px, - rgb(255 206 0 / 25%) 116px, - rgb(255 206 0 / 25%) 166px - ), repeating-linear-gradient( - -45deg, - transparent, - transparent 5px, - rgb(143 77 63 / 25%) 5px, - rgb(143 77 63 / 25%) 10px - ), repeating-linear-gradient(45deg, transparent, transparent 5px, rgb( - 143 77 63 / 25% - ) 5px, rgb(143 77 63 / 25%) 10px); - - background: repeating-linear-gradient( - 90deg, - transparent 0 50px, - rgb(255 127 0 / 25%) 50px 56px, - transparent 56px 63px, - rgb(255 127 0 / 25%) 63px 69px, - transparent 69px 116px, - rgb(255 206 0 / 25%) 116px 166px - ), repeating-linear-gradient( - 0deg, - transparent 0 50px, - rgb(255 127 0 / 25%) 50px 56px, - transparent 56px 63px, - rgb(255 127 0 / 25%) 63px 69px, - transparent 69px 116px, - rgb(255 206 0 / 25%) 116px 166px - ), repeating-linear-gradient( - -45deg, - transparent 0 5px, - rgb(143 77 63 / 25%) 5px 10px - ), repeating-linear-gradient(45deg, transparent 0 5px, rgb(143 77 63 / 25%) 5px - 10px); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - .plaid-gradient { -``` - -# Output - -```md - - -```css - -.plaid-gradient { - background: repeating-linear-gradient( - 90deg, - transparent, - transparent 50px, - rgb(255 127 0 / 25%) 50px, - rgb(255 127 0 / 25%) 56px, - transparent 56px, - transparent 63px, - rgb(255 127 0 / 25%) 63px, - rgb(255 127 0 / 25%) 69px, -transparent 69px, - transparent 116px, - rgb(255 206 0 / 25%) 116px, - rgb(255 206 0 / 25%) 166px - ), repeating-linear-gradient( - 0deg, - transparent, - transparent 50px, - rgb(255 127 0 / 25%) 50px, - rgb(255 127 0 / 25%) 56px, - transparent 56px, - transparent 63px, - rgb(255 127 0 / 25%) 63px, - rgb(255 127 0 / 25%) 69px, - transparent 69px, - transparent 116px, - rgb(255 206 0 / 25%) 116px, - rgb(255 206 0 / 25%) 166px - ), repeating-linear-gradient( - -45deg, - transparent, - transparent 5px, - rgb(143 77 63 / 25%) 5px, - rgb(143 77 63 / 25%) 10px - ), repeating-linear-gradient(45deg, transparent, transparent 5px, rgb( - 143 77 63 / 25% - ) 5px, rgb(143 77 63 / 25%) 10px); - - background: repeating-linear-gradient( - 90deg, - transparent 0 50px, - rgb(255 127 0 / 25%) 50px 56px, - transparent 56px 63px, - rgb(255 127 0 / 25%) 63px 69px, - transparent 69px 116px, - rgb(255 206 0 / 25%) 116px 166px - ), repeating-linear-gradient( - 0deg, - transparent 0 50px, - rgb(255 127 0 / 25%) 50px 56px, - transparent 56px 63px, - rgb(255 127 0 / 25%) 63px 69px, - transparent 69px 116px, - rgb(255 206 0 / 25%) 116px 166px - ), repeating-linear-gradient( - -45deg, - transparent 0 5px, - rgb(143 77 63 / 25%) 5px 10px - ), repeating-linear-gradient(45deg, transparent 0 5px, rgb(143 77 63 / 25%) 5px - 10px); -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 64: ), repeating-linear-gradient(45deg, transparent 0 5px, rgb(143 77 63 / 25%) 5px -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-9.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-9.md.snap deleted file mode 100644 index 14ba5f4a434d..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-background-9.md.snap +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-background-9.md ---- - -# Input - -```md - -```css - - -div { - background: conic-gradient( - #fff 0.25turn, - #000 0.25turn 0.5turn, - #fff 0.5turn 0.75turn, - #000 0.75turn - ) top left / 25% 25% repeat; - border: 1px solid; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - -``` - -# Output - -```md - -```css - - -div { - background: conic-gradient( - #fff 0.25turn, - #000 0.25turn 0.5turn, - #fff 0.5turn 0.75turn, - #000 0.75turn - ) top left / 25% 25% repeat; - border: 1px solid; -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-1.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-1.md.snap deleted file mode 100644 index 1ac78764b8b1..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-1.md.snap +++ /dev/null @@ -1,59 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-filter-1.md ---- - -# Input - -```md - -```css - -img { - filter: drop-shadow(2px 2px 0 hsl(300deg 100% 50%)) drop-shadow( - -2px -2px 0 hsl(210deg 100% 50%) ) drop-shadow(2px 2px 0 hsl(120deg 100% 50%)) drop-shadow( - -2px -2px 0 hsl(30deg 100% 50%) - ); -} -img + img { -filter: none; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - img { -``` - -# Output - -```md - -```css - -img { - filter: drop-shadow(2px 2px 0 hsl(300deg 100% 50%)) drop-shadow( - -2px -2px 0 hsl(210deg 100% 50%) ) drop-shadow(2px 2px 0 hsl(120deg 100% 50%)) drop-shadow( - -2px -2px 0 hsl(30deg 100% 50%) - ); -} -img + img { -filter: none; -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 6: -2px -2px 0 hsl(210deg 100% 50%) ) drop-shadow(2px 2px 0 hsl(120deg 100% 50%)) drop-shadow( -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-2.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-2.md.snap deleted file mode 100644 index 9b8ec226b3b5..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-filter-2.md.snap +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-filter-2.md ---- - -# Input - -```md - -```css - - - -#MDN-logo { -border: 1px solid blue; - filter: drop-shadow(5px 5px 0 red) hue-rotate(180deg) drop-shadow(5px 5px 0 - red); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - -``` - -# Output - -```md - -```css - - - -#MDN-logo { -border: 1px solid blue; - filter: drop-shadow(5px 5px 0 red) hue-rotate(180deg) drop-shadow(5px 5px 0 - red); -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-1.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-1.md.snap deleted file mode 100644 index 6a434f1f7ada..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-1.md.snap +++ /dev/null @@ -1,67 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-font-face-1.md ---- - -# Input - -```md - - - -```css - -@font-face { - font-family: "HeydingsControlsRegular"; - src: url("fonts/heydings_controls-webfont.eot"); - src: - url("fonts/heydings_controls-webfont.eot?#iefix") format("embedded-opentype"), -url("fonts/heydings_controls-webfont.woff") format("woff"), - url("fonts/heydings_controls-webfont.ttf") format("truetype"); - font-weight: normal; -font-style: normal; -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,6 @@ -+ -+ -+ - ```css - - @font-face { -``` - -# Output - -```md - - - -```css - -@font-face { - font-family: "HeydingsControlsRegular"; - src: url("fonts/heydings_controls-webfont.eot"); - src: - url("fonts/heydings_controls-webfont.eot?#iefix") format("embedded-opentype"), -url("fonts/heydings_controls-webfont.woff") format("woff"), - url("fonts/heydings_controls-webfont.ttf") format("truetype"); - font-weight: normal; -font-style: normal; -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 10: url("fonts/heydings_controls-webfont.eot?#iefix") format("embedded-opentype"), -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-2.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-2.md.snap deleted file mode 100644 index d77594846714..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-font-face-2.md.snap +++ /dev/null @@ -1,62 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-font-face-2.md ---- - -# Input - -```md - - -```css - - - - - -@font-face { - font-family: "Bungee Spice"; - src: - url("https://fonts.googleapis.com/css2?family=Bungee+Spice") tech(color-COLRv1), url("Bungee-fallback.otf") format("opentype"); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - -``` - -# Output - -```md - - -```css - - - - - -@font-face { - font-family: "Bungee Spice"; - src: - url("https://fonts.googleapis.com/css2?family=Bungee+Spice") tech(color-COLRv1), url("Bungee-fallback.otf") format("opentype"); -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 12: url("https://fonts.googleapis.com/css2?family=Bungee+Spice") tech(color-COLRv1), url("Bungee-fallback.otf") format("opentype"); -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-grid-auto-columns.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-grid-auto-columns.md.snap deleted file mode 100644 index 8ef34fa8beba..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-grid-auto-columns.md.snap +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-grid-auto-columns.md ---- - -# Input - -```md - -```css - -/* multiple track-size values */ -grid-auto-columns: min-content max-content auto; -grid-auto-columns: 100px 150px 390px; -grid-auto-columns: 10% 33.3%; -grid-auto-columns: 0.5fr 3fr 1fr; -grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); -grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - /* multiple track-size values */ -``` - -# Output - -```md - -```css - -/* multiple track-size values */ -grid-auto-columns: min-content max-content auto; -grid-auto-columns: 100px 150px 390px; -grid-auto-columns: 10% 33.3%; -grid-auto-columns: 0.5fr 3fr 1fr; -grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); -grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); -``` -``` - -# Lines exceeding max width of 80 characters -``` - 9: grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); - 10: grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-import.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-import.md.snap deleted file mode 100644 index 0a68676fe6db..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-import.md.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-import.md ---- - -# Input - -```md - - -```css - - -@import url("gridy.css") supports( display: grid) screen and (max-width: 400px); -@import url("flexy.css") supports(not (display: grid ) and (display: flex)) screen and (max-width: 400px); -@import url( -"whatever.css") supports((selector(h2 > p)) and (font-tech(color-COLRv1))); -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - -``` - -# Output - -```md - - -```css - - -@import url("gridy.css") supports( display: grid) screen and (max-width: 400px); -@import url("flexy.css") supports(not (display: grid ) and (display: flex)) screen and (max-width: 400px); -@import url( -"whatever.css") supports((selector(h2 > p)) and (font-tech(color-COLRv1))); -``` -``` - -# Lines exceeding max width of 80 characters -``` - 6: @import url("gridy.css") supports( display: grid) screen and (max-width: 400px); - 7: @import url("flexy.css") supports(not (display: grid ) and (display: flex)) screen and (max-width: 400px); -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-mask-image.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-mask-image.md.snap deleted file mode 100644 index c084e4799945..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-mask-image.md.snap +++ /dev/null @@ -1,45 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-mask-image.md ---- - -# Input - -```md - -```css - -/* Multiple values */ -mask-image: image(url(mask.png), skyblue), linear-gradient(rgb(0 0 0 / 100%), transparent); -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - /* Multiple values */ -``` - -# Output - -```md - -```css - -/* Multiple values */ -mask-image: image(url(mask.png), skyblue), linear-gradient(rgb(0 0 0 / 100%), transparent); -``` -``` - -# Lines exceeding max width of 80 characters -``` - 5: mask-image: image(url(mask.png), skyblue), linear-gradient(rgb(0 0 0 / 100%), transparent); -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-1.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-1.md.snap deleted file mode 100644 index a2763f7e5f20..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-1.md.snap +++ /dev/null @@ -1,51 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-padding-1.md ---- - -# Input - -```md - - -```css - -body { -padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env( - safe-area-inset-bottom, - 20px - ) env(safe-area-inset-left, 20px); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - body { -``` - -# Output - -```md - - -```css - -body { -padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env( - safe-area-inset-bottom, - 20px - ) env(safe-area-inset-left, 20px); -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-2.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-2.md.snap deleted file mode 100644 index 4834a240f205..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-padding-2.md.snap +++ /dev/null @@ -1,60 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-padding-2.md ---- - -# Input - -```md - - -```css - -p { - width: 300px; - border: 2px solid red; - padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px) env( - safe-area-inset-bottom, - 50px - ) env(SAFE-AREA-INSET-LEFT, 50px); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - p { -``` - -# Output - -```md - - -```css - -p { - width: 300px; - border: 2px solid red; - padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px) env( - safe-area-inset-bottom, - 50px - ) env(SAFE-AREA-INSET-LEFT, 50px); -} -``` -``` - -# Lines exceeding max width of 80 characters -``` - 8: padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px) env( -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-transform.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-transform.md.snap deleted file mode 100644 index b932c751a143..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-transform.md.snap +++ /dev/null @@ -1,76 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-transform.md ---- - -# Input - -```md - -```css - -#example-element:focus { - transform: rotate3d(1, 1, 1, 30deg) matrix3d( - 1, - 0, - 0, - 0, - 0, - 1, - 6, - 0, - 0, - 0, - 1, - 0, - 50, - 100, - 0, - 1.1 - ); -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,4 @@ -+ - ```css - - #example-element:focus { -``` - -# Output - -```md - -```css - -#example-element:focus { - transform: rotate3d(1, 1, 1, 30deg) matrix3d( - 1, - 0, - 0, - 0, - 0, - 1, - 6, - 0, - 0, - 0, - 1, - 0, - 50, - 100, - 0, - 1.1 - ); -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-unicode-range.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-unicode-range.md.snap deleted file mode 100644 index a558dae4f4d8..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/mdn-unicode-range.md.snap +++ /dev/null @@ -1,77 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/mdn-unicode-range.md ---- - -# Input - -```md - - -```css - - - -@media (prefers-reduced-data: no-preference) { - @font-face { - font-family: Montserrat; - font-style: normal; - font-weight: 400; - font-display: swap; - /* latin */ - src: - local("Montserrat Regular"), - local("Montserrat-Regular"), - url("fonts/montserrat-regular.woff2") format("woff2"); - unicode-range: U+0000-00FF, U+0131, -U+0152-0153, U+02BB-02BC, U+02C6, - U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, - U+2212, U+2215, U+FEFF, U+FFFD; - } -} -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,5 @@ -+ -+ - ```css - - -``` - -# Output - -```md - - -```css - - - -@media (prefers-reduced-data: no-preference) { - @font-face { - font-family: Montserrat; - font-style: normal; - font-weight: 400; - font-display: swap; - /* latin */ - src: - local("Montserrat Regular"), - local("Montserrat-Regular"), - url("fonts/montserrat-regular.woff2") format("woff2"); - unicode-range: U+0000-00FF, U+0131, -U+0152-0153, U+02BB-02BC, U+02C6, - U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, - U+2212, U+2215, U+FEFF, U+FFFD; - } -} -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/link/encodedLink.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/link/encodedLink.md.snap index 2d63c39f3c48..1b495e55ba8e 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/link/encodedLink.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/link/encodedLink.md.snap @@ -41,13 +41,6 @@ info: markdown/link/encodedLink.md ![link](https://www.google.fr/foo->bar) ![link](https://www.google.fr/foo-%3Ebar) ![link](https://www.google.fr/foo-bar - [link]: https://www.google.fr/foo-%3Ebar - [link]: https://www.google.fr/foo-bar [link]: https://www.google.fr/foo-%3Ebar [link]: https://www.google.fr/foo- | +| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean \| object | false | +| split | Toggles rendering of the split under the list item | boolean | true | -\ No newline at end of file ``` # Output @@ -72,7 +71,8 @@ info: markdown/long-table/long-table.md | loadMore | Shows a load more content | string\|ReactNode | - | | locale | i18n text including empty text | object | emptyText: 'No Data'
| | pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean \| object | false | -| split | Toggles rendering of the split under the list item | boolean | true |``` +| split | Toggles rendering of the split under the list item | boolean | true | +``` # Lines exceeding max width of 80 characters ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/markdown/real-world-case.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/markdown/real-world-case.md.snap index 868b107bc531..4a0105370956 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/markdown/real-world-case.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/markdown/real-world-case.md.snap @@ -1064,7 +1064,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). ```js (text: string, parsers: object, options: object) => AST; ``` -@@ -552,138 +546,121 @@ +@@ -552,11 +546,9 @@ ``` ## Options @@ -1076,9 +1076,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). Specify the line length that the printer will wrap on. > **For readability we recommend against using more than 80 characters:** - > --> In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. -+>In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. +@@ -565,125 +557,110 @@ > > Prettier, on the other hand, strives to fit the most code into every line. With the print width set to 120, prettier may produce overly compact, or otherwise undesirable code. @@ -1176,14 +1174,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). -- `true` - Example: `{ foo: bar }`. -- `false` - Example: `{foo: bar}`. -- --| Default | CLI Override | API Override | --| ------- | ---------------------- | ------------------------ | --| `true` | `--no-bracket-spacing` | `bracketSpacing: ` | +Default | CLI Override | API Override +--------|--------------|------------- +`true` | `--no-bracket-spacing` | `bracketSpacing: ` +-| Default | CLI Override | API Override | +-| ------- | ---------------------- | ------------------------ | +-| `true` | `--no-bracket-spacing` | `bracketSpacing: ` | +- ### JSX Brackets - Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line (does not apply to self closing elements). @@ -1220,6 +1218,13 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). Both the `babylon` and `flow` parsers support the same set of JavaScript features (including Flow). Prettier automatically infers the parser from the input file path, so you shouldn't have to change this setting. Built-in parsers: +- +-- [`babylon`](https://github.com/babel/babylon/) +-- [`flow`](https://github.com/facebook/flow/tree/master/src/parser) +-- [`typescript`](https://github.com/eslint/typescript-eslint-parser) _Since v1.4.0_ +-- [`postcss`](https://github.com/postcss/postcss) _Since v1.4.0_ +-- [`json`](https://github.com/babel/babylon/tree/f09eb3200f57ea94d51c2a5b1facf2149fb406bf#babylonparseexpressioncode-options) _Since v1.5.0_ +-- [`graphql`](https://github.com/graphql/graphql-js/tree/master/src/language) _Since v1.5.0_ + - [`babylon`](https://github.com/babel/babylon/) + - [`flow`](https://github.com/facebook/flow/tree/master/src/parser) + - [`typescript`](https://github.com/eslint/typescript-eslint-parser) _Since v1.4.0_ @@ -1227,16 +1232,9 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). + - [`json`](https://github.com/babel/babylon/tree/f09eb3200f57ea94d51c2a5b1facf2149fb406bf#babylonparseexpressioncode-options) _Since v1.5.0_ + - [`graphql`](https://github.com/graphql/graphql-js/tree/master/src/language) _Since v1.5.0_ --- [`babylon`](https://github.com/babel/babylon/) --- [`flow`](https://github.com/facebook/flow/tree/master/src/parser) --- [`typescript`](https://github.com/eslint/typescript-eslint-parser) _Since v1.4.0_ --- [`postcss`](https://github.com/postcss/postcss) _Since v1.4.0_ --- [`json`](https://github.com/babel/babylon/tree/f09eb3200f57ea94d51c2a5b1facf2149fb406bf#babylonparseexpressioncode-options) _Since v1.5.0_ --- [`graphql`](https://github.com/graphql/graphql-js/tree/master/src/language) _Since v1.5.0_ +-[Custom parsers](#custom-parser-api) are also supported. _Since v1.5.0_ +[Custom parsers](#custom-parser-api) are also supported. _Since v1.5.0_ --[Custom parsers](#custom-parser-api) are also supported. _Since v1.5.0_ -- -| Default | CLI Override | API Override | -| --------- | ----------------------------------------------- | ---------------------------------------------------------- | -| `babylon` | `--parser `
`--parser ./my-parser` | `parser: ""`
`parser: require("./my-parser")` | @@ -1859,7 +1857,7 @@ Specify the line length that the printer will wrap on. > **For readability we recommend against using more than 80 characters:** > ->In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. +> In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. > > Prettier, on the other hand, strives to fit the most code into every line. With the print width set to 120, prettier may produce overly compact, or otherwise undesirable code. @@ -2288,7 +2286,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). 512: The `--parser` CLI option may be a path to a node.js module exporting a parse function. 516: A JavaScript comment of `// prettier-ignore` will exclude the next node in the abstract syntax tree from formatting. 549: Prettier ships with a handful of customizable format options, usable in both the CLI and API. - 556: >In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. + 556: > In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. 558: > Prettier, on the other hand, strives to fit the most code into every line. With the print width set to 120, prettier may produce overly compact, or otherwise undesirable code. 584: - `false` - Only add semicolons at the beginning of lines that may introduce ASI failures. 595: - If the number of quotes outweighs the other quote, the quote which is less used will be used to format the string - Example: `"I'm double quoted"` results in `"I'm double quoted"` and `"This \"example\" is single quoted"` results in `'This "example" is single quoted'`. diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-json/invalid-json.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-json/invalid-json.md.snap index 72d15cd85506..06ba81af8592 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-json/invalid-json.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-json/invalid-json.md.snap @@ -23,9 +23,7 @@ packages\the-hub\cypress\fixtures\gridConfiguration.json - ```json packages\the-hub\cypress\fixtures\gridConfiguration.json --``` -+``` -\ No newline at end of file + ``` ``` # Output @@ -34,4 +32,5 @@ packages\the-hub\cypress\fixtures\gridConfiguration.json ```json packages\the-hub\cypress\fixtures\gridConfiguration.json -`````` +``` +``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/commonmark-0.30-example-337.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/commonmark-0.30-example-337.md.snap deleted file mode 100644 index 11ee9f9f89b8..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/commonmark-0.30-example-337.md.snap +++ /dev/null @@ -1,30 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/spec/commonmark-0.30-example-337.md ---- - -# Input - -```md -`foo bar -baz` -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,2 +1,2 @@ - `foo bar --baz` -+baz` -\ No newline at end of file -``` - -# Output - -```md -`foo bar -baz```` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-187.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-187.md.snap index 75ca77101cff..848dc345c480 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-187.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-187.md.snap @@ -23,26 +23,18 @@ aaa ```diff --- Prettier +++ Biome -@@ -1,3 +1,8 @@ -+ -+ +@@ -1,3 +1,4 @@ aaa + # aaa -+ -+ ``` # Output ```md - - aaa # aaa - - ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-189.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-189.md.snap index 1347111f1438..ce61f0b6e2b5 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-189.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-189.md.snap @@ -19,18 +19,16 @@ info: markdown/spec/example-189.md --- Prettier +++ Biome @@ -1,4 +1,3 @@ --> # Foo + > # Foo -> --> bar -+># Foo -+>bar + > bar > baz ``` # Output ```md -># Foo ->bar +> # Foo +> bar > baz ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-211.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-211.md.snap index c217ba5a4796..f00effcc2f4f 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-211.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-211.md.snap @@ -19,18 +19,17 @@ info: markdown/spec/example-211.md --- Prettier +++ Biome @@ -1,3 +1,3 @@ --> > > foo + > > > foo -> > > bar -> > > baz -+>>> foo +> bar -+>>baz ++> > baz ``` # Output ```md ->>> foo +> > > foo > bar ->>baz +> > baz ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-220.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-220.md.snap index 8efff89be615..1ac29e3d7ead 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-220.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-220.md.snap @@ -19,18 +19,16 @@ info: markdown/spec/example-220.md --- Prettier +++ Biome @@ -1,3 +1,3 @@ --> > - one --> > + > > - one + > > -> > two -+>>- one -+>> + > > two ``` # Output ```md ->>- one ->> +> > - one +> > > > two ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-48.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-48.md.snap index 3a415d275b23..902af8da1fc3 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-48.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-48.md.snap @@ -24,8 +24,7 @@ info: markdown/spec/example-48.md +## # - --### -+### + ### ``` # Output @@ -33,5 +32,5 @@ info: markdown/spec/example-48.md ```md ## # -### +### ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-543.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-543.md.snap deleted file mode 100644 index fc01c07508c3..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-543.md.snap +++ /dev/null @@ -1,28 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/spec/example-543.md ---- - -# Input - -```md -![foo]() - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1 @@ --![foo](url) -+![foo]() -``` - -# Output - -```md -![foo]() -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-65.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-65.md.snap deleted file mode 100644 index e599ffe999e6..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-65.md.snap +++ /dev/null @@ -1,30 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/spec/example-65.md ---- - -# Input - -```md - -==== - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1,2 @@ -+ - ==== -``` - -# Output - -```md - -==== -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-85.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-85.md.snap deleted file mode 100644 index 56cba9bcd41e..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-85.md.snap +++ /dev/null @@ -1,36 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/spec/example-85.md ---- - -# Input - -```md - - - foo - - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1,4 @@ -+ -+ - foo -+ -``` - -# Output - -```md - - - foo - -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/table/issue-15572.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/table/issue-15572.md.snap deleted file mode 100644 index 14d12b81981a..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/table/issue-15572.md.snap +++ /dev/null @@ -1,38 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/table/issue-15572.md ---- - -# Input - -```md -| | | -| :-: | :-: | -| ✔ | ✘ | -| ✘ | ✔ | -| ✔ | ✘ | -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -2,4 +2,4 @@ - | :-: | :-: | - | ✔ | ✘ | - | ✘ | ✔ | --| ✔ | ✘ | -+| ✔ | ✘ | -\ No newline at end of file -``` - -# Output - -```md -| | | -| :-: | :-: | -| ✔ | ✘ | -| ✘ | ✔ | -| ✔ | ✘ |``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-leading.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-leading.md.snap deleted file mode 100644 index 126747db95ed..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-leading.md.snap +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/wiki-link/extra-brackets-leading.md ---- - -# Input - -```md -A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. - - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1,2 @@ - A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. -+ -``` - -# Output - -```md -A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. - -``` - -# Lines exceeding max width of 80 characters -``` - 1: A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-trailing.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-trailing.md.snap deleted file mode 100644 index 515cb1f63a0c..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets-trailing.md.snap +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/wiki-link/extra-brackets-trailing.md ---- - -# Input - -```md -A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. - - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1,2 @@ - A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. -+ -``` - -# Output - -```md -A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. - -``` - -# Lines exceeding max width of 80 characters -``` - 1: A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets.md.snap deleted file mode 100644 index 09a8097b4f96..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/wiki-link/extra-brackets.md.snap +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/wiki-link/extra-brackets.md ---- - -# Input - -```md -A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. - - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1 +1,2 @@ - A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. -+ -``` - -# Output - -```md -A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. - -``` - -# Lines exceeding max width of 80 characters -``` - 1: A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. -``` diff --git a/crates/biome_markdown_parser/src/lexer/mod.rs b/crates/biome_markdown_parser/src/lexer/mod.rs index 1f5c2bf67dcd..c932558fea91 100644 --- a/crates/biome_markdown_parser/src/lexer/mod.rs +++ b/crates/biome_markdown_parser/src/lexer/mod.rs @@ -1220,11 +1220,17 @@ impl<'src> MarkdownLexer<'src> { offset += 1; } - // Check if followed by newline - if space_count >= 2 - && let Some(next) = self.byte_at(offset) - { - return next == b'\n' || next == b'\r'; + if space_count >= 2 { + // A hard line break requires 2+ spaces followed by a newline + // (https://spec.commonmark.org/0.31.2/#hard-line-breaks). + // Trailing spaces at EOF are never a valid hard line break, + // but they must be split from the preceding text so the + // formatter can strip them without idempotency issues. + match self.byte_at(offset) { + None => return true, + Some(b'\n' | b'\r') => return true, + _ => {} + } } false