diff --git a/crates/biome_markdown_factory/src/generated/node_factory.rs b/crates/biome_markdown_factory/src/generated/node_factory.rs index d4a7776fa04b..dcc2c608987d 100644 --- a/crates/biome_markdown_factory/src/generated/node_factory.rs +++ b/crates/biome_markdown_factory/src/generated/node_factory.rs @@ -312,35 +312,6 @@ impl MdInlineLinkBuilder { )) } } -pub fn md_link_block(label: MdTextual, url: MdTextual) -> MdLinkBlockBuilder { - MdLinkBlockBuilder { - label, - url, - title: None, - } -} -pub struct MdLinkBlockBuilder { - label: MdTextual, - url: MdTextual, - title: Option, -} -impl MdLinkBlockBuilder { - pub fn with_title(mut self, title: MdTextual) -> Self { - self.title = Some(title); - self - } - pub fn build(self) -> MdLinkBlock { - MdLinkBlock::unwrap_cast(SyntaxNode::new_detached( - MarkdownSyntaxKind::MD_LINK_BLOCK, - [ - Some(SyntaxElement::Node(self.label.into_syntax())), - Some(SyntaxElement::Node(self.url.into_syntax())), - self.title - .map(|token| SyntaxElement::Node(token.into_syntax())), - ], - )) - } -} pub fn md_link_destination(content: MdInlineItemList) -> MdLinkDestination { MdLinkDestination::unwrap_cast(SyntaxNode::new_detached( MarkdownSyntaxKind::MD_LINK_DESTINATION, diff --git a/crates/biome_markdown_factory/src/generated/syntax_factory.rs b/crates/biome_markdown_factory/src/generated/syntax_factory.rs index 95671fdc7eff..d22b91213c85 100644 --- a/crates/biome_markdown_factory/src/generated/syntax_factory.rs +++ b/crates/biome_markdown_factory/src/generated/syntax_factory.rs @@ -604,39 +604,6 @@ impl SyntaxFactory for MarkdownSyntaxFactory { } slots.into_node(MD_INLINE_LINK, children) } - MD_LINK_BLOCK => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element - && MdTextual::can_cast(element.kind()) - { - slots.mark_present(); - current_element = elements.next(); - } - slots.next_slot(); - if let Some(element) = ¤t_element - && MdTextual::can_cast(element.kind()) - { - slots.mark_present(); - current_element = elements.next(); - } - slots.next_slot(); - if let Some(element) = ¤t_element - && MdTextual::can_cast(element.kind()) - { - slots.mark_present(); - current_element = elements.next(); - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - MD_LINK_BLOCK.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(MD_LINK_BLOCK, children) - } MD_LINK_DESTINATION => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); diff --git a/crates/biome_markdown_formatter/src/comments.rs b/crates/biome_markdown_formatter/src/comments.rs index c95653244674..d39ad259b074 100644 --- a/crates/biome_markdown_formatter/src/comments.rs +++ b/crates/biome_markdown_formatter/src/comments.rs @@ -6,7 +6,7 @@ use biome_formatter::{ use biome_markdown_syntax::MarkdownLanguage; use biome_rowan::SyntaxTriviaPieceComments; -use crate::MdFormatContext; +use crate::MarkdownFormatContext; #[derive(Eq, PartialEq, Copy, Clone, Debug, Default)] pub struct MarkdownCommentStyle; @@ -34,7 +34,7 @@ impl CommentStyle for MarkdownCommentStyle { pub struct FormatMarkdownLeadingComment; impl FormatRule> for FormatMarkdownLeadingComment { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt( &self, diff --git a/crates/biome_markdown_formatter/src/context.rs b/crates/biome_markdown_formatter/src/context.rs index 61d33e58f4e6..f476051b4e05 100644 --- a/crates/biome_markdown_formatter/src/context.rs +++ b/crates/biome_markdown_formatter/src/context.rs @@ -10,7 +10,7 @@ use crate::comments::{FormatMarkdownLeadingComment, MarkdownCommentStyle}; pub type MarkdownComments = Comments; -pub struct MdFormatContext { +pub struct MarkdownFormatContext { source_map: Option, options: MdFormatOptions, comments: Rc, @@ -25,7 +25,7 @@ pub struct MdFormatOptions { trailing_newline: TrailingNewline, } -impl CstFormatContext for MdFormatContext { +impl CstFormatContext for MarkdownFormatContext { type Language = MarkdownLanguage; type Style = MarkdownCommentStyle; type CommentRule = FormatMarkdownLeadingComment; @@ -98,7 +98,7 @@ impl MdFormatOptions { } } -impl MdFormatContext { +impl MarkdownFormatContext { pub fn new(options: MdFormatOptions) -> Self { Self { options, @@ -117,7 +117,7 @@ impl MdFormatContext { } } -impl FormatContext for MdFormatContext { +impl FormatContext for MarkdownFormatContext { type Options = MdFormatOptions; fn options(&self) -> &Self::Options { diff --git a/crates/biome_markdown_formatter/src/cst.rs b/crates/biome_markdown_formatter/src/cst.rs index 74e62ed1362e..c415049fc8a0 100644 --- a/crates/biome_markdown_formatter/src/cst.rs +++ b/crates/biome_markdown_formatter/src/cst.rs @@ -1,4 +1,4 @@ -use crate::{MdFormatContext, prelude::*}; +use crate::{MarkdownFormatContext, prelude::*}; use biome_formatter::trivia::{FormatToken, format_skipped_token_trivia}; use biome_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult}; use biome_markdown_syntax::{ @@ -9,7 +9,7 @@ use biome_markdown_syntax::{ pub struct FormatMdSyntaxToken; impl FormatRule for FormatMdSyntaxToken { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt( &self, @@ -23,25 +23,25 @@ impl FormatRule for FormatMdSyntaxToken { } } -impl FormatToken for FormatMdSyntaxToken { +impl FormatToken for FormatMdSyntaxToken { fn format_skipped_token_trivia( &self, token: &MarkdownSyntaxToken, - f: &mut Formatter, + f: &mut Formatter, ) -> FormatResult<()> { format_skipped_token_trivia(token).fmt(f) } } impl FormatRule for FormatMdSyntaxToken { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MarkdownSyntaxNode, f: &mut MarkdownFormatter) -> FormatResult<()> { map_syntax_node!(node.clone(), node => node.format().fmt(f)) } } -impl AsFormat for MarkdownSyntaxNode { +impl AsFormat for MarkdownSyntaxNode { type Format<'a> = FormatRefWithRule<'a, Self, FormatMdSyntaxToken>; fn format(&self) -> Self::Format<'_> { @@ -49,7 +49,7 @@ impl AsFormat for MarkdownSyntaxNode { } } -impl IntoFormat for MarkdownSyntaxNode { +impl IntoFormat for MarkdownSyntaxNode { type Format = FormatOwnedWithRule; fn into_format(self) -> Self::Format { @@ -57,7 +57,7 @@ impl IntoFormat for MarkdownSyntaxNode { } } -impl AsFormat for MarkdownSyntaxToken { +impl AsFormat for MarkdownSyntaxToken { type Format<'a> = FormatRefWithRule<'a, Self, FormatMdSyntaxToken>; fn format(&self) -> Self::Format<'_> { @@ -65,7 +65,7 @@ impl AsFormat for MarkdownSyntaxToken { } } -impl IntoFormat for MarkdownSyntaxToken { +impl IntoFormat for MarkdownSyntaxToken { type Format = FormatOwnedWithRule; fn into_format(self) -> Self::Format { diff --git a/crates/biome_markdown_formatter/src/generated.rs b/crates/biome_markdown_formatter/src/generated.rs index 967af2dd54a1..56c355505bd2 100644 --- a/crates/biome_markdown_formatter/src/generated.rs +++ b/crates/biome_markdown_formatter/src/generated.rs @@ -3,13 +3,14 @@ #![allow(clippy::use_self)] #![expect(clippy::default_constructed_unit_structs)] use crate::{ - AsFormat, FormatBogusNodeRule, FormatNodeRule, IntoFormat, MarkdownFormatter, MdFormatContext, + AsFormat, FormatBogusNodeRule, FormatNodeRule, IntoFormat, MarkdownFormatContext, + MarkdownFormatter, }; use biome_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule}; impl FormatRule for crate::markdown::auxiliary::autolink::FormatMdAutolink { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -19,7 +20,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdAutolink { +impl AsFormat for biome_markdown_syntax::MdAutolink { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdAutolink, @@ -32,7 +33,7 @@ impl AsFormat for biome_markdown_syntax::MdAutolink { ) } } -impl IntoFormat for biome_markdown_syntax::MdAutolink { +impl IntoFormat for biome_markdown_syntax::MdAutolink { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdAutolink, crate::markdown::auxiliary::autolink::FormatMdAutolink, @@ -47,7 +48,7 @@ impl IntoFormat for biome_markdown_syntax::MdAutolink { impl FormatRule for crate::markdown::auxiliary::bullet::FormatMdBullet { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -57,7 +58,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdBullet { +impl AsFormat for biome_markdown_syntax::MdBullet { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdBullet, @@ -70,7 +71,7 @@ impl AsFormat for biome_markdown_syntax::MdBullet { ) } } -impl IntoFormat for biome_markdown_syntax::MdBullet { +impl IntoFormat for biome_markdown_syntax::MdBullet { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdBullet, crate::markdown::auxiliary::bullet::FormatMdBullet, @@ -85,7 +86,7 @@ impl IntoFormat for biome_markdown_syntax::MdBullet { impl FormatRule for crate::markdown::auxiliary::bullet_list_item::FormatMdBulletListItem { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -95,7 +96,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdBulletListItem { +impl AsFormat for biome_markdown_syntax::MdBulletListItem { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdBulletListItem, @@ -108,7 +109,7 @@ impl AsFormat for biome_markdown_syntax::MdBulletListItem { ) } } -impl IntoFormat for biome_markdown_syntax::MdBulletListItem { +impl IntoFormat for biome_markdown_syntax::MdBulletListItem { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdBulletListItem, crate::markdown::auxiliary::bullet_list_item::FormatMdBulletListItem, @@ -123,7 +124,7 @@ impl IntoFormat for biome_markdown_syntax::MdBulletListItem { impl FormatRule for crate::markdown::auxiliary::document::FormatMdDocument { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -133,7 +134,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdDocument { +impl AsFormat for biome_markdown_syntax::MdDocument { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdDocument, @@ -146,7 +147,7 @@ impl AsFormat for biome_markdown_syntax::MdDocument { ) } } -impl IntoFormat for biome_markdown_syntax::MdDocument { +impl IntoFormat for biome_markdown_syntax::MdDocument { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdDocument, crate::markdown::auxiliary::document::FormatMdDocument, @@ -161,7 +162,7 @@ impl IntoFormat for biome_markdown_syntax::MdDocument { impl FormatRule for crate::markdown::auxiliary::entity_reference::FormatMdEntityReference { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -171,7 +172,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdEntityReference { +impl AsFormat for biome_markdown_syntax::MdEntityReference { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdEntityReference, @@ -184,7 +185,7 @@ impl AsFormat for biome_markdown_syntax::MdEntityReference { ) } } -impl IntoFormat for biome_markdown_syntax::MdEntityReference { +impl IntoFormat for biome_markdown_syntax::MdEntityReference { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdEntityReference, crate::markdown::auxiliary::entity_reference::FormatMdEntityReference, @@ -199,7 +200,7 @@ impl IntoFormat for biome_markdown_syntax::MdEntityReference { impl FormatRule for crate::markdown::auxiliary::fenced_code_block::FormatMdFencedCodeBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -209,7 +210,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdFencedCodeBlock { +impl AsFormat for biome_markdown_syntax::MdFencedCodeBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdFencedCodeBlock, @@ -222,7 +223,7 @@ impl AsFormat for biome_markdown_syntax::MdFencedCodeBlock { ) } } -impl IntoFormat for biome_markdown_syntax::MdFencedCodeBlock { +impl IntoFormat for biome_markdown_syntax::MdFencedCodeBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdFencedCodeBlock, crate::markdown::auxiliary::fenced_code_block::FormatMdFencedCodeBlock, @@ -237,7 +238,7 @@ impl IntoFormat for biome_markdown_syntax::MdFencedCodeBlock { impl FormatRule for crate::markdown::auxiliary::hard_line::FormatMdHardLine { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -247,7 +248,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdHardLine { +impl AsFormat for biome_markdown_syntax::MdHardLine { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdHardLine, @@ -260,7 +261,7 @@ impl AsFormat for biome_markdown_syntax::MdHardLine { ) } } -impl IntoFormat for biome_markdown_syntax::MdHardLine { +impl IntoFormat for biome_markdown_syntax::MdHardLine { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdHardLine, crate::markdown::auxiliary::hard_line::FormatMdHardLine, @@ -273,7 +274,7 @@ impl IntoFormat for biome_markdown_syntax::MdHardLine { } } impl FormatRule for crate::markdown::auxiliary::hash::FormatMdHash { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -283,7 +284,7 @@ impl FormatRule for crate::markdown::auxiliary::h FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdHash { +impl AsFormat for biome_markdown_syntax::MdHash { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdHash, @@ -296,7 +297,7 @@ impl AsFormat for biome_markdown_syntax::MdHash { ) } } -impl IntoFormat for biome_markdown_syntax::MdHash { +impl IntoFormat for biome_markdown_syntax::MdHash { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdHash, crate::markdown::auxiliary::hash::FormatMdHash, @@ -311,7 +312,7 @@ impl IntoFormat for biome_markdown_syntax::MdHash { impl FormatRule for crate::markdown::auxiliary::header::FormatMdHeader { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -321,7 +322,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdHeader { +impl AsFormat for biome_markdown_syntax::MdHeader { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdHeader, @@ -334,7 +335,7 @@ impl AsFormat for biome_markdown_syntax::MdHeader { ) } } -impl IntoFormat for biome_markdown_syntax::MdHeader { +impl IntoFormat for biome_markdown_syntax::MdHeader { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdHeader, crate::markdown::auxiliary::header::FormatMdHeader, @@ -349,7 +350,7 @@ impl IntoFormat for biome_markdown_syntax::MdHeader { impl FormatRule for crate::markdown::auxiliary::html_block::FormatMdHtmlBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -359,7 +360,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdHtmlBlock { +impl AsFormat for biome_markdown_syntax::MdHtmlBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdHtmlBlock, @@ -372,7 +373,7 @@ impl AsFormat for biome_markdown_syntax::MdHtmlBlock { ) } } -impl IntoFormat for biome_markdown_syntax::MdHtmlBlock { +impl IntoFormat for biome_markdown_syntax::MdHtmlBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdHtmlBlock, crate::markdown::auxiliary::html_block::FormatMdHtmlBlock, @@ -387,7 +388,7 @@ impl IntoFormat for biome_markdown_syntax::MdHtmlBlock { impl FormatRule for crate::markdown::auxiliary::indent::FormatMdIndent { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -397,7 +398,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdIndent { +impl AsFormat for biome_markdown_syntax::MdIndent { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdIndent, @@ -410,7 +411,7 @@ impl AsFormat for biome_markdown_syntax::MdIndent { ) } } -impl IntoFormat for biome_markdown_syntax::MdIndent { +impl IntoFormat for biome_markdown_syntax::MdIndent { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdIndent, crate::markdown::auxiliary::indent::FormatMdIndent, @@ -425,7 +426,7 @@ impl IntoFormat for biome_markdown_syntax::MdIndent { impl FormatRule for crate::markdown::auxiliary::indent_code_block::FormatMdIndentCodeBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -435,7 +436,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdIndentCodeBlock { +impl AsFormat for biome_markdown_syntax::MdIndentCodeBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdIndentCodeBlock, @@ -448,7 +449,7 @@ impl AsFormat for biome_markdown_syntax::MdIndentCodeBlock { ) } } -impl IntoFormat for biome_markdown_syntax::MdIndentCodeBlock { +impl IntoFormat for biome_markdown_syntax::MdIndentCodeBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdIndentCodeBlock, crate::markdown::auxiliary::indent_code_block::FormatMdIndentCodeBlock, @@ -463,7 +464,7 @@ impl IntoFormat for biome_markdown_syntax::MdIndentCodeBlock { impl FormatRule for crate::markdown::auxiliary::indent_token::FormatMdIndentToken { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -473,7 +474,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdIndentToken { +impl AsFormat for biome_markdown_syntax::MdIndentToken { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdIndentToken, @@ -486,7 +487,7 @@ impl AsFormat for biome_markdown_syntax::MdIndentToken { ) } } -impl IntoFormat for biome_markdown_syntax::MdIndentToken { +impl IntoFormat for biome_markdown_syntax::MdIndentToken { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdIndentToken, crate::markdown::auxiliary::indent_token::FormatMdIndentToken, @@ -501,7 +502,7 @@ impl IntoFormat for biome_markdown_syntax::MdIndentToken { impl FormatRule for crate::markdown::auxiliary::inline_code::FormatMdInlineCode { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -511,7 +512,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdInlineCode { +impl AsFormat for biome_markdown_syntax::MdInlineCode { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineCode, @@ -524,7 +525,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineCode { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineCode { +impl IntoFormat for biome_markdown_syntax::MdInlineCode { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineCode, crate::markdown::auxiliary::inline_code::FormatMdInlineCode, @@ -539,7 +540,7 @@ impl IntoFormat for biome_markdown_syntax::MdInlineCode { impl FormatRule for crate::markdown::auxiliary::inline_emphasis::FormatMdInlineEmphasis { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -549,7 +550,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdInlineEmphasis { +impl AsFormat for biome_markdown_syntax::MdInlineEmphasis { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineEmphasis, @@ -562,7 +563,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineEmphasis { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineEmphasis { +impl IntoFormat for biome_markdown_syntax::MdInlineEmphasis { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineEmphasis, crate::markdown::auxiliary::inline_emphasis::FormatMdInlineEmphasis, @@ -577,7 +578,7 @@ impl IntoFormat for biome_markdown_syntax::MdInlineEmphasis { impl FormatRule for crate::markdown::auxiliary::inline_html::FormatMdInlineHtml { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -587,7 +588,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdInlineHtml { +impl AsFormat for biome_markdown_syntax::MdInlineHtml { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineHtml, @@ -600,7 +601,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineHtml { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineHtml { +impl IntoFormat for biome_markdown_syntax::MdInlineHtml { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineHtml, crate::markdown::auxiliary::inline_html::FormatMdInlineHtml, @@ -615,7 +616,7 @@ impl IntoFormat for biome_markdown_syntax::MdInlineHtml { impl FormatRule for crate::markdown::auxiliary::inline_image::FormatMdInlineImage { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -625,7 +626,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdInlineImage { +impl AsFormat for biome_markdown_syntax::MdInlineImage { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineImage, @@ -638,7 +639,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineImage { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineImage { +impl IntoFormat for biome_markdown_syntax::MdInlineImage { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineImage, crate::markdown::auxiliary::inline_image::FormatMdInlineImage, @@ -653,7 +654,7 @@ impl IntoFormat for biome_markdown_syntax::MdInlineImage { impl FormatRule for crate::markdown::auxiliary::inline_italic::FormatMdInlineItalic { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -663,7 +664,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdInlineItalic { +impl AsFormat for biome_markdown_syntax::MdInlineItalic { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineItalic, @@ -676,7 +677,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineItalic { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineItalic { +impl IntoFormat for biome_markdown_syntax::MdInlineItalic { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineItalic, crate::markdown::auxiliary::inline_italic::FormatMdInlineItalic, @@ -691,7 +692,7 @@ impl IntoFormat for biome_markdown_syntax::MdInlineItalic { impl FormatRule for crate::markdown::auxiliary::inline_link::FormatMdInlineLink { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -701,7 +702,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdInlineLink { +impl AsFormat for biome_markdown_syntax::MdInlineLink { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineLink, @@ -714,7 +715,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineLink { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineLink { +impl IntoFormat for biome_markdown_syntax::MdInlineLink { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineLink, crate::markdown::auxiliary::inline_link::FormatMdInlineLink, @@ -726,48 +727,10 @@ impl IntoFormat for biome_markdown_syntax::MdInlineLink { ) } } -impl FormatRule - for crate::markdown::auxiliary::link_block::FormatMdLinkBlock -{ - type Context = MdFormatContext; - #[inline(always)] - fn fmt( - &self, - node: &biome_markdown_syntax::MdLinkBlock, - f: &mut MarkdownFormatter, - ) -> FormatResult<()> { - FormatNodeRule::::fmt(self, node, f) - } -} -impl AsFormat for biome_markdown_syntax::MdLinkBlock { - type Format<'a> = FormatRefWithRule< - 'a, - biome_markdown_syntax::MdLinkBlock, - crate::markdown::auxiliary::link_block::FormatMdLinkBlock, - >; - fn format(&self) -> Self::Format<'_> { - FormatRefWithRule::new( - self, - crate::markdown::auxiliary::link_block::FormatMdLinkBlock::default(), - ) - } -} -impl IntoFormat for biome_markdown_syntax::MdLinkBlock { - type Format = FormatOwnedWithRule< - biome_markdown_syntax::MdLinkBlock, - crate::markdown::auxiliary::link_block::FormatMdLinkBlock, - >; - fn into_format(self) -> Self::Format { - FormatOwnedWithRule::new( - self, - crate::markdown::auxiliary::link_block::FormatMdLinkBlock::default(), - ) - } -} impl FormatRule for crate::markdown::auxiliary::link_destination::FormatMdLinkDestination { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -777,7 +740,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdLinkDestination { +impl AsFormat for biome_markdown_syntax::MdLinkDestination { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdLinkDestination, @@ -790,7 +753,7 @@ impl AsFormat for biome_markdown_syntax::MdLinkDestination { ) } } -impl IntoFormat for biome_markdown_syntax::MdLinkDestination { +impl IntoFormat for biome_markdown_syntax::MdLinkDestination { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdLinkDestination, crate::markdown::auxiliary::link_destination::FormatMdLinkDestination, @@ -805,7 +768,7 @@ impl IntoFormat for biome_markdown_syntax::MdLinkDestination { impl FormatRule for crate::markdown::auxiliary::link_label::FormatMdLinkLabel { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -815,7 +778,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdLinkLabel { +impl AsFormat for biome_markdown_syntax::MdLinkLabel { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdLinkLabel, @@ -828,7 +791,7 @@ impl AsFormat for biome_markdown_syntax::MdLinkLabel { ) } } -impl IntoFormat for biome_markdown_syntax::MdLinkLabel { +impl IntoFormat for biome_markdown_syntax::MdLinkLabel { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdLinkLabel, crate::markdown::auxiliary::link_label::FormatMdLinkLabel, @@ -843,7 +806,7 @@ impl IntoFormat for biome_markdown_syntax::MdLinkLabel { impl FormatRule for crate::markdown::auxiliary::link_reference_definition::FormatMdLinkReferenceDefinition { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -853,7 +816,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdLinkReferenceDefinition { +impl AsFormat for biome_markdown_syntax::MdLinkReferenceDefinition { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdLinkReferenceDefinition, @@ -863,7 +826,7 @@ impl AsFormat for biome_markdown_syntax::MdLinkReferenceDefinit FormatRefWithRule :: new (self , crate :: markdown :: auxiliary :: link_reference_definition :: FormatMdLinkReferenceDefinition :: default ()) } } -impl IntoFormat for biome_markdown_syntax::MdLinkReferenceDefinition { +impl IntoFormat for biome_markdown_syntax::MdLinkReferenceDefinition { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdLinkReferenceDefinition, crate::markdown::auxiliary::link_reference_definition::FormatMdLinkReferenceDefinition, @@ -875,7 +838,7 @@ impl IntoFormat for biome_markdown_syntax::MdLinkReferenceDefin impl FormatRule for crate::markdown::auxiliary::link_title::FormatMdLinkTitle { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -885,7 +848,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdLinkTitle { +impl AsFormat for biome_markdown_syntax::MdLinkTitle { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdLinkTitle, @@ -898,7 +861,7 @@ impl AsFormat for biome_markdown_syntax::MdLinkTitle { ) } } -impl IntoFormat for biome_markdown_syntax::MdLinkTitle { +impl IntoFormat for biome_markdown_syntax::MdLinkTitle { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdLinkTitle, crate::markdown::auxiliary::link_title::FormatMdLinkTitle, @@ -913,7 +876,7 @@ impl IntoFormat for biome_markdown_syntax::MdLinkTitle { impl FormatRule for crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -923,7 +886,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdListMarkerPrefix { +impl AsFormat for biome_markdown_syntax::MdListMarkerPrefix { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdListMarkerPrefix, @@ -936,7 +899,7 @@ impl AsFormat for biome_markdown_syntax::MdListMarkerPrefix { ) } } -impl IntoFormat for biome_markdown_syntax::MdListMarkerPrefix { +impl IntoFormat for biome_markdown_syntax::MdListMarkerPrefix { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdListMarkerPrefix, crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix, @@ -951,7 +914,7 @@ impl IntoFormat for biome_markdown_syntax::MdListMarkerPrefix { impl FormatRule for crate::markdown::auxiliary::newline::FormatMdNewline { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -961,7 +924,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdNewline { +impl AsFormat for biome_markdown_syntax::MdNewline { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdNewline, @@ -974,7 +937,7 @@ impl AsFormat for biome_markdown_syntax::MdNewline { ) } } -impl IntoFormat for biome_markdown_syntax::MdNewline { +impl IntoFormat for biome_markdown_syntax::MdNewline { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdNewline, crate::markdown::auxiliary::newline::FormatMdNewline, @@ -989,7 +952,7 @@ impl IntoFormat for biome_markdown_syntax::MdNewline { impl FormatRule for crate::markdown::auxiliary::ordered_list_item::FormatMdOrderedListItem { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -999,7 +962,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdOrderedListItem { +impl AsFormat for biome_markdown_syntax::MdOrderedListItem { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdOrderedListItem, @@ -1012,7 +975,7 @@ impl AsFormat for biome_markdown_syntax::MdOrderedListItem { ) } } -impl IntoFormat for biome_markdown_syntax::MdOrderedListItem { +impl IntoFormat for biome_markdown_syntax::MdOrderedListItem { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdOrderedListItem, crate::markdown::auxiliary::ordered_list_item::FormatMdOrderedListItem, @@ -1027,7 +990,7 @@ impl IntoFormat for biome_markdown_syntax::MdOrderedListItem { impl FormatRule for crate::markdown::auxiliary::paragraph::FormatMdParagraph { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1037,7 +1000,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdParagraph { +impl AsFormat for biome_markdown_syntax::MdParagraph { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdParagraph, @@ -1050,7 +1013,7 @@ impl AsFormat for biome_markdown_syntax::MdParagraph { ) } } -impl IntoFormat for biome_markdown_syntax::MdParagraph { +impl IntoFormat for biome_markdown_syntax::MdParagraph { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdParagraph, crate::markdown::auxiliary::paragraph::FormatMdParagraph, @@ -1065,7 +1028,7 @@ impl IntoFormat for biome_markdown_syntax::MdParagraph { impl FormatRule for crate::markdown::auxiliary::quote::FormatMdQuote { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1075,7 +1038,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdQuote { +impl AsFormat for biome_markdown_syntax::MdQuote { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdQuote, @@ -1088,7 +1051,7 @@ impl AsFormat for biome_markdown_syntax::MdQuote { ) } } -impl IntoFormat for biome_markdown_syntax::MdQuote { +impl IntoFormat for biome_markdown_syntax::MdQuote { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdQuote, crate::markdown::auxiliary::quote::FormatMdQuote, @@ -1103,7 +1066,7 @@ impl IntoFormat for biome_markdown_syntax::MdQuote { impl FormatRule for crate::markdown::auxiliary::quote_indent::FormatMdQuoteIndent { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1113,7 +1076,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdQuoteIndent { +impl AsFormat for biome_markdown_syntax::MdQuoteIndent { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdQuoteIndent, @@ -1126,7 +1089,7 @@ impl AsFormat for biome_markdown_syntax::MdQuoteIndent { ) } } -impl IntoFormat for biome_markdown_syntax::MdQuoteIndent { +impl IntoFormat for biome_markdown_syntax::MdQuoteIndent { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdQuoteIndent, crate::markdown::auxiliary::quote_indent::FormatMdQuoteIndent, @@ -1141,7 +1104,7 @@ impl IntoFormat for biome_markdown_syntax::MdQuoteIndent { impl FormatRule for crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1151,7 +1114,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdQuotePrefix { +impl AsFormat for biome_markdown_syntax::MdQuotePrefix { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdQuotePrefix, @@ -1164,7 +1127,7 @@ impl AsFormat for biome_markdown_syntax::MdQuotePrefix { ) } } -impl IntoFormat for biome_markdown_syntax::MdQuotePrefix { +impl IntoFormat for biome_markdown_syntax::MdQuotePrefix { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdQuotePrefix, crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix, @@ -1179,7 +1142,7 @@ impl IntoFormat for biome_markdown_syntax::MdQuotePrefix { impl FormatRule for crate::markdown::auxiliary::reference_image::FormatMdReferenceImage { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1189,7 +1152,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdReferenceImage { +impl AsFormat for biome_markdown_syntax::MdReferenceImage { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdReferenceImage, @@ -1202,7 +1165,7 @@ impl AsFormat for biome_markdown_syntax::MdReferenceImage { ) } } -impl IntoFormat for biome_markdown_syntax::MdReferenceImage { +impl IntoFormat for biome_markdown_syntax::MdReferenceImage { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdReferenceImage, crate::markdown::auxiliary::reference_image::FormatMdReferenceImage, @@ -1217,7 +1180,7 @@ impl IntoFormat for biome_markdown_syntax::MdReferenceImage { impl FormatRule for crate::markdown::auxiliary::reference_link::FormatMdReferenceLink { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1227,7 +1190,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdReferenceLink { +impl AsFormat for biome_markdown_syntax::MdReferenceLink { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdReferenceLink, @@ -1240,7 +1203,7 @@ impl AsFormat for biome_markdown_syntax::MdReferenceLink { ) } } -impl IntoFormat for biome_markdown_syntax::MdReferenceLink { +impl IntoFormat for biome_markdown_syntax::MdReferenceLink { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdReferenceLink, crate::markdown::auxiliary::reference_link::FormatMdReferenceLink, @@ -1255,7 +1218,7 @@ impl IntoFormat for biome_markdown_syntax::MdReferenceLink { impl FormatRule for crate::markdown::auxiliary::reference_link_label::FormatMdReferenceLinkLabel { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1265,7 +1228,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdReferenceLinkLabel { +impl AsFormat for biome_markdown_syntax::MdReferenceLinkLabel { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdReferenceLinkLabel, @@ -1278,7 +1241,7 @@ impl AsFormat for biome_markdown_syntax::MdReferenceLinkLabel { ) } } -impl IntoFormat for biome_markdown_syntax::MdReferenceLinkLabel { +impl IntoFormat for biome_markdown_syntax::MdReferenceLinkLabel { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdReferenceLinkLabel, crate::markdown::auxiliary::reference_link_label::FormatMdReferenceLinkLabel, @@ -1293,7 +1256,7 @@ impl IntoFormat for biome_markdown_syntax::MdReferenceLinkLabel impl FormatRule for crate::markdown::auxiliary::setext_header::FormatMdSetextHeader { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1303,7 +1266,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdSetextHeader { +impl AsFormat for biome_markdown_syntax::MdSetextHeader { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdSetextHeader, @@ -1316,7 +1279,7 @@ impl AsFormat for biome_markdown_syntax::MdSetextHeader { ) } } -impl IntoFormat for biome_markdown_syntax::MdSetextHeader { +impl IntoFormat for biome_markdown_syntax::MdSetextHeader { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdSetextHeader, crate::markdown::auxiliary::setext_header::FormatMdSetextHeader, @@ -1331,7 +1294,7 @@ impl IntoFormat for biome_markdown_syntax::MdSetextHeader { impl FormatRule for crate::markdown::auxiliary::soft_break::FormatMdSoftBreak { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1341,7 +1304,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdSoftBreak { +impl AsFormat for biome_markdown_syntax::MdSoftBreak { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdSoftBreak, @@ -1354,7 +1317,7 @@ impl AsFormat for biome_markdown_syntax::MdSoftBreak { ) } } -impl IntoFormat for biome_markdown_syntax::MdSoftBreak { +impl IntoFormat for biome_markdown_syntax::MdSoftBreak { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdSoftBreak, crate::markdown::auxiliary::soft_break::FormatMdSoftBreak, @@ -1369,7 +1332,7 @@ impl IntoFormat for biome_markdown_syntax::MdSoftBreak { impl FormatRule for crate::markdown::auxiliary::textual::FormatMdTextual { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1379,7 +1342,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdTextual { +impl AsFormat for biome_markdown_syntax::MdTextual { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdTextual, @@ -1392,7 +1355,7 @@ impl AsFormat for biome_markdown_syntax::MdTextual { ) } } -impl IntoFormat for biome_markdown_syntax::MdTextual { +impl IntoFormat for biome_markdown_syntax::MdTextual { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdTextual, crate::markdown::auxiliary::textual::FormatMdTextual, @@ -1407,7 +1370,7 @@ impl IntoFormat for biome_markdown_syntax::MdTextual { impl FormatRule for crate::markdown::auxiliary::thematic_break_block::FormatMdThematicBreakBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1417,7 +1380,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdThematicBreakBlock { +impl AsFormat for biome_markdown_syntax::MdThematicBreakBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdThematicBreakBlock, @@ -1430,7 +1393,7 @@ impl AsFormat for biome_markdown_syntax::MdThematicBreakBlock { ) } } -impl IntoFormat for biome_markdown_syntax::MdThematicBreakBlock { +impl IntoFormat for biome_markdown_syntax::MdThematicBreakBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdThematicBreakBlock, crate::markdown::auxiliary::thematic_break_block::FormatMdThematicBreakBlock, @@ -1445,7 +1408,7 @@ impl IntoFormat for biome_markdown_syntax::MdThematicBreakBlock impl FormatRule for crate::markdown::auxiliary::thematic_break_char::FormatMdThematicBreakChar { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1455,7 +1418,7 @@ impl FormatRule FormatNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdThematicBreakChar { +impl AsFormat for biome_markdown_syntax::MdThematicBreakChar { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdThematicBreakChar, @@ -1468,7 +1431,7 @@ impl AsFormat for biome_markdown_syntax::MdThematicBreakChar { ) } } -impl IntoFormat for biome_markdown_syntax::MdThematicBreakChar { +impl IntoFormat for biome_markdown_syntax::MdThematicBreakChar { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdThematicBreakChar, crate::markdown::auxiliary::thematic_break_char::FormatMdThematicBreakChar, @@ -1480,57 +1443,7 @@ impl IntoFormat for biome_markdown_syntax::MdThematicBreakChar ) } } -impl AsFormat for biome_markdown_syntax::MdThematicBreakPartList { - type Format<'a> = FormatRefWithRule< - 'a, - biome_markdown_syntax::MdThematicBreakPartList, - crate::markdown::lists::thematic_break_part_list::FormatMdThematicBreakPartList, - >; - fn format(&self) -> Self::Format<'_> { - FormatRefWithRule::new( - self, - crate::markdown::lists::thematic_break_part_list::FormatMdThematicBreakPartList::default(), - ) - } -} -impl IntoFormat for biome_markdown_syntax::MdThematicBreakPartList { - type Format = FormatOwnedWithRule< - biome_markdown_syntax::MdThematicBreakPartList, - crate::markdown::lists::thematic_break_part_list::FormatMdThematicBreakPartList, - >; - fn into_format(self) -> Self::Format { - FormatOwnedWithRule::new( - self, - crate::markdown::lists::thematic_break_part_list::FormatMdThematicBreakPartList::default(), - ) - } -} -impl AsFormat for biome_markdown_syntax::AnyMdThematicBreakPart { - type Format<'a> = FormatRefWithRule< - 'a, - biome_markdown_syntax::AnyMdThematicBreakPart, - crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart, - >; - fn format(&self) -> Self::Format<'_> { - FormatRefWithRule::new( - self, - crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart::default(), - ) - } -} -impl IntoFormat for biome_markdown_syntax::AnyMdThematicBreakPart { - type Format = FormatOwnedWithRule< - biome_markdown_syntax::AnyMdThematicBreakPart, - crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart, - >; - fn into_format(self) -> Self::Format { - FormatOwnedWithRule::new( - self, - crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart::default(), - ) - } -} -impl AsFormat for biome_markdown_syntax::MdBlockList { +impl AsFormat for biome_markdown_syntax::MdBlockList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdBlockList, @@ -1543,7 +1456,7 @@ impl AsFormat for biome_markdown_syntax::MdBlockList { ) } } -impl IntoFormat for biome_markdown_syntax::MdBlockList { +impl IntoFormat for biome_markdown_syntax::MdBlockList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdBlockList, crate::markdown::lists::block_list::FormatMdBlockList, @@ -1555,7 +1468,7 @@ impl IntoFormat for biome_markdown_syntax::MdBlockList { ) } } -impl AsFormat for biome_markdown_syntax::MdBulletList { +impl AsFormat for biome_markdown_syntax::MdBulletList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdBulletList, @@ -1568,7 +1481,7 @@ impl AsFormat for biome_markdown_syntax::MdBulletList { ) } } -impl IntoFormat for biome_markdown_syntax::MdBulletList { +impl IntoFormat for biome_markdown_syntax::MdBulletList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdBulletList, crate::markdown::lists::bullet_list::FormatMdBulletList, @@ -1580,7 +1493,7 @@ impl IntoFormat for biome_markdown_syntax::MdBulletList { ) } } -impl AsFormat for biome_markdown_syntax::MdCodeNameList { +impl AsFormat for biome_markdown_syntax::MdCodeNameList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdCodeNameList, @@ -1593,7 +1506,7 @@ impl AsFormat for biome_markdown_syntax::MdCodeNameList { ) } } -impl IntoFormat for biome_markdown_syntax::MdCodeNameList { +impl IntoFormat for biome_markdown_syntax::MdCodeNameList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdCodeNameList, crate::markdown::lists::code_name_list::FormatMdCodeNameList, @@ -1605,7 +1518,7 @@ impl IntoFormat for biome_markdown_syntax::MdCodeNameList { ) } } -impl AsFormat for biome_markdown_syntax::MdHashList { +impl AsFormat for biome_markdown_syntax::MdHashList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdHashList, @@ -1618,7 +1531,7 @@ impl AsFormat for biome_markdown_syntax::MdHashList { ) } } -impl IntoFormat for biome_markdown_syntax::MdHashList { +impl IntoFormat for biome_markdown_syntax::MdHashList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdHashList, crate::markdown::lists::hash_list::FormatMdHashList, @@ -1630,7 +1543,7 @@ impl IntoFormat for biome_markdown_syntax::MdHashList { ) } } -impl AsFormat for biome_markdown_syntax::MdIndentTokenList { +impl AsFormat for biome_markdown_syntax::MdIndentTokenList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdIndentTokenList, @@ -1643,7 +1556,7 @@ impl AsFormat for biome_markdown_syntax::MdIndentTokenList { ) } } -impl IntoFormat for biome_markdown_syntax::MdIndentTokenList { +impl IntoFormat for biome_markdown_syntax::MdIndentTokenList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdIndentTokenList, crate::markdown::lists::indent_token_list::FormatMdIndentTokenList, @@ -1655,7 +1568,7 @@ impl IntoFormat for biome_markdown_syntax::MdIndentTokenList { ) } } -impl AsFormat for biome_markdown_syntax::MdInlineItemList { +impl AsFormat for biome_markdown_syntax::MdInlineItemList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdInlineItemList, @@ -1668,7 +1581,7 @@ impl AsFormat for biome_markdown_syntax::MdInlineItemList { ) } } -impl IntoFormat for biome_markdown_syntax::MdInlineItemList { +impl IntoFormat for biome_markdown_syntax::MdInlineItemList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdInlineItemList, crate::markdown::lists::inline_item_list::FormatMdInlineItemList, @@ -1680,7 +1593,7 @@ impl IntoFormat for biome_markdown_syntax::MdInlineItemList { ) } } -impl AsFormat for biome_markdown_syntax::MdQuoteIndentList { +impl AsFormat for biome_markdown_syntax::MdQuoteIndentList { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdQuoteIndentList, @@ -1693,7 +1606,7 @@ impl AsFormat for biome_markdown_syntax::MdQuoteIndentList { ) } } -impl IntoFormat for biome_markdown_syntax::MdQuoteIndentList { +impl IntoFormat for biome_markdown_syntax::MdQuoteIndentList { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdQuoteIndentList, crate::markdown::lists::quote_indent_list::FormatMdQuoteIndentList, @@ -1705,8 +1618,27 @@ impl IntoFormat for biome_markdown_syntax::MdQuoteIndentList { ) } } +impl AsFormat for biome_markdown_syntax::MdThematicBreakPartList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_markdown_syntax::MdThematicBreakPartList, + crate::markdown::lists::thematic_break_part_list::FormatMdThematicBreakPartList, + >; + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule :: new (self , crate :: markdown :: lists :: thematic_break_part_list :: FormatMdThematicBreakPartList :: default ()) + } +} +impl IntoFormat for biome_markdown_syntax::MdThematicBreakPartList { + type Format = FormatOwnedWithRule< + biome_markdown_syntax::MdThematicBreakPartList, + crate::markdown::lists::thematic_break_part_list::FormatMdThematicBreakPartList, + >; + fn into_format(self) -> Self::Format { + FormatOwnedWithRule :: new (self , crate :: markdown :: lists :: thematic_break_part_list :: FormatMdThematicBreakPartList :: default ()) + } +} impl FormatRule for crate::markdown::bogus::bogus::FormatMdBogus { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; #[inline(always)] fn fmt( &self, @@ -1716,7 +1648,7 @@ impl FormatRule for crate::markdown::bogus::bogu FormatBogusNodeRule::::fmt(self, node, f) } } -impl AsFormat for biome_markdown_syntax::MdBogus { +impl AsFormat for biome_markdown_syntax::MdBogus { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::MdBogus, @@ -1729,7 +1661,7 @@ impl AsFormat for biome_markdown_syntax::MdBogus { ) } } -impl IntoFormat for biome_markdown_syntax::MdBogus { +impl IntoFormat for biome_markdown_syntax::MdBogus { type Format = FormatOwnedWithRule< biome_markdown_syntax::MdBogus, crate::markdown::bogus::bogus::FormatMdBogus, @@ -1741,7 +1673,7 @@ impl IntoFormat for biome_markdown_syntax::MdBogus { ) } } -impl AsFormat for biome_markdown_syntax::AnyMdBlock { +impl AsFormat for biome_markdown_syntax::AnyMdBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::AnyMdBlock, @@ -1754,7 +1686,7 @@ impl AsFormat for biome_markdown_syntax::AnyMdBlock { ) } } -impl IntoFormat for biome_markdown_syntax::AnyMdBlock { +impl IntoFormat for biome_markdown_syntax::AnyMdBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::AnyMdBlock, crate::markdown::any::block::FormatAnyMdBlock, @@ -1766,7 +1698,7 @@ impl IntoFormat for biome_markdown_syntax::AnyMdBlock { ) } } -impl AsFormat for biome_markdown_syntax::AnyMdBulletListMember { +impl AsFormat for biome_markdown_syntax::AnyMdBulletListMember { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::AnyMdBulletListMember, @@ -1779,7 +1711,7 @@ impl AsFormat for biome_markdown_syntax::AnyMdBulletListMember ) } } -impl IntoFormat for biome_markdown_syntax::AnyMdBulletListMember { +impl IntoFormat for biome_markdown_syntax::AnyMdBulletListMember { type Format = FormatOwnedWithRule< biome_markdown_syntax::AnyMdBulletListMember, crate::markdown::any::bullet_list_member::FormatAnyMdBulletListMember, @@ -1791,7 +1723,7 @@ impl IntoFormat for biome_markdown_syntax::AnyMdBulletListMembe ) } } -impl AsFormat for biome_markdown_syntax::AnyMdCodeBlock { +impl AsFormat for biome_markdown_syntax::AnyMdCodeBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::AnyMdCodeBlock, @@ -1804,7 +1736,7 @@ impl AsFormat for biome_markdown_syntax::AnyMdCodeBlock { ) } } -impl IntoFormat for biome_markdown_syntax::AnyMdCodeBlock { +impl IntoFormat for biome_markdown_syntax::AnyMdCodeBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::AnyMdCodeBlock, crate::markdown::any::code_block::FormatAnyMdCodeBlock, @@ -1816,7 +1748,7 @@ impl IntoFormat for biome_markdown_syntax::AnyMdCodeBlock { ) } } -impl AsFormat for biome_markdown_syntax::AnyMdContainerBlock { +impl AsFormat for biome_markdown_syntax::AnyMdContainerBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::AnyMdContainerBlock, @@ -1829,7 +1761,7 @@ impl AsFormat for biome_markdown_syntax::AnyMdContainerBlock { ) } } -impl IntoFormat for biome_markdown_syntax::AnyMdContainerBlock { +impl IntoFormat for biome_markdown_syntax::AnyMdContainerBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::AnyMdContainerBlock, crate::markdown::any::container_block::FormatAnyMdContainerBlock, @@ -1841,7 +1773,7 @@ impl IntoFormat for biome_markdown_syntax::AnyMdContainerBlock ) } } -impl AsFormat for biome_markdown_syntax::AnyMdInline { +impl AsFormat for biome_markdown_syntax::AnyMdInline { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::AnyMdInline, @@ -1854,7 +1786,7 @@ impl AsFormat for biome_markdown_syntax::AnyMdInline { ) } } -impl IntoFormat for biome_markdown_syntax::AnyMdInline { +impl IntoFormat for biome_markdown_syntax::AnyMdInline { type Format = FormatOwnedWithRule< biome_markdown_syntax::AnyMdInline, crate::markdown::any::inline::FormatAnyMdInline, @@ -1866,7 +1798,7 @@ impl IntoFormat for biome_markdown_syntax::AnyMdInline { ) } } -impl AsFormat for biome_markdown_syntax::AnyMdLeafBlock { +impl AsFormat for biome_markdown_syntax::AnyMdLeafBlock { type Format<'a> = FormatRefWithRule< 'a, biome_markdown_syntax::AnyMdLeafBlock, @@ -1879,7 +1811,7 @@ impl AsFormat for biome_markdown_syntax::AnyMdLeafBlock { ) } } -impl IntoFormat for biome_markdown_syntax::AnyMdLeafBlock { +impl IntoFormat for biome_markdown_syntax::AnyMdLeafBlock { type Format = FormatOwnedWithRule< biome_markdown_syntax::AnyMdLeafBlock, crate::markdown::any::leaf_block::FormatAnyMdLeafBlock, @@ -1891,3 +1823,28 @@ impl IntoFormat for biome_markdown_syntax::AnyMdLeafBlock { ) } } +impl AsFormat for biome_markdown_syntax::AnyMdThematicBreakPart { + type Format<'a> = FormatRefWithRule< + 'a, + biome_markdown_syntax::AnyMdThematicBreakPart, + crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart, + >; + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new( + self, + crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart::default(), + ) + } +} +impl IntoFormat for biome_markdown_syntax::AnyMdThematicBreakPart { + type Format = FormatOwnedWithRule< + biome_markdown_syntax::AnyMdThematicBreakPart, + crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart, + >; + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new( + self, + crate::markdown::any::thematic_break_part::FormatAnyMdThematicBreakPart::default(), + ) + } +} diff --git a/crates/biome_markdown_formatter/src/lib.rs b/crates/biome_markdown_formatter/src/lib.rs index 627549de04b3..25a1ec099382 100644 --- a/crates/biome_markdown_formatter/src/lib.rs +++ b/crates/biome_markdown_formatter/src/lib.rs @@ -4,10 +4,11 @@ mod cst; mod generated; mod markdown; mod prelude; +mod shared; mod trivia; mod verbatim; -pub(crate) use crate::context::MdFormatContext; +pub(crate) use crate::context::MarkdownFormatContext; use crate::prelude::{format_bogus_node, format_suppressed_node}; pub(crate) use crate::trivia::*; use crate::{context::MdFormatOptions, cst::FormatMdSyntaxToken}; @@ -17,7 +18,7 @@ use biome_formatter::{ use biome_markdown_syntax::{MarkdownLanguage, MarkdownSyntaxNode}; use biome_rowan::AstNode; -pub(crate) type MarkdownFormatter<'buf> = Formatter<'buf, MdFormatContext>; +pub(crate) type MarkdownFormatter<'buf> = Formatter<'buf, MarkdownFormatContext>; #[derive(Debug, Clone, Default)] pub struct MdFormatLanguage { @@ -32,7 +33,7 @@ impl MdFormatLanguage { impl FormatLanguage for MdFormatLanguage { type SyntaxLanguage = MarkdownLanguage; - type Context = MdFormatContext; + type Context = MarkdownFormatContext; type FormatRule = FormatMdSyntaxToken; fn create_context( @@ -40,8 +41,8 @@ impl FormatLanguage for MdFormatLanguage { _root: &MarkdownSyntaxNode, source_map: Option, _delegate_fmt_embedded_nodes: bool, - ) -> MdFormatContext { - MdFormatContext::new(self.options.clone()).with_source_map(source_map) + ) -> MarkdownFormatContext { + MarkdownFormatContext::new(self.options.clone()).with_source_map(source_map) } fn options(&self) -> &::Options { @@ -253,6 +254,6 @@ where pub fn format_node( options: MdFormatOptions, root: &MarkdownSyntaxNode, -) -> FormatResult> { +) -> FormatResult> { biome_formatter::format_node(root, MdFormatLanguage::new(options), false) } diff --git a/crates/biome_markdown_formatter/src/markdown/any/block.rs b/crates/biome_markdown_formatter/src/markdown/any/block.rs index 31ac8a8c1cf0..f6644b6071d8 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/block.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/block.rs @@ -5,7 +5,7 @@ use biome_markdown_syntax::AnyMdBlock; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdBlock; impl FormatRule for FormatAnyMdBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdBlock, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdBlock::AnyMdContainerBlock(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/any/bullet_list_member.rs b/crates/biome_markdown_formatter/src/markdown/any/bullet_list_member.rs index 9cd40d67554d..a28a4c8c2493 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/bullet_list_member.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/bullet_list_member.rs @@ -5,7 +5,7 @@ use biome_markdown_syntax::AnyMdBulletListMember; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdBulletListMember; impl FormatRule for FormatAnyMdBulletListMember { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdBulletListMember, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdBulletListMember::MdBullet(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/any/code_block.rs b/crates/biome_markdown_formatter/src/markdown/any/code_block.rs index cb7b26afa20e..146af77c0f78 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/code_block.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/code_block.rs @@ -5,7 +5,7 @@ use biome_markdown_syntax::AnyMdCodeBlock; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdCodeBlock; impl FormatRule for FormatAnyMdCodeBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdCodeBlock, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdCodeBlock::MdFencedCodeBlock(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/any/container_block.rs b/crates/biome_markdown_formatter/src/markdown/any/container_block.rs index c086417c7332..3dbee461b927 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/container_block.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/container_block.rs @@ -5,7 +5,7 @@ use biome_markdown_syntax::AnyMdContainerBlock; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdContainerBlock; impl FormatRule for FormatAnyMdContainerBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdContainerBlock, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdContainerBlock::MdBulletListItem(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/any/inline.rs b/crates/biome_markdown_formatter/src/markdown/any/inline.rs index bc35c24fd9ec..6fb02427588b 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/inline.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/inline.rs @@ -5,7 +5,7 @@ use biome_markdown_syntax::AnyMdInline; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdInline; impl FormatRule for FormatAnyMdInline { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdInline, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdInline::MdAutolink(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/any/leaf_block.rs b/crates/biome_markdown_formatter/src/markdown/any/leaf_block.rs index 910b27b33520..fb40f900684b 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/leaf_block.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/leaf_block.rs @@ -5,13 +5,12 @@ use biome_markdown_syntax::AnyMdLeafBlock; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdLeafBlock; impl FormatRule for FormatAnyMdLeafBlock { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdLeafBlock, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdLeafBlock::AnyMdCodeBlock(node) => node.format().fmt(f), AnyMdLeafBlock::MdHeader(node) => node.format().fmt(f), AnyMdLeafBlock::MdHtmlBlock(node) => node.format().fmt(f), - AnyMdLeafBlock::MdLinkBlock(node) => node.format().fmt(f), AnyMdLeafBlock::MdLinkReferenceDefinition(node) => node.format().fmt(f), AnyMdLeafBlock::MdNewline(node) => node.format().fmt(f), AnyMdLeafBlock::MdParagraph(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/any/thematic_break_part.rs b/crates/biome_markdown_formatter/src/markdown/any/thematic_break_part.rs index 700a626bacb7..decb04ee4a15 100644 --- a/crates/biome_markdown_formatter/src/markdown/any/thematic_break_part.rs +++ b/crates/biome_markdown_formatter/src/markdown/any/thematic_break_part.rs @@ -1,9 +1,11 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + use crate::prelude::*; use biome_markdown_syntax::AnyMdThematicBreakPart; #[derive(Debug, Clone, Default)] pub(crate) struct FormatAnyMdThematicBreakPart; impl FormatRule for FormatAnyMdThematicBreakPart { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &AnyMdThematicBreakPart, f: &mut MarkdownFormatter) -> FormatResult<()> { match node { AnyMdThematicBreakPart::MdIndentToken(node) => node.format().fmt(f), diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/fenced_code_block.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/fenced_code_block.rs index af5df9ebb2a7..af3e9645dbea 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/fenced_code_block.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/fenced_code_block.rs @@ -1,10 +1,90 @@ +use crate::markdown::lists::inline_item_list::FormatMdFormatInlineItemListOptions; use crate::prelude::*; -use biome_markdown_syntax::MdFencedCodeBlock; -use biome_rowan::AstNode; +use crate::shared::TextPrintMode; +use biome_formatter::write; +use biome_markdown_syntax::{MdFencedCodeBlock, MdFencedCodeBlockFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdFencedCodeBlock; impl FormatNodeRule for FormatMdFencedCodeBlock { fn fmt_fields(&self, node: &MdFencedCodeBlock, f: &mut MarkdownFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let MdFencedCodeBlockFields { + l_fence, + r_fence, + r_fence_indent, + content, + code_list, + indent, + } = node.as_fields(); + + let l_fence = l_fence?; + let fence_text = l_fence.text(); + // SAFETY: fence_text has at least one character. + let fence_char = fence_text.as_bytes()[0] as char; + + // Compute the minimum fence length needed (CommonMark ยง4.5). + // The fence must be strictly longer than any same-character sequence + // in the content, otherwise the inner sequence would be parsed as a + // closing fence. E.g. if the content contains ``` (3 backticks), + // the outer fence needs at least 4. + let max_inner = longest_fence_char_sequence(node, fence_char); + let fence_len = (max_inner + 1).max(3); + let normalized_fence: String = std::iter::repeat_n(fence_char, fence_len).collect(); + + write!( + f, + [ + indent.format(), + format_replaced( + &l_fence, + &text(&normalized_fence, l_fence.text_trimmed_range().start()) + ), + code_list.format(), + hard_line_break(), + content + .format() + .with_options(FormatMdFormatInlineItemListOptions { + print_mode: TextPrintMode::Clean + }), + hard_line_break(), + r_fence_indent.format(), + ] + )?; + + if let Ok(r_fence) = r_fence { + write!( + f, + [format_replaced( + &r_fence, + &text(&normalized_fence, r_fence.text_trimmed_range().start()) + )] + )?; + } + + Ok(()) } } + +/// Find the longest consecutive run of `fence_char` in the code block's content. +fn longest_fence_char_sequence(node: &MdFencedCodeBlock, fence_char: char) -> usize { + let content = node.content(); + let mut max_len = 0usize; + + for item in content.iter() { + if let Some(textual) = item.as_md_textual() + && let Ok(token) = textual.value_token() + { + let mut consecutive_count = 0usize; + for ch in token.text().chars() { + if ch == fence_char { + consecutive_count += 1; + max_len = max_len.max(consecutive_count); + } else { + consecutive_count = 0; + } + } + } + } + + max_len +} diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/hard_line.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/hard_line.rs index f92ea9eb1c71..5841f6981402 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/hard_line.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/hard_line.rs @@ -1,11 +1,20 @@ use crate::prelude::*; -use biome_formatter::write; +use crate::shared::TextPrintMode; +use biome_formatter::{FormatRuleWithOptions, write}; use biome_markdown_syntax::MdHardLine; + #[derive(Debug, Clone, Default)] -pub(crate) struct FormatMdHardLine; +pub(crate) struct FormatMdHardLine { + print_mode: TextPrintMode, +} impl FormatNodeRule for FormatMdHardLine { fn fmt_fields(&self, node: &MdHardLine, f: &mut MarkdownFormatter) -> FormatResult<()> { let token = node.value_token()?; + + if self.print_mode.is_pristine() { + return format_verbatim_node(node.syntax()).fmt(f); + } + let text_content = token.text(); if text_content.trim_end().ends_with('\\') { @@ -33,3 +42,16 @@ impl FormatNodeRule for FormatMdHardLine { } } } + +pub(crate) struct FormatMdFormatHardLineOptions { + pub(crate) print_mode: TextPrintMode, +} + +impl FormatRuleWithOptions for FormatMdHardLine { + type Options = FormatMdFormatHardLineOptions; + + fn with_options(mut self, options: Self::Options) -> Self { + self.print_mode = options.print_mode; + self + } +} diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/header.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/header.rs index 5871988e1d34..0347f50d96aa 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/header.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/header.rs @@ -1,5 +1,6 @@ use crate::markdown::auxiliary::paragraph::FormatMdParagraphOptions; use crate::prelude::*; +use crate::shared::{TextPrintMode, TrimMode}; use crate::verbatim::format_verbatim_node; use biome_formatter::write; use biome_markdown_syntax::{MdHeader, MdHeaderFields}; @@ -24,9 +25,9 @@ impl FormatNodeRule for FormatMdHeader { f, [ space(), - content - .format() - .with_options(FormatMdParagraphOptions { trim_start: true }) + content.format().with_options(FormatMdParagraphOptions { + trim_mode: TextPrintMode::Trim(TrimMode::Start) + }) ] )?; } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_link.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_link.rs index ce789c445871..0281290574f4 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_link.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/inline_link.rs @@ -1,10 +1,44 @@ +use crate::markdown::lists::inline_item_list::FormatMdFormatInlineItemListOptions; use crate::prelude::*; -use biome_markdown_syntax::MdInlineLink; -use biome_rowan::AstNode; +use crate::shared::{TextPrintMode, TrimMode}; +use biome_formatter::write; +use biome_markdown_syntax::{MdInlineLink, MdInlineLinkFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdInlineLink; impl FormatNodeRule for FormatMdInlineLink { fn fmt_fields(&self, node: &MdInlineLink, f: &mut MarkdownFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let MdInlineLinkFields { + title, + text, + destination, + r_brack_token, + r_paren_token, + l_brack_token, + l_paren_token, + } = node.as_fields(); + + write!( + f, + [ + l_brack_token.format(), + text.format() + .with_options(FormatMdFormatInlineItemListOptions { + print_mode: TextPrintMode::Trim(TrimMode::All) + }), + r_brack_token.format(), + l_paren_token.format(), + destination + .format() + .with_options(FormatMdFormatInlineItemListOptions { + print_mode: TextPrintMode::Trim(TrimMode::All) + }) + ] + )?; + if let Some(title) = title { + write!(f, [space(), title.format()])?; + } + + write!(f, [r_paren_token.format()]) } } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/link_block.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/link_block.rs deleted file mode 100644 index a16ddcfb187d..000000000000 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/link_block.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::prelude::*; -use biome_markdown_syntax::MdLinkBlock; -use biome_rowan::AstNode; -#[derive(Debug, Clone, Default)] -pub(crate) struct FormatMdLinkBlock; -impl FormatNodeRule for FormatMdLinkBlock { - fn fmt_fields(&self, node: &MdLinkBlock, f: &mut MarkdownFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) - } -} diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/link_title.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/link_title.rs index 326eb7e9b46d..e1d6da8226c8 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/link_title.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/link_title.rs @@ -1,10 +1,22 @@ +use crate::markdown::lists::inline_item_list::FormatMdFormatInlineItemListOptions; use crate::prelude::*; -use biome_markdown_syntax::MdLinkTitle; -use biome_rowan::AstNode; +use crate::shared::{TextPrintMode, TrimMode}; +use biome_formatter::write; +use biome_markdown_syntax::{MdLinkTitle, MdLinkTitleFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdLinkTitle; impl FormatNodeRule for FormatMdLinkTitle { fn fmt_fields(&self, node: &MdLinkTitle, f: &mut MarkdownFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let MdLinkTitleFields { content } = node.as_fields(); + + write!( + f, + [content + .format() + .with_options(FormatMdFormatInlineItemListOptions { + print_mode: TextPrintMode::Trim(TrimMode::None) + })] + ) } } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/mod.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/mod.rs index ed2f199bfca4..939f61af9253 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/mod.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/mod.rs @@ -19,7 +19,6 @@ pub(crate) mod inline_html; pub(crate) mod inline_image; pub(crate) mod inline_italic; pub(crate) mod inline_link; -pub(crate) mod link_block; pub(crate) mod link_destination; pub(crate) mod link_label; pub(crate) mod link_reference_definition; diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/paragraph.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/paragraph.rs index 2dba54f6c099..e0331089a7ca 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/paragraph.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/paragraph.rs @@ -1,11 +1,20 @@ use crate::markdown::lists::inline_item_list::FormatMdFormatInlineItemListOptions; use crate::prelude::*; +use crate::shared::{TextPrintMode, TrimMode}; use biome_formatter::{FormatRuleWithOptions, write}; use biome_markdown_syntax::{MdParagraph, MdParagraphFields}; -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub(crate) struct FormatMdParagraph { - trim_start: bool, + trim_mode: TextPrintMode, +} + +impl Default for FormatMdParagraph { + fn default() -> Self { + Self { + trim_mode: TextPrintMode::Trim(TrimMode::None), + } + } } impl FormatNodeRule for FormatMdParagraph { fn fmt_fields(&self, node: &MdParagraph, f: &mut MarkdownFormatter) -> FormatResult<()> { @@ -15,7 +24,7 @@ impl FormatNodeRule for FormatMdParagraph { [list .format() .with_options(FormatMdFormatInlineItemListOptions { - trime_start: self.trim_start + print_mode: self.trim_mode })] )?; if let Some(hard_line) = hard_line { @@ -27,14 +36,14 @@ impl FormatNodeRule for FormatMdParagraph { pub(crate) struct FormatMdParagraphOptions { /// Whether to trim the start of the paragraph. Usually signaled by the headers - pub trim_start: bool, + pub trim_mode: TextPrintMode, } impl FormatRuleWithOptions for FormatMdParagraph { type Options = FormatMdParagraphOptions; fn with_options(mut self, options: Self::Options) -> Self { - self.trim_start = options.trim_start; + self.trim_mode = options.trim_mode; self } } diff --git a/crates/biome_markdown_formatter/src/markdown/auxiliary/textual.rs b/crates/biome_markdown_formatter/src/markdown/auxiliary/textual.rs index e12ecd5aa5d7..df1c9a82bb8c 100644 --- a/crates/biome_markdown_formatter/src/markdown/auxiliary/textual.rs +++ b/crates/biome_markdown_formatter/src/markdown/auxiliary/textual.rs @@ -1,11 +1,13 @@ use crate::prelude::*; +use crate::shared::TextPrintMode; use biome_formatter::{FormatRuleWithOptions, write}; use biome_markdown_syntax::{MdTextual, MdTextualFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdTextual { should_remove: bool, - trime_start: bool, + trim_start: bool, + print_mode: TextPrintMode, } impl FormatNodeRule for FormatMdTextual { fn fmt_fields(&self, node: &MdTextual, f: &mut MarkdownFormatter) -> FormatResult<()> { @@ -15,7 +17,25 @@ impl FormatNodeRule for FormatMdTextual { if self.should_remove { format_removed(&value_token).fmt(f) - } else if self.trime_start { + } else if self.print_mode.is_clean() { + // Clean mode: strip spaces/tabs but preserve newlines. + // Used for code block content where trailing whitespace on empty + // lines should be removed but newlines must be kept. + let cleaned = value_token + .text() + .trim_matches(|c: char| c == ' ' || c == '\t'); + if cleaned == value_token.text() { + write!(f, [value_token.format()]) + } else { + write!( + f, + [format_replaced( + &value_token, + &text(cleaned, value_token.text_trimmed_range().start()) + )] + ) + } + } else if self.trim_start { let trimmed_text = value_token.text().trim_start(); write!( f, @@ -33,7 +53,8 @@ impl FormatNodeRule for FormatMdTextual { #[derive(Debug, Clone, Copy, Default)] pub(crate) struct FormatMdTextualOptions { pub(crate) should_remove: bool, - pub(crate) trime_start: bool, + pub(crate) trim_start: bool, + pub(crate) print_mode: TextPrintMode, } impl FormatRuleWithOptions for FormatMdTextual { @@ -41,7 +62,8 @@ impl FormatRuleWithOptions for FormatMdTextual { fn with_options(mut self, options: Self::Options) -> Self { self.should_remove = options.should_remove; - self.trime_start = options.trime_start; + self.trim_start = options.trim_start; + self.print_mode = options.print_mode; self } } 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 94f1b1a5ac9d..cf1efe186e84 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/block_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/block_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdBlockList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdBlockList; impl FormatRule for FormatMdBlockList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdBlockList, f: &mut MarkdownFormatter) -> FormatResult<()> { f.join().entries(node.iter().formatted()).finish() } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/bullet_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/bullet_list.rs index 68b2fa57ec71..c7d658290141 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/bullet_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/bullet_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdBulletList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdBulletList; impl FormatRule for FormatMdBulletList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdBulletList, f: &mut MarkdownFormatter) -> FormatResult<()> { f.join().entries(node.iter().formatted()).finish() } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/code_name_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/code_name_list.rs index 3923d1f35a72..b7a76f9ef83a 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/code_name_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/code_name_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdCodeNameList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdCodeNameList; impl FormatRule for FormatMdCodeNameList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdCodeNameList, f: &mut MarkdownFormatter) -> FormatResult<()> { format_verbatim_node(node.syntax()).fmt(f) } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/hash_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/hash_list.rs index e70a04529657..1c1977386f74 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/hash_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/hash_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdHashList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdHashList; impl FormatRule for FormatMdHashList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdHashList, f: &mut MarkdownFormatter) -> FormatResult<()> { f.join().entries(node.iter().formatted()).finish() } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/indent_token_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/indent_token_list.rs index 0ad3d749d848..6bdbaeb3f1e8 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/indent_token_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/indent_token_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdIndentTokenList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdIndentTokenList; impl FormatRule for FormatMdIndentTokenList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdIndentTokenList, f: &mut MarkdownFormatter) -> FormatResult<()> { f.join().entries(node.iter().formatted()).finish() } 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 ac095d3896de..23b18c06a51b 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 @@ -1,28 +1,40 @@ +use crate::markdown::auxiliary::hard_line::FormatMdFormatHardLineOptions; use crate::markdown::auxiliary::textual::FormatMdTextualOptions; use crate::prelude::*; +use crate::shared::{TextPrintMode, TrimMode}; use biome_formatter::{FormatRuleWithOptions, write}; use biome_markdown_syntax::{AnyMdInline, MdInlineItemList}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdInlineItemList { - trime_start: bool, + print_mode: TextPrintMode, } + impl FormatRule for FormatMdInlineItemList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdInlineItemList, f: &mut MarkdownFormatter) -> FormatResult<()> { + if self.print_mode.is_all() { + return self.fmt_trim_all(node, f); + } else if self.print_mode.is_pristine() { + return self.fmt_pristine(node, f); + } else if self.print_mode.is_clean() { + return self.fmt_clean(node, f); + } + let mut joiner = f.join(); let mut seen_new_line = false; for (index, item) in node.iter().enumerate() { match item { AnyMdInline::MdTextual(text) => { - if text.is_empty()? && seen_new_line { + if text.is_empty_and_not_newline()? && seen_new_line { let entry = format_with(|f| { write!( f, [text.format().with_options(FormatMdTextualOptions { should_remove: true, - trime_start: false + trim_start: false, + ..Default::default() })] ) }); @@ -34,7 +46,8 @@ impl FormatRule for FormatMdInlineItemList { [ text.format().with_options(FormatMdTextualOptions { should_remove: true, - trime_start: false + trim_start: false, + ..Default::default() }), hard_line_break() ] @@ -45,14 +58,24 @@ impl FormatRule for FormatMdInlineItemList { } else { joiner.entry(&text.format().with_options(FormatMdTextualOptions { should_remove: false, - trime_start: self.trime_start && index == 0, + trim_start: self.print_mode.is_start() && index == 0, + ..Default::default() })); } } AnyMdInline::MdHardLine(hard_line) => { seen_new_line = true; - joiner.entry(&format_with(|f| write!(f, [hard_line.format()]))); + joiner.entry(&format_with(|f| { + write!( + f, + [hard_line + .format() + .with_options(FormatMdFormatHardLineOptions { + print_mode: self.print_mode, + })] + ) + })); } _ => { joiner.entry(&item.format()); @@ -65,15 +88,144 @@ impl FormatRule for FormatMdInlineItemList { } } +impl FormatMdInlineItemList { + /// 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. + fn fmt_trim_all(&self, node: &MdInlineItemList, f: &mut MarkdownFormatter) -> FormatResult<()> { + let items: Vec<_> = node.iter().collect(); + let mut joiner = f.join(); + + let is_content = |item: &AnyMdInline| match item { + AnyMdInline::MdTextual(text) => !text.is_empty().unwrap_or_default(), + AnyMdInline::MdHardLine(_) => false, + _ => true, + }; + + // Find the first non-empty item from the left. + let first_content = items.iter().position(&is_content); + + // Find the first non-empty item from the right. + let last_content = items + .iter() + .rev() + .position(is_content) + .map(|pos| items.len() - 1 - pos); + + for (index, item) in items.iter().enumerate() { + let is_before_content = first_content.is_none_or(|first| index < first); + let is_after_content = last_content.is_none_or(|last| index > last); + + if is_before_content || is_after_content { + // Outside content boundaries: remove empty nodes. + match item { + AnyMdInline::MdTextual(text) => { + joiner.entry(&text.format().with_options(FormatMdTextualOptions { + should_remove: true, + trim_start: true, + ..Default::default() + })); + } + AnyMdInline::MdHardLine(hard_line) => { + joiner.entry(&hard_line.format().with_options( + FormatMdFormatHardLineOptions { + print_mode: TextPrintMode::Trim(TrimMode::All), + }, + )); + } + _ => { + joiner.entry(&item.format()); + } + } + } else { + // Inside content boundaries: keep as-is. + joiner.entry(&item.format()); + } + } + + joiner.finish() + } + + /// Clean mode: formats content verbatim, but removes the first + /// whitespace-only textual token. + fn fmt_clean(&self, node: &MdInlineItemList, f: &mut MarkdownFormatter) -> FormatResult<()> { + let mut joiner = f.join(); + let mut handled_first = false; + + for item in node.iter() { + match item { + AnyMdInline::MdTextual(text) if !handled_first => { + handled_first = true; + if text.is_empty_and_not_newline().unwrap_or(false) + || text.is_newline().unwrap_or(false) + { + // First token is trailing whitespace/newline from the + // info string line โ€” remove it entirely. + joiner.entry(&text.format().with_options(FormatMdTextualOptions { + should_remove: true, + ..Default::default() + })); + } else { + let token = text.value_token()?; + let token_text = token.text(); + if token_text.trim().is_empty() { + // Mixed whitespace + newline (e.g. " \n") โ€” remove. + joiner.entry(&text.format().with_options(FormatMdTextualOptions { + should_remove: true, + ..Default::default() + })); + } else { + // First token has content โ€” keep as-is. + joiner.entry(&text.format()); + } + } + } + AnyMdInline::MdHardLine(hd) => { + joiner.entry(&hd.format().with_options(FormatMdFormatHardLineOptions { + print_mode: TextPrintMode::Pristine, + })); + } + node => { + joiner.entry(&node.format()); + } + } + } + + joiner.finish() + } + + /// Formats all items verbatim, preserving the original text exactly. + /// Hard lines are explicitly set to pristine mode to prevent + /// normalization (e.g. collapsing multiple trailing spaces to two). + fn fmt_pristine(&self, node: &MdInlineItemList, f: &mut MarkdownFormatter) -> FormatResult<()> { + let mut joiner = f.join(); + + for item in node.iter() { + match item { + AnyMdInline::MdHardLine(hd) => { + joiner.entry(&hd.format().with_options(FormatMdFormatHardLineOptions { + print_mode: TextPrintMode::Pristine, + })); + } + node => { + joiner.entry(&node.format()); + } + } + } + + joiner.finish() + } +} + pub(crate) struct FormatMdFormatInlineItemListOptions { - pub(crate) trime_start: bool, + pub(crate) print_mode: TextPrintMode, } impl FormatRuleWithOptions for FormatMdInlineItemList { type Options = FormatMdFormatInlineItemListOptions; fn with_options(mut self, options: Self::Options) -> Self { - self.trime_start = options.trime_start; + self.print_mode = options.print_mode; self } } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/quote_indent_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/quote_indent_list.rs index 56ff0f373c22..2099db44da6c 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/quote_indent_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/quote_indent_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdQuoteIndentList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdQuoteIndentList; impl FormatRule for FormatMdQuoteIndentList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdQuoteIndentList, f: &mut MarkdownFormatter) -> FormatResult<()> { f.join().entries(node.iter().formatted()).finish() } diff --git a/crates/biome_markdown_formatter/src/markdown/lists/thematic_break_part_list.rs b/crates/biome_markdown_formatter/src/markdown/lists/thematic_break_part_list.rs index 343674877f42..c41dc7a38f6c 100644 --- a/crates/biome_markdown_formatter/src/markdown/lists/thematic_break_part_list.rs +++ b/crates/biome_markdown_formatter/src/markdown/lists/thematic_break_part_list.rs @@ -3,7 +3,7 @@ use biome_markdown_syntax::MdThematicBreakPartList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatMdThematicBreakPartList; impl FormatRule for FormatMdThematicBreakPartList { - type Context = MdFormatContext; + type Context = MarkdownFormatContext; fn fmt(&self, node: &MdThematicBreakPartList, f: &mut MarkdownFormatter) -> FormatResult<()> { f.join().entries(node.iter().formatted()).finish() } diff --git a/crates/biome_markdown_formatter/src/prelude.rs b/crates/biome_markdown_formatter/src/prelude.rs index 75e49d414a78..1f3f80379cca 100644 --- a/crates/biome_markdown_formatter/src/prelude.rs +++ b/crates/biome_markdown_formatter/src/prelude.rs @@ -4,7 +4,7 @@ pub(crate) use crate::{ AsFormat, FormatNodeRule, FormattedIterExt as _, FormattedIterExt, IntoFormat, - MarkdownFormatter, MdFormatContext, format_removed, format_replaced, verbatim::*, + MarkdownFormatContext, MarkdownFormatter, format_removed, format_replaced, verbatim::*, }; pub(crate) use biome_formatter::prelude::*; pub(crate) use biome_rowan::{ diff --git a/crates/biome_markdown_formatter/src/shared.rs b/crates/biome_markdown_formatter/src/shared.rs new file mode 100644 index 000000000000..410893816510 --- /dev/null +++ b/crates/biome_markdown_formatter/src/shared.rs @@ -0,0 +1,59 @@ +#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)] +pub(crate) enum TextPrintMode { + /// Keep the original formatting. Don't attempt to optimize it. This is usually achieved + /// by formatting the code as verbatim. + #[default] + Pristine, + /// Usually used inside code blocks. It keeps the original formatting of the content, + /// but it removes possible spaces if there's empty hard line. + /// + /// In the following example, the first line will keep only the newline, as there are only spaces + /// ``````md + /// ``` + /// + /// ``` + /// `````` + /// However, in the following example, spaces are keep as is because there's text (code): + /// + /// ``````md + /// ```js + /// function f() {} + /// ``` + /// `````` + Clean, + /// It removes the token/node + _Remove, + /// Replace the token/node + _Replace, + /// It cleans the code by using a trimming strategy + Trim(TrimMode), +} + +#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)] +pub(crate) enum TrimMode { + /// Trim the start of the list + Start, + /// Trim start and end of the list + All, + /// Don't trim anything + #[default] + None, +} + +impl TextPrintMode { + pub(crate) const fn is_start(&self) -> bool { + matches!(self, Self::Trim(TrimMode::Start)) + } + + pub(crate) const fn is_all(&self) -> bool { + matches!(self, Self::Trim(TrimMode::All)) + } + + pub(crate) const fn is_pristine(&self) -> bool { + matches!(self, Self::Pristine) + } + + pub(crate) const fn is_clean(&self) -> bool { + matches!(self, Self::Clean) + } +} diff --git a/crates/biome_markdown_formatter/src/trivia.rs b/crates/biome_markdown_formatter/src/trivia.rs index bea791c50298..b71ecae38110 100644 --- a/crates/biome_markdown_formatter/src/trivia.rs +++ b/crates/biome_markdown_formatter/src/trivia.rs @@ -1,4 +1,4 @@ -use crate::MdFormatContext; +use crate::MarkdownFormatContext; use crate::cst::FormatMdSyntaxToken; use biome_formatter::formatter::Formatter; use biome_formatter::trivia::FormatToken; @@ -13,20 +13,20 @@ pub(crate) fn format_removed(token: &MarkdownSyntaxToken) -> FormatRemoved<'_> { FormatRemoved { token } } -impl<'a> Format for FormatRemoved<'a> { - fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { +impl<'a> Format for FormatRemoved<'a> { + fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { FormatMdSyntaxToken.format_removed(self.token, f) } } pub(crate) struct FormatReplaced<'a> { token: &'a MarkdownSyntaxToken, - content: Argument<'a, MdFormatContext>, + content: Argument<'a, MarkdownFormatContext>, } pub(crate) fn format_replaced<'a>( token: &'a MarkdownSyntaxToken, - content: &'a impl Format, + content: &'a impl Format, ) -> FormatReplaced<'a> { FormatReplaced { token, @@ -34,8 +34,8 @@ pub(crate) fn format_replaced<'a>( } } -impl<'a> Format for FormatReplaced<'a> { - fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { +impl<'a> Format for FormatReplaced<'a> { + fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { FormatMdSyntaxToken.format_replaced(self.token, &self.content, f) } } diff --git a/crates/biome_markdown_formatter/src/verbatim.rs b/crates/biome_markdown_formatter/src/verbatim.rs index eaf0aa07e813..7c2cc0ea6b36 100644 --- a/crates/biome_markdown_formatter/src/verbatim.rs +++ b/crates/biome_markdown_formatter/src/verbatim.rs @@ -1,4 +1,4 @@ -use crate::MdFormatContext; +use crate::MarkdownFormatContext; use biome_formatter::{ Buffer, Format, FormatResult, prelude::{Formatter, text}, @@ -19,8 +19,8 @@ pub struct FormatMarkdownVerbatimNode<'node> { node: &'node MarkdownSyntaxNode, } -impl Format for FormatMarkdownVerbatimNode<'_> { - fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { +impl Format for FormatMarkdownVerbatimNode<'_> { + fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { // Track all tokens in the node so the formatter knows they've been seen for element in self.node.descendants_with_tokens(Direction::Next) { match element { diff --git a/crates/biome_markdown_formatter/tests/language.rs b/crates/biome_markdown_formatter/tests/language.rs index 01949fb1810a..4b6208343ee9 100644 --- a/crates/biome_markdown_formatter/tests/language.rs +++ b/crates/biome_markdown_formatter/tests/language.rs @@ -1,6 +1,6 @@ use biome_formatter_test::TestFormatLanguage; use biome_fs::BiomePath; -use biome_markdown_formatter::{MdFormatLanguage, context::MdFormatContext}; +use biome_markdown_formatter::{MdFormatLanguage, context::MarkdownFormatContext}; use biome_markdown_parser::parse_markdown; use biome_markdown_syntax::MarkdownLanguage; use biome_parser::AnyParse; @@ -14,7 +14,7 @@ pub struct MarkdownTestFormatLanguage {} impl TestFormatLanguage for MarkdownTestFormatLanguage { type ServiceLanguage = MarkdownLanguage; - type Context = MdFormatContext; + type Context = MarkdownFormatContext; type FormatLanguage = MdFormatLanguage; fn parse(&self, text: &str) -> AnyParse { diff --git a/crates/biome_markdown_formatter/tests/quick_test.rs b/crates/biome_markdown_formatter/tests/quick_test.rs index 6e8339c26674..6143d14201d0 100644 --- a/crates/biome_markdown_formatter/tests/quick_test.rs +++ b/crates/biome_markdown_formatter/tests/quick_test.rs @@ -4,12 +4,19 @@ use biome_markdown_parser::parse_markdown; #[ignore] #[test] fn quick_test() { - let source = r#"# h1 -"#; + let source = r#"`````````` + +```js +console.log("hello world!"); +``` + +``````````"#; let parse = parse_markdown(source); // Print CST eprintln!("{:#?}", parse.syntax()); + // print red tree + eprintln!("{:#?}", parse.tree()); let options = MdFormatOptions::default(); let result = diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block.md b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block.md new file mode 100644 index 000000000000..56cceb39f553 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block.md @@ -0,0 +1,16 @@ +`````````` + +```js +console.log("hello world!"); +``` + +`````````` + +~~~~~~~~~~~ + +~~~python +def hello(): + pass +~~~ + +~~~~~~~~~~~ diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block.md.snap new file mode 100644 index 000000000000..f9e4c5635617 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block.md.snap @@ -0,0 +1,49 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: markdown/fenced_code_block.md +--- + +# Input + +```md +`````````` + +```js +console.log("hello world!"); +``` + +`````````` + +~~~~~~~~~~~ + +~~~python +def hello(): + pass +~~~ + +~~~~~~~~~~~ + +``` + + +# Formatted + +```md +```` + +```js +console.log("hello world!"); +``` + +```` + +~~~~ + +~~~python +def hello(): + pass +~~~ + +~~~~ + +``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block_info_string.md b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block_info_string.md new file mode 100644 index 000000000000..b2e31f951f76 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block_info_string.md @@ -0,0 +1,11 @@ +```js +console.log("hello"); +``` + +``` +some code +``` + +```rust + fn main() {} +``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block_info_string.md.snap b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block_info_string.md.snap new file mode 100644 index 000000000000..2e73646ba084 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/fenced_code_block_info_string.md.snap @@ -0,0 +1,39 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: markdown/fenced_code_block_info_string.md +--- + +# Input + +```md +```js +console.log("hello"); +``` + +``` +some code +``` + +```rust + fn main() {} +``` + +``` + + +# Formatted + +```md +```js +console.log("hello"); +``` + +``` +some code +``` + +```rust + fn main() {} +``` + +``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md b/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md new file mode 100644 index 000000000000..ffbad94e0c83 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md @@ -0,0 +1,8 @@ +foo +baz + +backslash\ +form + +no hard line +here 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 new file mode 100644 index 000000000000..a5466203b521 --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/hard_line.md.snap @@ -0,0 +1,33 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: markdown/hard_line.md +--- + +# Input + +```md +foo +baz + +backslash\ +form + +no hard line +here + +``` + + +# Formatted + +```md +foo +baz + +backslash\ +form + +no hard line +here + +``` diff --git a/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md new file mode 100644 index 000000000000..8424594d2c9e --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md @@ -0,0 +1,11 @@ +[hello](#world) + +[ spaced ](#link) + +[link](https://example.com "title") + +[link](https://example.com " spaced title ") + +text with [inline](link) in the middle + +[link with **bold**](url) 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 new file mode 100644 index 000000000000..7312ad59c2ec --- /dev/null +++ b/crates/biome_markdown_formatter/tests/specs/markdown/inline_links.md.snap @@ -0,0 +1,39 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: markdown/inline_links.md +--- + +# Input + +```md +[hello](#world) + +[ spaced ](#link) + +[link](https://example.com "title") + +[link](https://example.com " spaced title ") + +text with [inline](link) in the middle + +[link with **bold**](url) + +``` + + +# Formatted + +```md +[hello](#world) + +[ spaced ](#link) + +[link](https://example.com "title") + +[link](https://example.com " spaced title ") + +text with [inline](link) in the middle + +[link with **bold**](url) + +``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/broken-plugins/missing-comments.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/broken-plugins/missing-comments.md.snap deleted file mode 100644 index d6e674868129..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/broken-plugins/missing-comments.md.snap +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/broken-plugins/missing-comments.md ---- - -# Input - -```md -``````missing-comments - This should not be replaced. -`````` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,3 @@ --```missing-comments -+``````missing-comments - This should not be replaced. --``` -+`````` -``` - -# Output - -```md -``````missing-comments - This should not be replaced. -`````` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/backtick.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/backtick.md.snap deleted file mode 100644 index fb7fd3b5d44f..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/code/backtick.md.snap +++ /dev/null @@ -1,47 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/code/backtick.md ---- - -# Input - -```md -`````````` - -```js -console.log("hello world!"); -``` - -`````````` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,7 +1,7 @@ --```` -+`````````` - - ```js - console.log("hello world!"); - ``` - --```` -+`````````` -``` - -# Output - -```md -`````````` - -```js -console.log("hello world!"); -``` - -`````````` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-js/meta-in-code-block.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-js/meta-in-code-block.md.snap index 036bcc5e97ad..f8b1c62f329e 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-js/meta-in-code-block.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/multiparser-js/meta-in-code-block.md.snap @@ -38,14 +38,6 @@ console.log ( "hello world" ); ```diff --- Prettier +++ Biome -@@ -1,6 +1,6 @@ - ## plain js block - --```js -+```js - console.log ( "hello world" ); - ``` - @@ -18,6 +18,6 @@ ## js block with meta and extra spaces (only the first set of spaces should be changed) @@ -61,7 +53,7 @@ console.log ( "hello world" ); ```md ## plain js block -```js +```js console.log ( "hello world" ); ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-104.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-104.md.snap index bc3967bf890c..62faba02fb8b 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-104.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-104.md.snap @@ -19,8 +19,7 @@ aaa --- Prettier +++ Biome @@ -1,4 +1,3 @@ --```` -+``` + ```` aaa ``` -```` @@ -29,7 +28,7 @@ aaa # Output ```md -``` +```` aaa ``` ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-106.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-106.md.snap index 03b14b989488..f0d1e2acaad6 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-106.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-106.md.snap @@ -20,7 +20,7 @@ aaa +++ Biome @@ -1,4 +1,3 @@ -``` -+~~~~~~ ++~~~~ aaa ~~~ ~~ -``` @@ -29,7 +29,7 @@ aaa # Output ```md -~~~~~~ +~~~~ aaa ~~~ ~~ ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-110.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-110.md.snap index 2e926ffe382f..9a523320a75d 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-110.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-110.md.snap @@ -22,20 +22,20 @@ end +++ Biome @@ -1,5 +1,5 @@ -```ruby startline=3 $%@#$ -+~~~~ ruby startline=3 $%@#$ ++~~~ ruby startline=3 $%@#$ def foo(x) return 3 end -``` -+~~~~~~~ ++~~~ ``` # Output ```md -~~~~ ruby startline=3 $%@#$ +~~~ ruby startline=3 $%@#$ def foo(x) return 3 end -~~~~~~~ +~~~ ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-111.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-111.md.snap index 0f86ade74fd7..0e71b20edad3 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-111.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-111.md.snap @@ -18,16 +18,14 @@ info: markdown/spec/example-111.md --- Prettier +++ Biome @@ -1,3 +1,2 @@ --```; + ```; - --``` -+````; -+```` + ``` ``` # Output ```md -````; -```` +```; +``` ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-113.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-113.md.snap deleted file mode 100644 index b1f177969f67..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-113.md.snap +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/spec/example-113.md ---- - -# Input - -```md -``` -``` aaa -``` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,3 +1,3 @@ --```` -+``` - ``` aaa --```` -+``` -``` - -# Output - -```md -``` -``` aaa -``` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-476.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-476.md.snap index 377332737a05..73f250ce3381 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-476.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-476.md.snap @@ -17,15 +17,13 @@ info: markdown/spec/example-476.md ```diff --- Prettier +++ Biome -@@ -1 +1,2 @@ +@@ -1 +1 @@ -[link](/uri "title") -+[link]( /uri -+ "title" ) ++[link](/uri "title" ) ``` # Output ```md -[link]( /uri - "title" ) +[link](/uri "title" ) ``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-91.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-91.md.snap deleted file mode 100644 index 47cae52dac39..000000000000 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-91.md.snap +++ /dev/null @@ -1,37 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: markdown/spec/example-91.md ---- - -# Input - -```md -```` -aaa -``` -`````` - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -1,4 +1,4 @@ - ```` - aaa - ``` --```` -+`````` -``` - -# Output - -```md -```` -aaa -``` -`````` -``` diff --git a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-94.md.snap b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-94.md.snap index 943b8c7cf425..228e7971a9a8 100644 --- a/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-94.md.snap +++ b/crates/biome_markdown_formatter/tests/specs/prettier/markdown/spec/example-94.md.snap @@ -19,9 +19,7 @@ aaa ```diff --- Prettier +++ Biome -@@ -1,5 +1,4 @@ --```` -+````` +@@ -2,4 +2,3 @@ ``` aaa @@ -31,7 +29,7 @@ aaa # Output ```md -````` +```` ``` aaa diff --git a/crates/biome_markdown_parser/src/to_html.rs b/crates/biome_markdown_parser/src/to_html.rs index a82099d1130f..c4e84e27eb0e 100644 --- a/crates/biome_markdown_parser/src/to_html.rs +++ b/crates/biome_markdown_parser/src/to_html.rs @@ -47,8 +47,8 @@ use biome_markdown_syntax::{ MarkdownLanguage, MdAutolink, MdBlockList, MdBullet, MdBulletListItem, MdDocument, MdEntityReference, MdFencedCodeBlock, MdHardLine, MdHeader, MdHtmlBlock, MdIndentCodeBlock, MdInlineCode, MdInlineEmphasis, MdInlineHtml, MdInlineImage, MdInlineItalic, MdInlineItemList, - MdInlineLink, MdLinkBlock, MdLinkDestination, MdLinkLabel, MdLinkReferenceDefinition, - MdLinkTitle, MdOrderedListItem, MdParagraph, MdQuote, MdReferenceImage, MdReferenceLink, + MdInlineLink, MdLinkDestination, MdLinkLabel, MdLinkReferenceDefinition, MdLinkTitle, + MdOrderedListItem, MdParagraph, MdQuote, MdReferenceImage, MdReferenceLink, MdReferenceLinkLabel, MdSetextHeader, MdSoftBreak, MdTextual, MdThematicBreakBlock, }; use biome_rowan::{AstNode, AstNodeList, Direction, SyntaxNode, TextRange, WalkEvent}; @@ -761,9 +761,7 @@ impl<'a> HtmlRenderer<'a> { return; } - if MdLinkReferenceDefinition::cast(node.clone()).is_some() - || MdLinkBlock::cast(node.clone()).is_some() - { + if MdLinkReferenceDefinition::cast(node.clone()).is_some() { self.opaque_depth = Some(self.depth); return; } diff --git a/crates/biome_markdown_syntax/src/generated/kind.rs b/crates/biome_markdown_syntax/src/generated/kind.rs index 3688c4a78f62..c10a42978e39 100644 --- a/crates/biome_markdown_syntax/src/generated/kind.rs +++ b/crates/biome_markdown_syntax/src/generated/kind.rs @@ -66,7 +66,6 @@ pub enum MarkdownSyntaxKind { MD_FENCED_CODE_BLOCK, MD_CODE_NAME_LIST, MD_HTML_BLOCK, - MD_LINK_BLOCK, MD_LINK_REFERENCE_DEFINITION, MD_LINK_LABEL, MD_LINK_DESTINATION, diff --git a/crates/biome_markdown_syntax/src/generated/macros.rs b/crates/biome_markdown_syntax/src/generated/macros.rs index 93eed417c4c5..8532f9e20d65 100644 --- a/crates/biome_markdown_syntax/src/generated/macros.rs +++ b/crates/biome_markdown_syntax/src/generated/macros.rs @@ -92,10 +92,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::MdInlineLink::new_unchecked(node) }; $body } - $crate::MarkdownSyntaxKind::MD_LINK_BLOCK => { - let $pattern = unsafe { $crate::MdLinkBlock::new_unchecked(node) }; - $body - } $crate::MarkdownSyntaxKind::MD_LINK_DESTINATION => { let $pattern = unsafe { $crate::MdLinkDestination::new_unchecked(node) }; $body diff --git a/crates/biome_markdown_syntax/src/generated/nodes.rs b/crates/biome_markdown_syntax/src/generated/nodes.rs index 13a4c68be357..8b59c89a101f 100644 --- a/crates/biome_markdown_syntax/src/generated/nodes.rs +++ b/crates/biome_markdown_syntax/src/generated/nodes.rs @@ -851,51 +851,6 @@ pub struct MdInlineLinkFields { pub r_paren_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct MdLinkBlock { - pub(crate) syntax: SyntaxNode, -} -impl MdLinkBlock { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> MdLinkBlockFields { - MdLinkBlockFields { - label: self.label(), - url: self.url(), - title: self.title(), - } - } - pub fn label(&self) -> SyntaxResult { - support::required_node(&self.syntax, 0usize) - } - pub fn url(&self) -> SyntaxResult { - support::required_node(&self.syntax, 1usize) - } - pub fn title(&self) -> Option { - support::node(&self.syntax, 2usize) - } -} -impl Serialize for MdLinkBlock { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[derive(Serialize)] -pub struct MdLinkBlockFields { - pub label: SyntaxResult, - pub url: SyntaxResult, - pub title: Option, -} -#[derive(Clone, PartialEq, Eq, Hash)] pub struct MdLinkDestination { pub(crate) syntax: SyntaxNode, } @@ -1887,7 +1842,6 @@ pub enum AnyMdLeafBlock { AnyMdCodeBlock(AnyMdCodeBlock), MdHeader(MdHeader), MdHtmlBlock(MdHtmlBlock), - MdLinkBlock(MdLinkBlock), MdLinkReferenceDefinition(MdLinkReferenceDefinition), MdNewline(MdNewline), MdParagraph(MdParagraph), @@ -1913,12 +1867,6 @@ impl AnyMdLeafBlock { _ => None, } } - pub fn as_md_link_block(&self) -> Option<&MdLinkBlock> { - match &self { - Self::MdLinkBlock(item) => Some(item), - _ => None, - } - } pub fn as_md_link_reference_definition(&self) -> Option<&MdLinkReferenceDefinition> { match &self { Self::MdLinkReferenceDefinition(item) => Some(item), @@ -2946,55 +2894,6 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for MdLinkBlock { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(MD_LINK_BLOCK as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == MD_LINK_BLOCK - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for MdLinkBlock { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - thread_local! { static DEPTH : std :: cell :: Cell < u8 > = const { std :: cell :: Cell :: new (0) } }; - let current_depth = DEPTH.get(); - let result = if current_depth < 16 { - DEPTH.set(current_depth + 1); - f.debug_struct("MdLinkBlock") - .field("label", &support::DebugSyntaxResult(self.label())) - .field("url", &support::DebugSyntaxResult(self.url())) - .field("title", &support::DebugOptionalElement(self.title())) - .finish() - } else { - f.debug_struct("MdLinkBlock").finish() - }; - DEPTH.set(current_depth); - result - } -} -impl From for SyntaxNode { - fn from(n: MdLinkBlock) -> Self { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: MdLinkBlock) -> Self { - n.syntax.into() - } -} impl AstNode for MdLinkDestination { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -4475,11 +4374,6 @@ impl From for AnyMdLeafBlock { Self::MdHtmlBlock(node) } } -impl From for AnyMdLeafBlock { - fn from(node: MdLinkBlock) -> Self { - Self::MdLinkBlock(node) - } -} impl From for AnyMdLeafBlock { fn from(node: MdLinkReferenceDefinition) -> Self { Self::MdLinkReferenceDefinition(node) @@ -4510,7 +4404,6 @@ impl AstNode for AnyMdLeafBlock { const KIND_SET: SyntaxKindSet = AnyMdCodeBlock::KIND_SET .union(MdHeader::KIND_SET) .union(MdHtmlBlock::KIND_SET) - .union(MdLinkBlock::KIND_SET) .union(MdLinkReferenceDefinition::KIND_SET) .union(MdNewline::KIND_SET) .union(MdParagraph::KIND_SET) @@ -4520,7 +4413,6 @@ impl AstNode for AnyMdLeafBlock { match kind { MD_HEADER | MD_HTML_BLOCK - | MD_LINK_BLOCK | MD_LINK_REFERENCE_DEFINITION | MD_NEWLINE | MD_PARAGRAPH @@ -4534,7 +4426,6 @@ impl AstNode for AnyMdLeafBlock { let res = match syntax.kind() { MD_HEADER => Self::MdHeader(MdHeader { syntax }), MD_HTML_BLOCK => Self::MdHtmlBlock(MdHtmlBlock { syntax }), - MD_LINK_BLOCK => Self::MdLinkBlock(MdLinkBlock { syntax }), MD_LINK_REFERENCE_DEFINITION => { Self::MdLinkReferenceDefinition(MdLinkReferenceDefinition { syntax }) } @@ -4555,7 +4446,6 @@ impl AstNode for AnyMdLeafBlock { match self { Self::MdHeader(it) => it.syntax(), Self::MdHtmlBlock(it) => it.syntax(), - Self::MdLinkBlock(it) => it.syntax(), Self::MdLinkReferenceDefinition(it) => it.syntax(), Self::MdNewline(it) => it.syntax(), Self::MdParagraph(it) => it.syntax(), @@ -4568,7 +4458,6 @@ impl AstNode for AnyMdLeafBlock { match self { Self::MdHeader(it) => it.into_syntax(), Self::MdHtmlBlock(it) => it.into_syntax(), - Self::MdLinkBlock(it) => it.into_syntax(), Self::MdLinkReferenceDefinition(it) => it.into_syntax(), Self::MdNewline(it) => it.into_syntax(), Self::MdParagraph(it) => it.into_syntax(), @@ -4584,7 +4473,6 @@ impl std::fmt::Debug for AnyMdLeafBlock { Self::AnyMdCodeBlock(it) => std::fmt::Debug::fmt(it, f), Self::MdHeader(it) => std::fmt::Debug::fmt(it, f), Self::MdHtmlBlock(it) => std::fmt::Debug::fmt(it, f), - Self::MdLinkBlock(it) => std::fmt::Debug::fmt(it, f), Self::MdLinkReferenceDefinition(it) => std::fmt::Debug::fmt(it, f), Self::MdNewline(it) => std::fmt::Debug::fmt(it, f), Self::MdParagraph(it) => std::fmt::Debug::fmt(it, f), @@ -4599,7 +4487,6 @@ impl From for SyntaxNode { AnyMdLeafBlock::AnyMdCodeBlock(it) => it.into_syntax(), AnyMdLeafBlock::MdHeader(it) => it.into_syntax(), AnyMdLeafBlock::MdHtmlBlock(it) => it.into_syntax(), - AnyMdLeafBlock::MdLinkBlock(it) => it.into_syntax(), AnyMdLeafBlock::MdLinkReferenceDefinition(it) => it.into_syntax(), AnyMdLeafBlock::MdNewline(it) => it.into_syntax(), AnyMdLeafBlock::MdParagraph(it) => it.into_syntax(), @@ -4804,11 +4691,6 @@ impl std::fmt::Display for MdInlineLink { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for MdLinkBlock { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for MdLinkDestination { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/biome_markdown_syntax/src/generated/nodes_mut.rs b/crates/biome_markdown_syntax/src/generated/nodes_mut.rs index 052a6854ebee..b825629a165b 100644 --- a/crates/biome_markdown_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_markdown_syntax/src/generated/nodes_mut.rs @@ -353,26 +353,6 @@ impl MdInlineLink { ) } } -impl MdLinkBlock { - pub fn with_label(self, element: MdTextual) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_url(self, element: MdTextual) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_title(self, element: Option) -> Self { - Self::unwrap_cast(self.syntax.splice_slots( - 2usize..=2usize, - once(element.map(|element| element.into_syntax().into())), - )) - } -} impl MdLinkDestination { pub fn with_content(self, element: MdInlineItemList) -> Self { Self::unwrap_cast( diff --git a/crates/biome_markdown_syntax/src/text_ext.rs b/crates/biome_markdown_syntax/src/text_ext.rs index ad86eb924492..e0aa4d2d812e 100644 --- a/crates/biome_markdown_syntax/src/text_ext.rs +++ b/crates/biome_markdown_syntax/src/text_ext.rs @@ -2,11 +2,16 @@ use crate::MdTextual; use biome_rowan::SyntaxResult; impl MdTextual { - pub fn is_empty(&self) -> SyntaxResult { + pub fn is_empty_and_not_newline(&self) -> SyntaxResult { let token = self.value_token()?; Ok(token.text().trim().is_empty() && !self.is_newline()?) } + pub fn is_empty(&self) -> SyntaxResult { + let token = self.value_token()?; + Ok(token.text().trim().is_empty() || self.is_newline()?) + } + pub fn is_newline(&self) -> SyntaxResult { let token = self.value_token()?; Ok(token.text() == "\n" || token.text() == "\r" || token.text() == "\r\n") diff --git a/xtask/codegen/markdown.ungram b/xtask/codegen/markdown.ungram index 28f9524d0144..cc2e1356c228 100644 --- a/xtask/codegen/markdown.ungram +++ b/xtask/codegen/markdown.ungram @@ -59,7 +59,6 @@ AnyMdLeafBlock = | AnyMdCodeBlock | MdHtmlBlock | MdLinkReferenceDefinition - | MdLinkBlock | MdParagraph | MdNewline @@ -166,10 +165,6 @@ MdLinkDestination = content: MdInlineItemList // Titles can contain multiple tokens MdLinkTitle = content: MdInlineItemList -// Legacy MdLinkBlock retained for backwards compatibility -MdLinkBlock = label: MdTextual - url: MdTextual - title: MdTextual? // > Foo // ^^^^^ diff --git a/xtask/codegen/src/markdown_kinds_src.rs b/xtask/codegen/src/markdown_kinds_src.rs index 929a91198cdd..a508a86ed884 100644 --- a/xtask/codegen/src/markdown_kinds_src.rs +++ b/xtask/codegen/src/markdown_kinds_src.rs @@ -59,7 +59,6 @@ pub const MARKDOWN_KINDS_SRC: KindsSrc = KindsSrc { "MD_FENCED_CODE_BLOCK", "MD_CODE_NAME_LIST", "MD_HTML_BLOCK", - "MD_LINK_BLOCK", "MD_LINK_REFERENCE_DEFINITION", "MD_LINK_LABEL", "MD_LINK_DESTINATION",