Skip to content

Commit

Permalink
merge blockquote kind parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Roms1383 committed Jun 13, 2024
1 parent 89d5dd5 commit 6d05a28
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 6d05a28

Please sign in to comment.