pinnwand icon indicating copy to clipboard operation
pinnwand copied to clipboard

Download feature should use the language selected for the file

Open janine9vn opened this issue 1 year ago • 3 comments

Currently, if you download a paste it will use a .txt extension for all files regardless of the language selected: https://github.com/supakeen/pinnwand/blob/master/src/pinnwand/handler/website.py#L495-L500

It would be nice if the file downloaded with the extension of the language selected instead. For example a file with the Python language selected would download as a .py file.

This should be not too bad to implement with being able to peak at the lexer used for the filename and then using pygments.get_lexer_get_name() and then .filenames to get the available extensions. (Thanks @ChrisLovering for the assist on this)

janine9vn avatar Jun 04 '23 20:06 janine9vn

Just a note to whoever implements this (if it's approved) .filenames is an optional list of valid file names, so you would need to derive the extension from one of those, rather than being able to use it directly.

The Extensions(s) column of this language table is what I believe pygements stores in the .filenames attribute

ChrisLovering avatar Jun 04 '23 20:06 ChrisLovering

My main 'issue' with this functionality is that while useful for code editors and such it also allows users to download files that might then become /clickable/ on their desktop or downloads folder. The initial reason for always going for .txt was to prevent that from happening.

I could likely be convinced on setting the filename based on the lexer in use if that's not considered to be a problem :)

supakeen avatar Jun 05 '23 08:06 supakeen

I definitely see the concern with downloading a file and having it be run-able with an accidental click. If the files are zipped up in an archive that reduces the chances of that accidental click happening and so having the extensions be the appropriate one for the selected language should be fine in that case.

The single file downloads though would still present an issue, so unsure how to approach that and still have a unified experience for people.

janine9vn avatar Jun 09 '23 03:06 janine9vn