aboutsummaryrefslogtreecommitdiffstats
path: root/src/content/text.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-21 17:24:56 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-21 17:24:56 +0200
commit56ff5c73c7ec19b349e7d60d04ce1057c006d6ec (patch)
treeb4107ae0e0219f871a2f2764215ad979b2b0d75f /src/content/text.rs
parent7effd171218fff68f051671f1373cee467a8f921 (diff)
downloadmarkdown-rs-56ff5c73c7ec19b349e7d60d04ce1057c006d6ec.tar.gz
markdown-rs-56ff5c73c7ec19b349e7d60d04ce1057c006d6ec.tar.bz2
markdown-rs-56ff5c73c7ec19b349e7d60d04ce1057c006d6ec.zip
Make data a construct
Diffstat (limited to 'src/content/text.rs')
-rw-r--r--src/content/text.rs53
1 files changed, 12 insertions, 41 deletions
diff --git a/src/content/text.rs b/src/content/text.rs
index 6a30d4c..857e9a0 100644
--- a/src/content/text.rs
+++ b/src/content/text.rs
@@ -21,8 +21,17 @@ use crate::construct::{
character_reference::start as character_reference, code_text::start as code_text,
hard_break_escape::start as hard_break_escape,
hard_break_trailing::start as hard_break_trailing, html_text::start as html_text,
+ partial_data::start as data,
};
-use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer};
+use crate::tokenizer::{Code, State, StateFnResult, Tokenizer};
+
+const MARKERS: [Code; 5] = [
+ Code::Char(' '), // `hard_break_trailing`
+ Code::Char('&'), // `character_reference`
+ Code::Char('<'), // `autolink`, `html_text`
+ Code::Char('\\'), // `character_escape`, `hard_break_escape`
+ Code::Char('`'), // `code_text`
+];
/// Before text.
///
@@ -49,49 +58,11 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
}
}
-/// Before text.
-///
-/// We’re at data.
+/// At data.
///
/// ```markdown
/// |qwe
/// ```
fn before_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
- match code {
- Code::None => (State::Ok, None),
- Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => {
- tokenizer.enter(TokenType::LineEnding);
- tokenizer.consume(code);
- tokenizer.exit(TokenType::LineEnding);
- (State::Fn(Box::new(start)), None)
- }
- _ => {
- tokenizer.enter(TokenType::Data);
- tokenizer.consume(code);
- (State::Fn(Box::new(in_data)), None)
- }
- }
-}
-
-/// In data.
-///
-/// ```markdown
-/// q|w|e
-/// ```
-fn in_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
- match code {
- Code::None | Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => {
- tokenizer.exit(TokenType::Data);
- before_data(tokenizer, code)
- }
- // To do: somehow get these markers from constructs.
- Code::Char(' ' | '&' | '<' | '\\' | '`') => {
- tokenizer.exit(TokenType::Data);
- start(tokenizer, code)
- }
- _ => {
- tokenizer.consume(code);
- (State::Fn(Box::new(in_data)), None)
- }
- }
+ tokenizer.go(|t, c| data(t, c, MARKERS.to_vec()), start)(tokenizer, code)
}