From c9484d562e21e1d6fd779a062f25414f3fa42a6f Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Mon, 15 May 2023 21:11:38 +0200 Subject: 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. `\r\n` will actually be 2 HTML elements: the `` part and a `\n` part, whereas `\n` will be just one: `\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 --- src/lib.rs | 2 ++ tests/it.rs | 5 +++++ 2 files changed, 7 insertions(+) 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 { opts.insert(Options::ENABLE_TASKLISTS); let mark: Vec = 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"); +} -- cgit v1.2.3