Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: Prevent fully defined links [name](link) from being reformatted #10442

Merged
merged 1 commit into from Mar 18, 2024

Conversation

augustelalande
Copy link
Contributor

Summary

Currently fully define markdown links which include ticks are being reformatted by

let documentation = Regex::new(r"\[`([^`]*?)`]($|[^\[])").unwrap().replace_all(
documentation,
|caps: &Captures| {
format!(
"[`{option}`][{option}]{sep}",
option = &caps[1],
sep = &caps[2]
)
},
);

[`name`](link) -> [`name`][name](link)

For example: https://docs.astral.sh/ruff/rules/typed-argument-default-in-stub/

This PR excludes the open parentheses from the regex, so that these types of links won't be reformatted.

Test Plan

Extended the regression test.

@augustelalande augustelalande changed the title Bug fix: Prevent fully defineds links [name](link) from being reformatted Bug fix: Prevent fully defined links [name](link) from being reformatted Mar 18, 2024
@augustelalande augustelalande changed the title Bug fix: Prevent fully defined links [name](link) from being reformatted Bug fix: Prevent fully defined links [\name\](link) from being reformatted Mar 18, 2024
@augustelalande augustelalande changed the title Bug fix: Prevent fully defined links [\name\](link) from being reformatted Bug fix: Prevent fully defined links [name](link) from being reformatted Mar 18, 2024
Copy link

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh
Copy link
Member

Does the example in https://docs.astral.sh/ruff/rules/typed-argument-default-in-stub/ now render correctly? I think this hack exists because MkDocs wasn't respecting backticks within URLs.

@augustelalande
Copy link
Contributor Author

augustelalande commented Mar 18, 2024

It does work. Although looking again at #280 I'm not sure why.
image

@charliermarsh
Copy link
Member

Is it possible that something changed in MkDocs?

@augustelalande
Copy link
Contributor Author

Wait actually this always worked even in Python-Markdown/markdown#280

>>> markdown.markdown('[`hello`](world)')
'<p><a href="world"><code>hello</code></a></p>'

@augustelalande
Copy link
Contributor Author

augustelalande commented Mar 18, 2024

What doesn't work is empty references with code formatting, so the proposed fix is reasonable.

>>> markdown.markdown('[`hello`][]\n\n[`hello`]: world')
'<p>[<code>hello</code>][]</p>'

And actually the current implementation doesn't address Python-Markdown/markdown#280

@charliermarsh
Copy link
Member

Oh right, I think the motivating case was specifically about reference links.

@charliermarsh charliermarsh merged commit 91e8141 into astral-sh:main Mar 18, 2024
17 checks passed
@charliermarsh charliermarsh added bug Something isn't working documentation Improvements or additions to documentation labels Mar 18, 2024
@augustelalande augustelalande deleted the minor-doc-bug branch March 18, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants