1
Fork 0

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
This commit is contained in:
Jan-Erik Rediger 2023-05-15 21:11:38 +02:00
parent c78210ea72
commit c9484d562e
2 changed files with 7 additions and 0 deletions

View file

@ -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 {

View file

@ -164,3 +164,8 @@ fn empty_document() {
// Empty documents should not fail
assert_toc!("empty_document");
}
#[test]
fn crlf() {
assert_toc!("crlf");
}