prettier-browser-extension icon indicating copy to clipboard operation
prettier-browser-extension copied to clipboard

Feature request: ability to format code files hosted on github

Open fxnoob opened this issue 4 years ago • 9 comments

When I am on GitHub in some project directory .if that's a file say index.js then by clicking on some extensions option I should get that file content rerendered with prettier formatted code

fxnoob avatar Nov 26 '19 14:11 fxnoob

To be clear, do you mean a read-only display or within the file editor?

nickmccurdy avatar Nov 26 '19 14:11 nickmccurdy

@nickmccurdy In file editor, is ok to me. nice to have both. Screenshot 2019-11-26 at 10 05 28 PM eg file content shown should be formatted and rendered

fxnoob avatar Nov 26 '19 16:11 fxnoob

The former should we easy as we would just need to tweak how we detect text fields and make sure the button styles are appropriate in this toolbar. I'm not sure if we can reliably do the latter, as even if we supported read-only formatting, it could interfere with GitHub features like highlighting, selections, line/range links, and comments.

nickmccurdy avatar Nov 26 '19 16:11 nickmccurdy

if we supported read-only formatting, it could interfere with GitHub features like highlighting, selections, line/range links, and comments.

Good point. @nickmccurdy Maybe provide an option in content menu of chrome to get it formatted in the option page of this chrome extension

eg

Screenshot 2019-11-26 at 10 15 52 PM

fxnoob avatar Nov 26 '19 16:11 fxnoob

We're tracking that in #21

nickmccurdy avatar Nov 26 '19 16:11 nickmccurdy

Agreed with @nickmccurdy. I don’t think it’s a good idea to format read-only content. The overhead of reverse-engineering the DOM structure to work with GitHub’s scripts would be extremely difficult, with no guarantees that it’ll work at any given time.

kaicataldo avatar Nov 26 '19 17:11 kaicataldo

I'm okay with keeping this open to track support for GitHub's file editors.

nickmccurdy avatar Nov 26 '19 18:11 nickmccurdy

I did some investigating and this seems less straightfoward. The file editor is CodeMirror 6 (with gist.github.com, it is CodeMirror 5). From what I know about CodeMirror 6, it tracks state changes internally (not reading DOM), so a solution may require writing an extension. But I doubt GitHub has some mechanism for customizing CodeMirror editor extensions.

hyperupcall avatar Jan 15 '24 22:01 hyperupcall

@hyperupcall I think that's just for code editors, not discussion editors, right? We could shift focus to supporting discussion editors since GitHub's VSCode based editors (replacing code editors) already support Prettier.

nickmccurdy avatar Jan 15 '24 23:01 nickmccurdy