aboutsummaryrefslogtreecommitdiffstats
path: root/src/content/flow.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-09 13:01:36 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-09 13:01:36 +0200
commit10355a403f57c93a074716c785d588c76de5634c (patch)
tree46408a8a1198c1bb632f22964a347c01023867bc /src/content/flow.rs
parent433680ae0914da8921c4ee762fdc93e7b70cf9f1 (diff)
downloadmarkdown-rs-10355a403f57c93a074716c785d588c76de5634c.tar.gz
markdown-rs-10355a403f57c93a074716c785d588c76de5634c.tar.bz2
markdown-rs-10355a403f57c93a074716c785d588c76de5634c.zip
Add support for indented lines in paragraphs
Diffstat (limited to '')
-rw-r--r--src/content/flow.rs43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/content/flow.rs b/src/content/flow.rs
index 6c47a10..ac987e1 100644
--- a/src/content/flow.rs
+++ b/src/content/flow.rs
@@ -19,6 +19,7 @@
//!
//! <!-- To do: `setext` in content? Link to content. -->
+use crate::constant::TAB_SIZE;
use crate::construct::{
blank_line::start as blank_line, code_fenced::start as code_fenced,
code_indented::start as code_indented, heading_atx::start as heading_atx,
@@ -26,6 +27,7 @@ use crate::construct::{
thematic_break::start as thematic_break,
};
use crate::tokenizer::{Code, Event, State, StateFnResult, TokenType, Tokenizer};
+use crate::util::get_span;
/// Turn `codes` as the flow content type into events.
// To do: remove this `allow` when all the content types are glued together.
@@ -237,34 +239,29 @@ fn continuation_construct_initial_before(tokenizer: &mut Tokenizer, code: Code)
}
fn continuation_construct_after_prefix(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
- // let tail = tokenizer.events.last();
- // let mut prefix = 0;
+ let tail = tokenizer.events.last();
+ let mut prefix = 0;
- // if let Some(event) = tail {
- // if event.token_type == TokenType::Whitespace {
- // let span = get_span(&tokenizer.events, tokenizer.events.len() - 1);
- // prefix = span.end_index - span.start_index;
- // }
- // }
+ if let Some(event) = tail {
+ if event.token_type == TokenType::Whitespace {
+ let span = get_span(&tokenizer.events, tokenizer.events.len() - 1);
+ prefix = span.end_index - span.start_index;
+ }
+ }
match code {
// Blank lines are not allowed in content.
Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => (State::Nok, None),
- // If code is disabled, indented lines are part of the content.
- // _ if prefix >= TAB_SIZE => {
- // (State::Ok, None)
- // }
- _ => {
- println!("to do: check if flow interrupts, assuming it can’t");
- tokenizer.attempt_2(heading_atx, thematic_break, |ok| {
- let result = if ok {
- (State::Nok, None)
- } else {
- (State::Ok, None)
- };
- Box::new(|_t, _c| result)
- })(tokenizer, code)
- }
+ // To do: If code is disabled, indented lines are part of the content.
+ _ if prefix >= TAB_SIZE => (State::Ok, None),
+ _ => tokenizer.attempt_2(heading_atx, thematic_break, |ok| {
+ let result = if ok {
+ (State::Nok, None)
+ } else {
+ (State::Ok, None)
+ };
+ Box::new(|_t, _c| result)
+ })(tokenizer, code),
}
}