Refactor JS string prettyprinting