diff --git a/packages/markdown_parser/rust/src/block.rs b/packages/markdown_parser/rust/src/block.rs index 967dad3c2..bd5ab4e38 100644 --- a/packages/markdown_parser/rust/src/block.rs +++ b/packages/markdown_parser/rust/src/block.rs @@ -32,6 +32,13 @@ struct ExtraContent { offset: usize, } +#[derive(Clone, Debug)] +struct BlockSpoilerResult { + node: Node, + new_line_index: usize, + extra_content: Option, +} + #[derive(Clone, Debug)] struct ClosingFence<'a> { fence_index: usize, @@ -130,9 +137,13 @@ pub(crate) fn parse_block(state: &mut RuntimeState<'_>) -> Result Result<(Node, usize), ParseError> { +) -> Result { let mut found_end = false; + let mut trailing_content: Option = None; let mut child_lines = Vec::new(); let mut content_len = 0usize; let mut index = current; @@ -617,6 +629,13 @@ fn parse_block_spoiler( offset: lines[index].offset, }); found_end = true; + let trailing = &line[end + 2..]; + if !trailing.is_empty() { + trailing_content = Some(ExtraContent { + content: trailing.to_owned(), + offset: lines[index].offset + (line.len() - trailing.len()), + }); + } index += 1; break; } else { @@ -630,31 +649,38 @@ fn parse_block_spoiler( } if !found_end { let content = lines_to_text(&child_lines); - return Ok(( - Node::Text { + return Ok(BlockSpoilerResult { + node: Node::Text { content: concat("||", trim_right(&content)), }, - index, - )); + new_line_index: index, + extra_content: None, + }); } let mut child_parser = parser.child_with_flags(parser.flags()); let mut window = child_lines; if !has_visible_content(&lines_to_text(&window)) { - return Ok(( - Node::Text { + return Ok(BlockSpoilerResult { + node: Node::Text { content: lines_to_text(&lines[current..index]), }, - index, - )); + new_line_index: index, + extra_content: None, + }); } let inner = child_parser.parse_lines(trim_line_window(&mut window))?; - Ok(( - Node::Spoiler { + Ok(BlockSpoilerResult { + node: Node::Spoiler { children: inner, is_block: Some(true), }, - index, - )) + new_line_index: if trailing_content.is_some() { + index - 1 + } else { + index + }, + extra_content: trailing_content, + }) } fn parse_alert_lines(