Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions crates/biome_markdown_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion crates/biome_markdown_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions crates/biome_markdown_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,44 @@ impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdQuote {
)
}
}
impl FormatRule<biome_markdown_syntax::MdQuotePrefix>
for crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix
{
type Context = MarkdownFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_markdown_syntax::MdQuotePrefix,
f: &mut MarkdownFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_markdown_syntax::MdQuotePrefix>::fmt(self, node, f)
}
}
impl AsFormat<MarkdownFormatContext> for biome_markdown_syntax::MdQuotePrefix {
type Format<'a> = FormatRefWithRule<
'a,
biome_markdown_syntax::MdQuotePrefix,
crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix::default(),
)
}
}
impl IntoFormat<MarkdownFormatContext> for biome_markdown_syntax::MdQuotePrefix {
type Format = FormatOwnedWithRule<
biome_markdown_syntax::MdQuotePrefix,
crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::markdown::auxiliary::quote_prefix::FormatMdQuotePrefix::default(),
)
}
}
impl FormatRule<biome_markdown_syntax::MdReferenceImage>
for crate::markdown::auxiliary::reference_image::FormatMdReferenceImage
{
Expand Down
1 change: 1 addition & 0 deletions crates/biome_markdown_formatter/src/markdown/any/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl FormatRule<AnyMdBlock> for FormatAnyMdBlock {
match node {
AnyMdBlock::AnyMdContainerBlock(node) => node.format().fmt(f),
AnyMdBlock::AnyMdLeafBlock(node) => node.format().fmt(f),
AnyMdBlock::MdQuotePrefix(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_markdown_formatter/src/markdown/any/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl FormatRule<AnyMdInline> for FormatAnyMdInline {
AnyMdInline::MdInlineImage(node) => node.format().fmt(f),
AnyMdInline::MdInlineItalic(node) => node.format().fmt(f),
AnyMdInline::MdInlineLink(node) => node.format().fmt(f),
AnyMdInline::MdQuotePrefix(node) => node.format().fmt(f),
AnyMdInline::MdReferenceImage(node) => node.format().fmt(f),
AnyMdInline::MdReferenceLink(node) => node.format().fmt(f),
AnyMdInline::MdSoftBreak(node) => node.format().fmt(f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) mod newline;
pub(crate) mod ordered_list_item;
pub(crate) mod paragraph;
pub(crate) mod quote;
pub(crate) mod quote_prefix;
pub(crate) mod reference_image;
pub(crate) mod reference_link;
pub(crate) mod reference_link_label;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::prelude::*;
use biome_markdown_syntax::MdQuotePrefix;
use biome_rowan::AstNode;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatMdQuotePrefix;
impl FormatNodeRule<MdQuotePrefix> for FormatMdQuotePrefix {
fn fmt_fields(&self, node: &MdQuotePrefix, f: &mut MarkdownFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
}
}
49 changes: 2 additions & 47 deletions crates/biome_markdown_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use list::{
};
use quote::{
at_quote, consume_quote_prefix, consume_quote_prefix_without_virtual, has_quote_prefix,
parse_quote,
line_has_quote_prefix_at_current, parse_quote,
};
use thematic_break_block::{at_thematic_break_block, parse_thematic_break_block};

Expand Down Expand Up @@ -757,7 +757,7 @@ fn allow_setext_heading(p: &MarkdownParser) -> bool {
return true;
}

line_has_quote_prefix(p, depth)
line_has_quote_prefix_at_current(p, depth)
}

/// Compute the real leading indent of the current line from source text.
Expand All @@ -783,51 +783,6 @@ fn real_line_indent_from_source(p: &MarkdownParser) -> usize {
column
}

fn line_has_quote_prefix(p: &MarkdownParser, depth: usize) -> bool {
// Tokens may have consumed whitespace as trivia; scan source to recover columns.
if depth == 0 {
return false;
}

let source = p.source().source_text();
let start: usize = p.cur_range().start().into();
let line_start = source[..start].rfind('\n').map_or(0, |idx| idx + 1);

let mut idx = line_start;
let mut indent = 0usize;
while idx < start {
match source.as_bytes()[idx] {
b' ' => {
indent += 1;
idx += 1;
}
b'\t' => {
indent += 4;
idx += 1;
}
_ => break,
}
if indent > 3 {
return false;
}
}

for _ in 0..depth {
if idx >= start || source.as_bytes()[idx] != b'>' {
return false;
}
idx += 1;
if idx < start {
let c = source.as_bytes()[idx];
if c == b' ' || c == b'\t' {
idx += 1;
}
}
}

true
}

fn classify_quote_break_after_newline(
p: &mut MarkdownParser,
quote_depth: usize,
Expand Down
Loading
Loading