Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/generation/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ fn gen_code_block(code_block: &CodeBlock, context: &mut Context) -> PrintItems {
}
}

fn gen_code(code: &Code, _: &mut Context) -> PrintItems {
fn gen_code(code: &Code, context: &mut Context) -> PrintItems {
let text = code.code.trim();
let mut backtick_text = "`";
let mut separator = "";
Expand All @@ -444,7 +444,8 @@ fn gen_code(code: &Code, _: &mut Context) -> PrintItems {
}
}

format!("{0}{1}{2}{1}{0}", backtick_text, separator, text).into()
let full_string = format!("{0}{1}{2}{1}{0}", backtick_text, separator, text);
gen_str(&full_string, context)
}

fn gen_text(text: &Text, context: &mut Context) -> PrintItems {
Expand Down
21 changes: 21 additions & 0 deletions tests/specs/Code/Code_Inline_TextWrap_Always.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ Testing

[expect]
Testing `this` out.

!! should wrap inline code across lines !!
Testing `this
out`.

[expect]
Testing `this out`.

!! should rewrap inline code across lines in blockquote !!
> Testing `this
> out`.

[expect]
> Testing `this out`.

!! should rewrap inline code across lines which are too long in blockquote !!
> This is some long text, which will have a bit of inline code across the `80 character limit` and then more after that.

[expect]
> This is some long text, which will have a bit of inline code across the `80
> character limit` and then more after that.
Comment on lines +29 to +41
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovered this failure mode while testing this PR against the Rust book, where there are a few of these. Should hopefully have a fix in for this tomorrow morning!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving some breadcrumbs here for myself, given I do not expect to get back to this till January—I spent some time chasing this (after beating my head against the wall that is getting useful debugging set up for Rust 😑) and concluded so far that it is down to something amiss in how dprint-plugin-markdown is using the result of parsing from pulldown-cmark, but haven’t gotten further than that.

Specifically, it ends up seeing an inline code snippet that wraps across a line in a blockquote as including the > character. It will correctly introduce the wrapping for a too-long line, but is not stable because once it has done so, on the next formatting pass it will then interpret it as part of the inline code instead of as a blockquote marker.

A side observation: this is just a challenging issue. Here is a simple sample that I used for testing pulldown-cmark itself locally:

> This is some `inline
> code`. And it gets
> *rendered* just fine.
> The problem is thus
> not `pulldown-cmark`
> but something in how
> `dprint` uses it.

Notice how GitHub’s (line-wrapping-aware) renderer trips in a different way over the exact same thing, not wrapping when it should:

This is some inline code. And it gets
rendered just fine.
The problem is thus
not pulldown-cmark
but something in how
dprint uses it.