Type: Jupyter Notebook Extension Name: Code prettify Description: Use kernel-specific code to reformat/prettify the contents of code cells Link: README_code_prettify.md Main: code_prettify.js Compatibility: Jupyter 4.x, 5.x Parameters: - name: code_prettify.add_toolbar_button description: Add a toolbar button to prettify the selected cell(s) input_type: checkbox default: true - name: code_prettify.button_icon description: | Toolbar button icon: a font-awesome class defining the icon used for the toolbar button and actions. See https://fontawesome.com/icons for available icons. input_type: text default: 'fa-legal' - name: code_prettify.button_label description: Toolbar button label text input_type: text default: 'Code prettify' - name: code_prettify.register_hotkey description: | Register hotkeys to prettify the selected code cell(s), or all code cells in the notebook input_type: checkbox default: true - name: code_prettify.hotkeys.process_selected description: Hotkey to use to prettify the selected cell(s) input_type: hotkey default: 'Ctrl-L' - name: code_prettify.hotkeys.process_all description: Hotkey to use to prettify the whole notebook input_type: hotkey default: 'Ctrl-Shift-L' - name: code_prettify.show_alerts_for_not_supported_kernel description: Show alerts if the kernel is not supported input_type: checkbox default: false - name: code_prettify.show_alerts_for_errors description: Show alerts for errors in the kernel prettifying calls input_type: checkbox default: true - name: code_prettify.kernel_config_map_json description: | json defining library calls required to load the kernel-specific prettifying modules, and the prefix & postfix for the json-format string required to make the prettifying call. input_type: textarea default: | { "python": { "library": "import json\ndef yapf_reformat(cell_text):\n import yapf.yapflib.yapf_api\n import re\n cell_text = re.sub('^%', '#%#', cell_text, flags=re.M)\n reformated_text = yapf.yapflib.yapf_api.FormatCode(cell_text)[0]\n return re.sub('^#%#', '%', reformated_text, flags=re.M)", "prefix": "print(json.dumps(yapf_reformat(u", "postfix": ")))" }, "r": { "library": "library(formatR)\nlibrary(jsonlite)", "prefix": "cat(toJSON(paste(tidy_source(text=", "postfix": ", output=FALSE)[['text.tidy']], collapse='\n')))" }, "javascript": { "library": "jsbeautify = require('js-beautify')", "prefix": "console.log(JSON.stringify(jsbeautify.js_beautify(", "postfix": ")));" } }