dart-lang / markdown

A Dart markdown library
https://pub.dev/packages/markdown
BSD 3-Clause "New" or "Revised" License
440 stars 200 forks source link

`Copy Code` Button #572

Closed Number-3434 closed 3 months ago

Number-3434 commented 5 months ago

Please add a button to copy code in code spans in markdown documentation comments.

Like the following:

/// There is a copy code button to the right!
void insubstantialMethod() { ... }

Also open here.

DanTup commented 5 months ago

Adding a way to copy the code is something that would need to be done in the IDE extension (https://github.com/Dart-Code/Dart-Code/issues/4939). There's nothing specific to do here in the markdown package besides the existing request for offsets/lengths in parsed results (https://github.com/dart-lang/markdown/issues/369).

(I think we should close this as a dupe of those issues)

jonasfj commented 3 months ago

This exists on pub.dev, I don't see how it's related to markdown parsing.

If you're suggesting it be done in generated documentation, that's an issue for dartdoc.

We did on pub.dev using javascript to find the code tags that should have a copy button added.

DanTup commented 3 months ago

The request here was about allowing it in the IDE (eg. code blocks inside doc comments can easily be copied). To do this, we need to reliably know the offset/lengths of the code blocks within the doc comments (while we could approximate this with regex, it should really be done with real parsing).