Skip to content

Parsing inline code span with a single newline loses the newline #655

Description

@mgeisler

According to the Commonmark playground and the Commonmark spec, the string

"`\n`"

should be parsed into

[Start(Paragraph)Code(" ")End(Paragraph)]

since newline is normalized as a space.

However, when parsing the string with pulldown-cmark 0.9.3, I get

[Start(Paragraph)Code("")End(Paragraph)]

instead. I used this little test program:

use pulldown_cmark::{Event,Parser};fnmain(){let text = "`\n`";eprintln!("{text:?} -> [");for event inParser::new(&text){match event {Event::Code(code) => eprintln!(" Code({:?})",&*code),
_ => eprintln!(" {event:?}"),}}eprintln!("]");}

Note that "`foo\n`" and "`\nfoo`" are parsed correctly with a trailing and leading space, respectively.

I found this while trying round-trip strings through pulldown-cmark-to-cmark (Byron/pulldown-cmark-to-cmark#55).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions