aboutsummaryrefslogtreecommitdiffstats
path: root/src/content/text.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-09 14:04:27 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-09 14:04:27 +0200
commit8f8d72a749a39845fd03ae259533abe73dc7dcdf (patch)
treeebc54d404f5a5e7e406f6323131dae1ed7a79c50 /src/content/text.rs
parentfafcfd55e5f7ea8b87cab4bbf979730d81749402 (diff)
downloadmarkdown-rs-8f8d72a749a39845fd03ae259533abe73dc7dcdf.tar.gz
markdown-rs-8f8d72a749a39845fd03ae259533abe73dc7dcdf.tar.bz2
markdown-rs-8f8d72a749a39845fd03ae259533abe73dc7dcdf.zip
Add support for passing `ok`, `nok` as separate states to attempts
Diffstat (limited to 'src/content/text.rs')
-rw-r--r--src/content/text.rs85
1 files changed, 64 insertions, 21 deletions
diff --git a/src/content/text.rs b/src/content/text.rs
index d8a2726..ff8c9eb 100644
--- a/src/content/text.rs
+++ b/src/content/text.rs
@@ -46,37 +46,80 @@ pub fn start(tokenizer: &mut Tokenizer) -> State {
pub fn before(tokenizer: &mut Tokenizer) -> State {
match tokenizer.current {
None => State::Ok,
- _ => tokenizer.attempt_n(
- vec![
- StateName::AttentionStart,
- StateName::AutolinkStart,
- StateName::CharacterEscapeStart,
- StateName::CharacterReferenceStart,
- StateName::CodeTextStart,
- StateName::HardBreakEscapeStart,
- StateName::HtmlTextStart,
- StateName::LabelEndStart,
- StateName::LabelStartImageStart,
- StateName::LabelStartLinkStart,
- ],
- |ok| {
- State::Fn(if ok {
- StateName::TextBefore
- } else {
- StateName::TextBeforeData
- })
- },
+ Some(b'!') => tokenizer.attempt(
+ StateName::LabelStartImageStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
),
+ Some(b'&') => tokenizer.attempt(
+ StateName::CharacterReferenceStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ ),
+ Some(b'*' | b'_') => tokenizer.attempt(
+ StateName::AttentionStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ ),
+ // `autolink`, `html_text` (order does not matter)
+ Some(b'<') => tokenizer.attempt(
+ StateName::AutolinkStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeHtml),
+ ),
+ Some(b'[') => tokenizer.attempt(
+ StateName::LabelStartLinkStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ ),
+ Some(b'\\') => tokenizer.attempt(
+ StateName::CharacterEscapeStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeHardBreakEscape),
+ ),
+ Some(b']') => tokenizer.attempt(
+ StateName::LabelEndStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ ),
+ Some(b'`') => tokenizer.attempt(
+ StateName::CodeTextStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ ),
+ _ => before_data(tokenizer),
}
}
+/// To do.
+pub fn before_html(tokenizer: &mut Tokenizer) -> State {
+ tokenizer.attempt(
+ StateName::HtmlTextStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ )
+}
+
+/// To do.
+pub fn before_hard_break_escape(tokenizer: &mut Tokenizer) -> State {
+ tokenizer.attempt(
+ StateName::HardBreakEscapeStart,
+ State::Fn(StateName::TextBefore),
+ State::Fn(StateName::TextBeforeData),
+ )
+}
+
/// At data.
///
/// ```markdown
/// |qwe
/// ```
pub fn before_data(tokenizer: &mut Tokenizer) -> State {
- tokenizer.go(StateName::DataStart, StateName::TextBefore)
+ tokenizer.attempt(
+ StateName::DataStart,
+ State::Fn(StateName::TextBefore),
+ State::Nok,
+ )
}
/// Resolve whitespace.