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:
parent
c78210ea72
commit
c9484d562e
|
@ -149,10 +149,12 @@ fn add_toc(content: &str, cfg: &Config) -> Result<String> {
|
||||||
opts.insert(Options::ENABLE_TASKLISTS);
|
opts.insert(Options::ENABLE_TASKLISTS);
|
||||||
|
|
||||||
let mark: Vec<Event> = Parser::new(&cfg.marker).collect();
|
let mark: Vec<Event> = Parser::new(&cfg.marker).collect();
|
||||||
|
log::trace!("Marker: {:?}", mark);
|
||||||
let mut mark_start = None;
|
let mut mark_start = None;
|
||||||
let mut mark_end = 0..0;
|
let mut mark_end = 0..0;
|
||||||
let mut mark_loc = 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() {
|
for (e, span) in Parser::new_ext(&content, opts).into_offset_iter() {
|
||||||
log::trace!("Event: {:?} (span: {:?})", e, span);
|
log::trace!("Event: {:?} (span: {:?})", e, span);
|
||||||
if !toc_found {
|
if !toc_found {
|
||||||
|
|
|
@ -164,3 +164,8 @@ fn empty_document() {
|
||||||
// Empty documents should not fail
|
// Empty documents should not fail
|
||||||
assert_toc!("empty_document");
|
assert_toc!("empty_document");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn crlf() {
|
||||||
|
assert_toc!("crlf");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue