aboutsummaryrefslogtreecommitdiffstats
path: root/src/subtokenize.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-22 16:16:59 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-22 16:16:59 +0200
commit8774b207b7251730eaa7fbfe4f144122a472dda0 (patch)
treece1b8f92a08ff70da265ae8e4484dba2335280a9 /src/subtokenize.rs
parent351c69644bdbdf52c95e322904273657892920b5 (diff)
downloadmarkdown-rs-8774b207b7251730eaa7fbfe4f144122a472dda0.tar.gz
markdown-rs-8774b207b7251730eaa7fbfe4f144122a472dda0.tar.bz2
markdown-rs-8774b207b7251730eaa7fbfe4f144122a472dda0.zip
Add support for GFM task list item
Diffstat (limited to 'src/subtokenize.rs')
-rw-r--r--src/subtokenize.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/subtokenize.rs b/src/subtokenize.rs
index 5932f11..7fcc481 100644
--- a/src/subtokenize.rs
+++ b/src/subtokenize.rs
@@ -17,11 +17,11 @@
//! whole document needs to be parsed up to the level of definitions, before
//! any level that can include references can be parsed.
-use crate::event::{Content, Event, Kind, VOID_EVENTS};
+use crate::event::{Content, Event, Kind, Name, VOID_EVENTS};
use crate::parser::ParseState;
use crate::state::{Name as StateName, State};
use crate::tokenizer::Tokenizer;
-use crate::util::edit_map::EditMap;
+use crate::util::{edit_map::EditMap, skip};
use alloc::{vec, vec::Vec};
/// Link two [`Event`][]s.
@@ -94,6 +94,34 @@ pub fn subtokenize(events: &mut Vec<Event>, parse_state: &ParseState) -> bool {
StateName::TextStart
});
+ // Check if this is the first paragraph, after zero or more
+ // definitions (or a blank line), in a list item.
+ // Used for GFM task list items.
+ if tokenizer.parse_state.options.constructs.gfm_task_list_item
+ && index > 2
+ && events[index - 1].kind == Kind::Enter
+ && events[index - 1].name == Name::Paragraph
+ {
+ let before = skip::opt_back(
+ events,
+ index - 2,
+ &[
+ Name::BlankLineEnding,
+ Name::Definition,
+ Name::LineEnding,
+ Name::SpaceOrTab,
+ ],
+ );
+
+ if events[before].kind == Kind::Exit
+ && events[before].name == Name::ListItemPrefix
+ {
+ tokenizer
+ .tokenize_state
+ .document_at_first_paragraph_of_list_item = true;
+ }
+ }
+
// Loop through links to pass them in order to the subtokenizer.
while let Some(index) = link_index {
let enter = &events[index];