Skip to content

[ty] Implement support for explicit markdown code fences in docstring rendering#22373

Merged
Gankra merged 3 commits intomainfrom
gankra/markdown-fail
Jan 5, 2026
Merged

[ty] Implement support for explicit markdown code fences in docstring rendering#22373
Gankra merged 3 commits intomainfrom
gankra/markdown-fail

Conversation

@Gankra
Copy link
Contributor

@Gankra Gankra commented Jan 4, 2026

@Gankra Gankra added the server Related to the LSP server label Jan 4, 2026
@Gankra Gankra requested a review from carljm as a code owner January 4, 2026 19:07
@Gankra Gankra added the ty Multi-file analysis & type inference label Jan 4, 2026
@Gankra Gankra added the internal An internal refactor or improvement label Jan 4, 2026
AlexWaygood
AlexWaygood previously approved these changes Jan 4, 2026
@Gankra Gankra changed the title [ty] checkin snapshot test for bad result on markdown fences in doctests [ty] Add support for explicit markdown code fences in docstrings Jan 4, 2026
@Gankra Gankra removed the internal An internal refactor or improvement label Jan 4, 2026
@Gankra
Copy link
Contributor Author

Gankra commented Jan 4, 2026

Upgraded this into implementing a solution.

@Gankra Gankra changed the title [ty] Add support for explicit markdown code fences in docstrings [ty] Implement support for explicit markdown code fences in docstring rendering Jan 4, 2026
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

I think we should add support for ~~~ too. While less common, it is part of the markdown standard.

}

// If we're not in a codeblock and we see a markdown codefence, start one
if !in_any_code && line.starts_with("```") {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also add support for ~~~ (spec)

}

// If we're not in a codeblock and we see a markdown codefence, start one
if !in_any_code && line.starts_with("```") {
Copy link
Member

Choose a reason for hiding this comment

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

Code blocks can also be indented (but that's maybe something for another PR) spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expect that one will remain out of scope because python people love random indents in their docstrings and it's a struggle to disambiguate "are we markdown or just some text".

let ticks = &line[..num_ticks];
// If we don't see this amount of ticks again on the line, assume we're opening a markdown block
// (We *don't* want to consider ```hello``` as a codefence, that's inline code!)
if !without_leading_ticks.contains(ticks) {
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't know that you can use multiple backticks for inline code

Copy link
Contributor Author

@Gankra Gankra Jan 5, 2026

Choose a reason for hiding this comment

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

Yeah in both reST and markdown! In python docstrings there's a soft convention of `x` and ``x`` being used for different purposes (similar to `x` and [`x`] in rustdoc).

@AlexWaygood AlexWaygood dismissed their stale review January 5, 2026 08:33

My approval was when this PR only added a test

@Gankra
Copy link
Contributor Author

Gankra commented Jan 5, 2026

tilde fences added

@Gankra Gankra merged commit e63cf97 into main Jan 5, 2026
44 checks passed
@Gankra Gankra deleted the gankra/markdown-fail branch January 5, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code blocks opening and closing backticks don't match

3 participants