A simple ruby script which tries to properly format code blocks copied from the Kindle for Mac application. I was ramping up on android using a Kindle book and realized the app does a terrible job of copy/pasting contents to an IDE/text editor. This script reads the contents of your clipboard and applies some basic formatting logic then replaces the contents of your clipboard with (somewhat) better formatted code. Not perfect, but made my life a little easier.
1- Install clipboard gem:
gem install clipboard
2- Go to your Kindle app copy a block of code (only xml and java supported for now)
3- Run the kindle_fmt script from your terminal.
4- The contents of your clipboard should contain newly formatted code.
Script will try to detect if you're pasting xml or java. You can explicitly tell the script how to treat the text. Ex:
- To make your life easier, add the git repo folder to your path so you can run this from anywhere: (In ~/.bashrc or ~/.zshrc)
- You could probably bind this script to a hotkey combo to make life even easier. Kind of annoying having to go to the terminal to apply formatting.
- Get Amazon to fix formatting int heir app. Its turrrrible.
- My formatting rules are super basic and don't cover corner cases well at all. Feel free to improve.
- Add support for more languages\syntax.