-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser extension: Format JS code blocks with Prettier #99
Comments
This could be useful for any code block on the web, not just on GitHub. |
Generally the problem I've found is that sometimes broken code blocks also lack any language marking so unless "JavaScript" is specified, this extension can't do anything. |
I often encounter blog posts with code examples using a bad and inconsistent code style but which is still correctly syntax highlighted. |
Maybe that can be solved with a button to format code when needed in case the language mode isn't specified |
I have created a very raw implementation, it basically reformats every |
It will be great if this extension exists for firefox and safari also. You can use https://github.com/EmailThis/extension-boilerplate for that (I am not related to that project). I had started to build it but found that @wasd171 is already doing it. So I thought I will just share the ideas I had.
I have no idea how to get the language of code if its not available. So maybe in that case we can give a select box at the top right of the code block to select from prettier supported languages or just the Enhancement : Support code highlighting using highlight.js. It can be easily detected most of the times if the code is syntax highlighted or not using the HTML tags in the code block. @wasd171 Let me know if you need any help. |
@ritz078 Thank you for your ideas! Unfortunately I am in the middle of my finals (for the whole August), so I can't actively contribute. Right now it tries to reformat the code and keeps the original if prettier fails with error. Does prettier autodetect the language? If so, perhaps it would be possible to extract this information afterwards? Modifying Medium-style code blocks looks hard, it is probably needed to parse the HTML structure to get the code string. But perhaps if a such two-way parser can be created, afterwards the extension can fill formatted HTML back and get "native" highlighting. |
Prettier is pretty biased. Formatting code with it can lead to code looking different than what is in the actual source. Or am I missing something here? |
I created a Darker-Medium extension that formats code blocks on Medium sites. All I had to do was target all |
It exists a GitHub App for your own repos (https://github.com/jgierer12/prettier-github) but it might be useful as a browser extension.
The text was updated successfully, but these errors were encountered: