aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/heading_atx.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-22 15:20:33 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-22 15:20:33 +0200
commit227e844154d9a592b80a88d7b8731d3d2f2fb3e2 (patch)
tree09d4243db0ae3d51c2420e70b9e364d470d520bd /src/construct/heading_atx.rs
parent6fdaffb3a8b4517a3b5c1e39dc1e16649c6eb0da (diff)
downloadmarkdown-rs-227e844154d9a592b80a88d7b8731d3d2f2fb3e2.tar.gz
markdown-rs-227e844154d9a592b80a88d7b8731d3d2f2fb3e2.tar.bz2
markdown-rs-227e844154d9a592b80a88d7b8731d3d2f2fb3e2.zip
Add `attempt_opt` to tokenizer
Diffstat (limited to '')
-rw-r--r--src/construct/heading_atx.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/construct/heading_atx.rs b/src/construct/heading_atx.rs
index ae16d3d..93c57f9 100644
--- a/src/construct/heading_atx.rs
+++ b/src/construct/heading_atx.rs
@@ -54,7 +54,9 @@
//! [wiki-setext]: https://en.wikipedia.org/wiki/Setext
//! [atx]: http://www.aaronsw.com/2002/atx/
-use super::partial_space_or_tab::{space_or_tab, space_or_tab_opt};
+use super::partial_space_or_tab::{
+ space_or_tab, space_or_tab_with_options, Options as SpaceOrTabOptions,
+};
use crate::constant::HEADING_ATX_OPENING_FENCE_SIZE_MAX;
use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer};
@@ -65,7 +67,7 @@ use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer};
/// ```
pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
tokenizer.enter(TokenType::HeadingAtx);
- tokenizer.go(space_or_tab_opt(), before)(tokenizer, code)
+ tokenizer.attempt_opt(space_or_tab(), before)(tokenizer, code)
}
/// Start of a heading (atx), after whitespace.
@@ -105,7 +107,11 @@ fn sequence_open(tokenizer: &mut Tokenizer, code: Code, rank: usize) -> StateFnR
_ if rank > 0 => {
tokenizer.exit(TokenType::HeadingAtxSequence);
tokenizer.go(
- space_or_tab(TokenType::HeadingAtxSpaceOrTab, 1, usize::MAX),
+ space_or_tab_with_options(SpaceOrTabOptions {
+ kind: TokenType::HeadingAtxSpaceOrTab,
+ min: 1,
+ max: usize::MAX,
+ }),
at_break,
)(tokenizer, code)
}
@@ -129,7 +135,11 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
(State::Ok, Some(vec![code]))
}
Code::VirtualSpace | Code::Char('\t' | ' ') => tokenizer.go(
- space_or_tab(TokenType::HeadingAtxSpaceOrTab, 1, usize::MAX),
+ space_or_tab_with_options(SpaceOrTabOptions {
+ kind: TokenType::HeadingAtxSpaceOrTab,
+ min: 1,
+ max: usize::MAX,
+ }),
at_break,
)(tokenizer, code),
Code::Char('#') => {