From 6d05a28029087187bbbbe085aa77689c6ed89a07 Mon Sep 17 00:00:00 2001 From: Roms1383 Date: Thu, 13 Jun 2024 18:47:28 +0700 Subject: [PATCH] merge blockquote kind parsing --- src/lib.rs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 479d80a..fbd8b46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -370,8 +370,19 @@ where }?; formatter.write_char(' ') } - BlockQuote(None) => { - state.padding.push(" > ".into()); + BlockQuote(kind) => { + if let Some(kind) = kind { + let kind = match kind { + BlockQuoteKind::Note => "NOTE", + BlockQuoteKind::Tip => "TIP", + BlockQuoteKind::Important => "IMPORTANT", + BlockQuoteKind::Warning => "WARNING", + BlockQuoteKind::Caution => "CAUTION", + }; + state.padding.push(format!(" > [!{kind}]\n > ").into()); + } else { + state.padding.push(" > ".into()); + } state.newlines_before_start = 1; // if we consumed some newlines, we know that we can just write out the next @@ -383,24 +394,6 @@ where formatter.write_char('\n').and(padding(formatter, &state.padding)) } } - BlockQuote(Some(kind)) => { - let kind = match kind { - BlockQuoteKind::Note => "NOTE", - BlockQuoteKind::Tip => "TIP", - BlockQuoteKind::Important => "IMPORTANT", - BlockQuoteKind::Warning => "WARNING", - BlockQuoteKind::Caution => "CAUTION", - }; - state.padding.push(format!(" > [!{kind}]\n > ").into()); - state.newlines_before_start = 1; - - // same logic as traditional blockquote, see above - if consumed_newlines { - formatter.write_str(" > ") - } else { - formatter.write_char('\n').and(padding(formatter, &state.padding)) - } - } CodeBlock(CodeBlockKind::Indented) => { state.is_in_code_block = true; for _ in 0..options.code_block_token_count {