-
Notifications
You must be signed in to change notification settings - Fork 244
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
Format code with prettier #34
Comments
Seems that overflow is giving you trouble? Try setting “white-space: pre-wrap;” or use “overflow-x: scroll” |
@siddharthkp itd be great to have as an opt-in feature 😬 I’m sure not everyone will need it. But I wanted to look into Babel-standalone / custom transpilers anyway, so this would fit right in |
Good point. I have no idea what that would look like to be able to help 🙁 If you point me in the right direction, I can give it a shot (after finishing my styleguide) |
sorry for the unrelated question, but I was curious how are you injecting the props like that? |
@tgreen7 here's the bad code if you want to read through: https://github.com/auth0/cosmos/blob/master/src/docs/spec/playground.js |
Hey @siddharthkp ! |
@Flo-Slv Here's some hacky code to make it happen: |
@siddharthkp thanks! but doesn't work, i've got this error that i don't understand. I have see discussions on prettier repos to integrate prettier on browser. |
If anyone stumbles across this thread, here is how i integrated it with import prettier from 'prettier/standalone'
import babelParser from 'prettier/parser-babylon' Then inside your wrapper component: ...
const [code, setCode] = useState(")
const formatOnKey = (e: KeyboardEvent) => {
if (e.ctrlKey && e.keyCode == 76) {
setCode(currentCode =>
prettier.format(currentCode, {
parser: 'babel',
plugins: [babelParser]
}))
}
}
useEffect(() => {
document.addEventListener('keyup', formatOnKey, false)
return () => document.removeEventListener('keyup', formatOnKey, false)
})
... if you want to do it with a button or something, just use |
Thanks @masterpavan ! For me the following worked:
for applying prettier by default. Works with |
When modifying code on the fly, it would be very useful to have prettier format the code.
I'd be happy to solve my own problem if someone can guide on how to use prettier on the browser.
This is the problem:
The text was updated successfully, but these errors were encountered: