aboutsummaryrefslogtreecommitdiffstats
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-08 17:16:24 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-08 17:16:24 +0200
commitf5b6e828d5f3b698b150ba4a0831b61574c6cc3b (patch)
treee9de59d824e2b4c68264437c05258fb2384fb809 /src/tokenizer.rs
parentc1b325a6dcf4bb8795dd2e5b2cdb1dcfcf61faf5 (diff)
downloadmarkdown-rs-f5b6e828d5f3b698b150ba4a0831b61574c6cc3b.tar.gz
markdown-rs-f5b6e828d5f3b698b150ba4a0831b61574c6cc3b.tar.bz2
markdown-rs-f5b6e828d5f3b698b150ba4a0831b61574c6cc3b.zip
Fix positional info on line ending after shift
Diffstat (limited to '')
-rw-r--r--src/tokenizer.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index dcbcb09..c984a75 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -346,19 +346,32 @@ impl<'a> Tokenizer<'a> {
);
let previous = self.events.last().expect("cannot close w/o open event");
- let point = self.point.clone();
+ let mut index = self.index;
+ let mut point = self.point.clone();
assert!(
- current_token != previous.token_type || previous.index != self.index,
+ current_token != previous.token_type || previous.index != index,
"expected non-empty token"
);
- log::debug!("exit `{:?}` ({:?})", token_type, self.point);
+ // A bit weird, but if we exit right after a line ending, we *don’t* want to consider\
+ // potential skips.
+ if matches!(
+ self.previous,
+ Code::CarriageReturnLineFeed | Code::Char('\n' | '\r')
+ ) {
+ let shift = point.column - 1;
+ point.column -= shift;
+ point.offset -= shift;
+ index -= shift;
+ }
+
+ log::debug!("exit `{:?}` ({:?})", token_type, point);
self.events.push(Event {
event_type: EventType::Exit,
token_type,
point,
- index: self.index,
+ index,
previous: None,
next: None,
content_type: None,