aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-14 17:40:10 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-14 17:40:10 +0200
commit8183323c432fc1359c634feb68bc372e13f0bd03 (patch)
tree0c80086a956d216960cedc436a3b22372190b7a8 /src/compiler.rs
parente2c9664b0d63ec686f9e4625ac11bb21720f74dc (diff)
downloadmarkdown-rs-8183323c432fc1359c634feb68bc372e13f0bd03.tar.gz
markdown-rs-8183323c432fc1359c634feb68bc372e13f0bd03.tar.bz2
markdown-rs-8183323c432fc1359c634feb68bc372e13f0bd03.zip
Add support for container state
* Fix to parse list item continuation based on how big the initial list item prefix was * Fix list items that start with blank lines
Diffstat (limited to 'src/compiler.rs')
-rw-r--r--src/compiler.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index 37229a4..51c7e2b 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -1150,7 +1150,9 @@ fn on_exit_media(context: &mut CompileContext) {
fn on_exit_paragraph(context: &mut CompileContext) {
let tight = context.tight_stack.last().unwrap_or(&false);
- if !tight {
+ if *tight {
+ context.slurp_one_line_ending = true;
+ } else {
context.tag("</p>".to_string());
}
}
@@ -1216,6 +1218,14 @@ fn on_enter_list(context: &mut CompileContext) {
if balance < 3 && event.token_type == Token::BlankLineEnding
// && !(balance == 1 && events[index - 2].token_type == Token::ListItem)
{
+ let at_marker = balance == 2
+ && events[skip::opt_back(
+ events,
+ index - 2,
+ &[Token::BlankLineEnding, Token::SpaceOrTab],
+ )]
+ .token_type
+ == Token::ListItemPrefix;
let at_list_item = balance == 1 && events[index - 2].token_type == Token::ListItem;
let at_empty_list_item = if at_list_item {
let before_item = skip::opt_back(events, index - 2, &[Token::ListItem]);
@@ -1229,7 +1239,7 @@ fn on_enter_list(context: &mut CompileContext) {
false
};
- if !at_list_item || !at_empty_list_item {
+ if !at_marker && (!at_list_item || !at_empty_list_item) {
loose = true;
break;
}
@@ -1297,7 +1307,12 @@ fn on_exit_list_item(context: &mut CompileContext) {
let before_item = skip::opt_back(
context.events,
context.index - 1,
- &[Token::BlankLineEnding, Token::LineEnding, Token::SpaceOrTab],
+ &[
+ Token::BlankLineEnding,
+ Token::LineEnding,
+ Token::SpaceOrTab,
+ Token::BlockQuotePrefix,
+ ],
);
let previous = &context.events[before_item];
let tight_paragraph = *tight && previous.token_type == Token::Paragraph;