Skip to content

Commit c65ad0f

Browse files
committed
refactor(markdown-parser): promote list structural tokens from skipped trivia to explicit CST nodes
Introduce MdListMarkerPrefix to wrap list marker structure (pre-marker indent, marker, post-marker space, content indent) as real CST nodes instead of skipped trivia. This mirrors the MdQuotePrefix pattern from Phase 1 and makes list structure visible to the formatter harness. - Add MdListMarkerPrefix, MdIndentToken, MdIndentTokenList to grammar - Replace skip_list_marker_indent() with emit_indent_char_list() - Emit MD_LIST_POST_MARKER_SPACE as an explicit token - Promote marker-only line newline to MdNewline node - Remove trim_range(); use raw node ranges for metadata recording - Fix to_html.rs renderer to handle new CST shape correctly - Add verbatim formatter stubs for new node types
1 parent 412a08d commit c65ad0f

28 files changed

+1545
-296
lines changed

crates/biome_markdown_factory/src/generated/node_factory.rs

Lines changed: 56 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_markdown_factory/src/generated/syntax_factory.rs

Lines changed: 66 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_markdown_formatter/src/generated.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,44 @@ impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdIndentCodeBl
461461
)
462462
}
463463
}
464+
impl FormatRule<biome_markdown_syntax::MdIndentToken>
465+
for crate::markdown::auxiliary::indent_token::FormatMdIndentToken
466+
{
467+
type Context = MarkdownFormatContext;
468+
#[inline(always)]
469+
fn fmt(
470+
&self,
471+
node: &biome_markdown_syntax::MdIndentToken,
472+
f: &mut MarkdownFormatter,
473+
) -> FormatResult<()> {
474+
FormatNodeRule::<biome_markdown_syntax::MdIndentToken>::fmt(self, node, f)
475+
}
476+
}
477+
impl AsFormat<MarkdownFormatContext> for biome_markdown_syntax::MdIndentToken {
478+
type Format<'a> = FormatRefWithRule<
479+
'a,
480+
biome_markdown_syntax::MdIndentToken,
481+
crate::markdown::auxiliary::indent_token::FormatMdIndentToken,
482+
>;
483+
fn format(&self) -> Self::Format<'_> {
484+
FormatRefWithRule::new(
485+
self,
486+
crate::markdown::auxiliary::indent_token::FormatMdIndentToken::default(),
487+
)
488+
}
489+
}
490+
impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdIndentToken {
491+
type Format = FormatOwnedWithRule<
492+
biome_markdown_syntax::MdIndentToken,
493+
crate::markdown::auxiliary::indent_token::FormatMdIndentToken,
494+
>;
495+
fn into_format(self) -> Self::Format {
496+
FormatOwnedWithRule::new(
497+
self,
498+
crate::markdown::auxiliary::indent_token::FormatMdIndentToken::default(),
499+
)
500+
}
501+
}
464502
impl FormatRule<biome_markdown_syntax::MdInlineCode>
465503
for crate::markdown::auxiliary::inline_code::FormatMdInlineCode
466504
{
@@ -873,6 +911,44 @@ impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdLinkTitle {
873911
)
874912
}
875913
}
914+
impl FormatRule<biome_markdown_syntax::MdListMarkerPrefix>
915+
for crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix
916+
{
917+
type Context = MarkdownFormatContext;
918+
#[inline(always)]
919+
fn fmt(
920+
&self,
921+
node: &biome_markdown_syntax::MdListMarkerPrefix,
922+
f: &mut MarkdownFormatter,
923+
) -> FormatResult<()> {
924+
FormatNodeRule::<biome_markdown_syntax::MdListMarkerPrefix>::fmt(self, node, f)
925+
}
926+
}
927+
impl AsFormat<MarkdownFormatContext> for biome_markdown_syntax::MdListMarkerPrefix {
928+
type Format<'a> = FormatRefWithRule<
929+
'a,
930+
biome_markdown_syntax::MdListMarkerPrefix,
931+
crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix,
932+
>;
933+
fn format(&self) -> Self::Format<'_> {
934+
FormatRefWithRule::new(
935+
self,
936+
crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix::default(),
937+
)
938+
}
939+
}
940+
impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdListMarkerPrefix {
941+
type Format = FormatOwnedWithRule<
942+
biome_markdown_syntax::MdListMarkerPrefix,
943+
crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix,
944+
>;
945+
fn into_format(self) -> Self::Format {
946+
FormatOwnedWithRule::new(
947+
self,
948+
crate::markdown::auxiliary::list_marker_prefix::FormatMdListMarkerPrefix::default(),
949+
)
950+
}
951+
}
876952
impl FormatRule<biome_markdown_syntax::MdNewline>
877953
for crate::markdown::auxiliary::newline::FormatMdNewline
878954
{
@@ -1467,6 +1543,31 @@ impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdHashList {
14671543
)
14681544
}
14691545
}
1546+
impl AsFormat<MarkdownFormatContext> for biome_markdown_syntax::MdIndentTokenList {
1547+
type Format<'a> = FormatRefWithRule<
1548+
'a,
1549+
biome_markdown_syntax::MdIndentTokenList,
1550+
crate::markdown::lists::indent_token_list::FormatMdIndentTokenList,
1551+
>;
1552+
fn format(&self) -> Self::Format<'_> {
1553+
FormatRefWithRule::new(
1554+
self,
1555+
crate::markdown::lists::indent_token_list::FormatMdIndentTokenList::default(),
1556+
)
1557+
}
1558+
}
1559+
impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdIndentTokenList {
1560+
type Format = FormatOwnedWithRule<
1561+
biome_markdown_syntax::MdIndentTokenList,
1562+
crate::markdown::lists::indent_token_list::FormatMdIndentTokenList,
1563+
>;
1564+
fn into_format(self) -> Self::Format {
1565+
FormatOwnedWithRule::new(
1566+
self,
1567+
crate::markdown::lists::indent_token_list::FormatMdIndentTokenList::default(),
1568+
)
1569+
}
1570+
}
14701571
impl AsFormat<MarkdownFormatContext> for biome_markdown_syntax::MdInlineItemList {
14711572
type Format<'a> = FormatRefWithRule<
14721573
'a,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::prelude::*;
2+
use biome_markdown_syntax::MdIndentToken;
3+
use biome_rowan::AstNode;
4+
#[derive(Debug, Clone, Default)]
5+
pub(crate) struct FormatMdIndentToken;
6+
impl FormatNodeRule<MdIndentToken> for FormatMdIndentToken {
7+
fn fmt_fields(&self, node: &MdIndentToken, f: &mut MarkdownFormatter) -> FormatResult<()> {
8+
format_verbatim_node(node.syntax()).fmt(f)
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::prelude::*;
2+
use biome_markdown_syntax::MdListMarkerPrefix;
3+
use biome_rowan::AstNode;
4+
#[derive(Debug, Clone, Default)]
5+
pub(crate) struct FormatMdListMarkerPrefix;
6+
impl FormatNodeRule<MdListMarkerPrefix> for FormatMdListMarkerPrefix {
7+
fn fmt_fields(&self, node: &MdListMarkerPrefix, f: &mut MarkdownFormatter) -> FormatResult<()> {
8+
format_verbatim_node(node.syntax()).fmt(f)
9+
}
10+
}

crates/biome_markdown_formatter/src/markdown/auxiliary/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) mod header;
1212
pub(crate) mod html_block;
1313
pub(crate) mod indent;
1414
pub(crate) mod indent_code_block;
15+
pub(crate) mod indent_token;
1516
pub(crate) mod inline_code;
1617
pub(crate) mod inline_emphasis;
1718
pub(crate) mod inline_html;
@@ -23,6 +24,7 @@ pub(crate) mod link_destination;
2324
pub(crate) mod link_label;
2425
pub(crate) mod link_reference_definition;
2526
pub(crate) mod link_title;
27+
pub(crate) mod list_marker_prefix;
2628
pub(crate) mod newline;
2729
pub(crate) mod ordered_list_item;
2830
pub(crate) mod paragraph;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::prelude::*;
2+
use biome_markdown_syntax::MdIndentTokenList;
3+
#[derive(Debug, Clone, Default)]
4+
pub(crate) struct FormatMdIndentTokenList;
5+
impl FormatRule<MdIndentTokenList> for FormatMdIndentTokenList {
6+
type Context = MarkdownFormatContext;
7+
fn fmt(&self, node: &MdIndentTokenList, f: &mut MarkdownFormatter) -> FormatResult<()> {
8+
f.join().entries(node.iter().formatted()).finish()
9+
}
10+
}

crates/biome_markdown_formatter/src/markdown/lists/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ pub(crate) mod block_list;
44
pub(crate) mod bullet_list;
55
pub(crate) mod code_name_list;
66
pub(crate) mod hash_list;
7+
pub(crate) mod indent_token_list;
78
pub(crate) mod inline_item_list;
89
pub(crate) mod quote_indent_list;

0 commit comments

Comments
 (0)