kivikakk / comrak

CommonMark + GFM compatible Markdown parser and renderer
Other
1.17k stars 140 forks source link

[feature request] Make copy-paste preserve markdown on generated HTML #403

Closed mrdomino closed 4 months ago

mrdomino commented 4 months ago

If someone copies and pastes a span of text that has been run through the formatter from a web page, the resulting text will have lost most markdown formatting for things like bold, emphasis, code, etc.

It seems like a way around this would be to do something like:

Source:

Some `code` block

Result:

<!doctype html>
<style>.hide{font-size:0}</style>
Some <span class="hide">`</span><code>code</code><span class="hide">`</span> block

The idea being that the markdown formatting characters are hidden in the resulting text, but show up again if copied and pasted.

gjtorikian commented 4 months ago

It's an interesting idea, but I feel this would be better managed via a post-HTML processing pipeline, or JavaScript, rather than adding more features to the library.

mrdomino commented 4 months ago

All right, how would that work?

Or I guess, to get to the root of it, where would I go to make this feature request against Github? The main thing is I want to be able to do that on this site.

gjtorikian commented 4 months ago

I'd recommend contacting GitHub Support for a feature request.

However, note that GitHub does have this feature somewhat implemented:

https://github.com/kivikakk/comrak/assets/64050/25b5eadd-ef2b-4b94-828d-31f3c02026f6

If you highlight any issue comment and press r, the original Commonmark/Markdown text is copied to your clipboard and set as a new response. There may be some more appropriate key command for the task you're trying to accomplish, but as neither myself nor @kivikakk work for GitHub we're not really able to provide more help there.

I'm going to close this as the issue isn't specific to comrak, but do feel free to keep the conversation going if you have other questions.

mrdomino commented 4 months ago

That's neat, I didn't know about it and will use that in future.

Fwiw (not that it's either here or there as this is clearly out of scope for this project), I was hoping for something more ~idiot-proof~ user-friendly; the issue I'm having isn't that I'm failing to copy markdown formatting, it's that markdown formatting is failing to get copied by others who quote me in the obvious way of drag-selecting some text from my comments.

gjtorikian commented 4 months ago

Ah, yeah, unfortunately software cannot always solve for human behavior. I wouldn’t be surprised if there’s a browser extension you can install that supports the UX you’re looking for.

kivikakk commented 4 months ago

Or I guess, to get to the root of it, where would I go to make this feature request against Github?

@mrdomino Out of curiosity, what led you to this repository? It's always interesting to hear how folks find it.

mrdomino commented 4 months ago

I looked at the official GitHub discussions, saw no place that seemed like it’d fit, saw no implementation links on the GitHub flavored markdown spec, and wound up here via commonmarker via googling something like “what markdown implementation does GitHub use.”