summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Erik Rediger <janerik@fnordig.de>2023-05-15 21:11:38 +0200
committerJan-Erik Rediger <janerik@fnordig.de>2023-05-15 21:21:06 +0200
commitc9484d562e21e1d6fd779a062f25414f3fa42a6f (patch)
tree9a04ec788461f73496c60054523a1faf9be78d6c
parentc78210ea72deaea938c8947ab1bec24b14653ea2 (diff)
Always convert CRLF into LF-only line endings.
CRLF lineendings will happen on Windows, but they shouldn't matter for Markdown content. pulldown-cmark will parse them _nearly_ the same. `<!-- toc -->\r\n` will actually be 2 HTML elements: the `<!-- toc -->` part and a `\n` part, whereas `<!-- toc -->\n` will be just one: `<!-- toc -->\n`. That throws off our marker parser because we're looking for the latter only. So by stripping our the CR (`\r`) we don't need to special-case anything. The rendering will be the same. Closes #35
-rw-r--r--src/lib.rs2
-rw-r--r--tests/it.rs5
2 files changed, 7 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 958a2c9..d5f8009 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -149,10 +149,12 @@ fn add_toc(content: &str, cfg: &Config) -> Result<String> {
opts.insert(Options::ENABLE_TASKLISTS);
let mark: Vec<Event> = Parser::new(&cfg.marker).collect();
+ log::trace!("Marker: {:?}", mark);
let mut mark_start = None;
let mut mark_end = 0..0;
let mut mark_loc = 0;
+ let content = content.replace("\r\n", "\n");
for (e, span) in Parser::new_ext(&content, opts).into_offset_iter() {
log::trace!("Event: {:?} (span: {:?})", e, span);
if !toc_found {
diff --git a/tests/it.rs b/tests/it.rs
index 7101ded..4ee922c 100644
--- a/tests/it.rs
+++ b/tests/it.rs
@@ -164,3 +164,8 @@ fn empty_document() {
// Empty documents should not fail
assert_toc!("empty_document");
}
+
+#[test]
+fn crlf() {
+ assert_toc!("crlf");
+}