Intelligent text reformatting