aboutsummaryrefslogtreecommitdiffstats
path: root/src/content/string.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/content/string.rs47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/content/string.rs b/src/content/string.rs
index f2650df..0a3f5eb 100644
--- a/src/content/string.rs
+++ b/src/content/string.rs
@@ -18,23 +18,26 @@ use crate::construct::{
};
use crate::tokenizer::{Code, State, StateFnResult, Tokenizer};
-const MARKERS: [Code; 5] = [
- // To do: build this vec based on whether they are enabled?
- Code::VirtualSpace, // `whitespace`
- Code::Char('\t'), // `whitespace`
- Code::Char(' '), // `whitespace`
- Code::Char('&'), // `character_reference`
- Code::Char('\\'), // `character_escape`
-];
-
/// Before string.
-///
-/// ```markdown
-/// |&
-/// |\&
-/// |qwe
-/// ```
pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ let mut markers = vec![
+ Code::VirtualSpace, // `whitespace`
+ Code::Char('\t'), // `whitespace`
+ Code::Char(' '), // `hard_break_trailing`, `whitespace`
+ ];
+
+ if tokenizer.parse_state.constructs.character_reference {
+ markers.push(Code::Char('&'));
+ }
+ if tokenizer.parse_state.constructs.character_escape {
+ markers.push(Code::Char('\\'));
+ }
+
+ before_marker(tokenizer, code, markers)
+}
+
+/// Before string.
+fn before_marker(tokenizer: &mut Tokenizer, code: Code, markers: Vec<Code>) -> StateFnResult {
match code {
Code::None => (State::Ok, None),
_ => tokenizer.attempt_n(
@@ -43,16 +46,16 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
Box::new(character_escape),
Box::new(whitespace),
],
- |ok| Box::new(if ok { start } else { before_data }),
+ |ok| {
+ let func = if ok { before_marker } else { before_data };
+ Box::new(move |t, c| func(t, c, markers))
+ },
)(tokenizer, code),
}
}
/// At data.
-///
-/// ```markdown
-/// |qwe
-/// ```
-fn before_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
- tokenizer.go(|t, c| data(t, c, MARKERS.to_vec()), start)(tokenizer, code)
+fn before_data(tokenizer: &mut Tokenizer, code: Code, markers: Vec<Code>) -> StateFnResult {
+ let copy = markers.clone();
+ tokenizer.go(|t, c| data(t, c, copy), |t, c| before_marker(t, c, markers))(tokenizer, code)
}