Skip to content

[ty] Add a Copy Markdown button to playground#23002

Merged
MichaReiser merged 11 commits intoastral-sh:mainfrom
sinon:share-markdown-link-playground
Mar 13, 2026
Merged

[ty] Add a Copy Markdown button to playground#23002
MichaReiser merged 11 commits intoastral-sh:mainfrom
sinon:share-markdown-link-playground

Conversation

@sinon
Copy link
Contributor

@sinon sinon commented Jan 31, 2026

Summary

Closes: astral-sh/ty#2675

Adds dropdown from Share button:

  • three options
    • Copy link - existing share button functionality
    • Copy link as Markdown - copy just the link as markdown
    • Copy link and code as Markdown - copy link and code in relevant language fences as markdown
  • persists state to cloudflare worker (same as share)
  • builds a markdown formatted output from the url returned by state persist and open files
  • copies the created markdown to clipboard

Test Plan

  1. Run both servers locally with:
    • npm start --workspace ty-playground
    • npm start --workspace ruff-playground
  2. Disable the persist and set it's returned id to a static value (so as not to have to figure out how to run the Cloudfare thing locally) reasonable trade off since no code in that is being changed.
  3. Click relevant buttons
  4. Paste text into issue
  5. No unit / integration tests included as playground doesn't have any yet
image

Example markdown output

Code sample in ty playground

main.py

from typing import Literal

type Style = Literal["italic", "bold", "underline"]

# Add parameter annotations `line: str, word: str, style: Style` and a return
# type annotation `-> str` to see if you can find the mistakes in this program.

def with_style(line, word, style):
    if style == "italic":
        return line.replace(word, f"*{word}*")
    elif style == "bold":
        return line.replace(word, f"__{word}__")

    position = line.find(word)
    output = line + "\n"
    output += " " * position
    output += "-" * len(word)


print(with_style("ty is a fast type checker for Python.", "fast", "underlined"))

ty.json

{
    "environment": {
        "python-version": "3.14"
    },
    "rules": {
        "undefined-reveal": "ignore"
    }
}

return "python";
case "json":
return "json";
case "toml":
Copy link
Contributor Author

@sinon sinon Jan 31, 2026

Choose a reason for hiding this comment

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

I don't think the ty.toml is yet supported by the playground so this is just some future proofing for it does get included the export till still looks right

@sinon sinon marked this pull request as ready for review January 31, 2026 15:50
@AlexWaygood AlexWaygood added playground A playground-specific issue ty Multi-file analysis & type inference labels Feb 2, 2026
@sharkdp
Copy link
Contributor

sharkdp commented Feb 3, 2026

Thank you for looking into this!

In general, this seems like a useful feature to have, but personally, I think it would be nice not to have multiple "share" buttons? Especially if we consider having both "Markdown with link" and "Markdown with link and code" functionality like in astral-sh/ty#2675. I'm not really familiar with our frontend code here, but maybe we have some dropdown-like components that would allow us to hide those three options in the main UI?

The playground was designed by @MichaReiser who is currently on an extended leave. We might want to wait for his return in March before we continue with this.

@sinon
Copy link
Contributor Author

sinon commented Feb 3, 2026

In general, this seems like a useful feature to have, but personally, I think it would be nice not to have multiple "share" buttons? Especially if we consider having both "Markdown with link" and "Markdown with link and code" functionality like in astral-sh/ty#2675. I'm not really familiar with our frontend code here, but maybe we have some dropdown-like components that would allow us to hide those three options in the main UI?

Yeah I agree, I wasn't convinced by having two Share buttons side-by-side either but opted for the simpler approach to get a direction check instead of implementing the more complex UX out the door and have that fall flat 😅

Good to know, I will try and get a proposal for a drop-down like component (and maybe the other modes too) ready for when Micha returns (unless someone else feels brave enough to review frontend code in the meantime 😆)

@sharkdp
Copy link
Contributor

sharkdp commented Feb 3, 2026

Good to know, I will try and get a proposal for a drop-down like component (and maybe the other modes too) ready for when Micha returns (unless someone else feels brave enough to review frontend code in the meantime 😆)

Thank you. I mainly want to make sure that you do not invest time into something that might eventually be rejected.

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.

Thanks. This is great. We should include this in Ruff too.

sinon and others added 10 commits March 13, 2026 10:23
`Copy Markdown` button:
- persists state to cloudflare worker (same as share)
- builds a markdown formatted output from the url returned by state persist and open files
- copies the markdown to clipboard
@MichaReiser MichaReiser force-pushed the share-markdown-link-playground branch from 0e4a7dc to e64c412 Compare March 13, 2026 10:43
@MichaReiser MichaReiser changed the title [ty] Add a Copy Markdown button to playground - astral-sh/ty#2675 [ty] Add a Copy Markdown button to playground Mar 13, 2026
@MichaReiser MichaReiser enabled auto-merge (squash) March 13, 2026 10:51
@MichaReiser MichaReiser merged commit 2e70459 into astral-sh:main Mar 13, 2026
42 checks passed
carljm added a commit that referenced this pull request Mar 13, 2026
* main: (94 commits)
  Fix shell injection via `shell=True` in subprocess calls (#23894)
  [ty] Refactor `relation.rs` to store state on a struct rather than passing around 7 arguments every time we recurse (#23837)
  Don't return code actions for non-Python documents (#23905)
  [ty] Make the default database truly statically infallible (#23929)
  [ty] Add `Download` button to ty playground which creates a zip export (#23478)
  [ty] Respect `kw_only` overwrites in dataclasses (#23930)
  [ty] Clarify in diagnostics that `from __future__ import annotations` only stringifies type annotations (#23928)
  [ty]  Add a `Copy Markdown` button to playground (#23002)
  [ty] Fix folding range classification of lines starting with `#` (#23831)
  [ty] Fix folding ranges for notebooks (#23830)
  [ty] fix too-many-cycle panics when inferring literal type loop variables (#23875)
  Add `RegularCallableTypeOf` and `into_regular_callable` in `ty_extensions` (#23909)
  [ty] treat properties as full structural types (#23925)
  [ty] Avoid duplicated work during multi-inference (#23923)
  [ty]: make `possibly-missing-attribute` ignored by default
  [ty]: split out `possibly-missing-submodule` from `possibly-missing-attribute`
  Update astral-sh/setup-uv action to v7.5.0 (#23922)
  [ty] Show truthiness in ConstraintSet display and simplify falsy error message (#23913)
  Bump 0.15.6 (#23919)
  [ty] Narrow type context during collection literal inference (#23844)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

playground A playground-specific issue ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

playground: offer "copy markdown with link" button

4 participants