Skip to content

Commit

Permalink
Merge pull request #1019 from jfbercher/code_prettify
Browse files Browse the repository at this point in the history
[code_prettify] added support for IPython magics, cf #1018
  • Loading branch information
jfbercher authored Jul 14, 2017
2 parents 51c04d3 + cf7562f commit 0a24d76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Name: 2to3 Converter
Description: Converts python2 code in a notebook's code cell to python3 code
Link: README_2to3.md
Main: 2to3.js
Compatibility: Jupyter (4.x)
Compatibility: Jupyter 4.x, 5.x
Parameters:

- name: 2to3.add_toolbar_button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Name: Autopep8
Description: Use kernel-specific code to reformat/prettify the contents of code cells
Link: README_autopep8.md
Main: autopep8.js
Compatibility: Jupyter (4.x)
Compatibility: Jupyter 4.x, 5.x
Parameters:

- name: autopep8.add_toolbar_button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ define(function(require, exports, module) {

cfg.kernel_config_map = { // map of parameters for supported kernels
"python": {
"library": "import json\nimport yapf.yapflib.yapf_api",
"prefix": "print(json.dumps(yapf.yapflib.yapf_api.FormatCode(u",
"postfix": ")[0]))"
"library": ["import json",
"def yapf_reformat(cell_text):",
" import yapf.yapflib.yapf_api",
" import re",
" cell_text = re.sub('^%', '#%#', cell_text, flags=re.M)",
" reformated_text = yapf.yapflib.yapf_api.FormatCode(cell_text)[0]",
" return re.sub('^#%#', '%', reformated_text, flags=re.M)"].join("\n"),
"prefix": "print(json.dumps(yapf_reformat(u",
"postfix": ")))"
},
"r": {
"library": "library(formatR)\nlibrary(jsonlite)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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)
Compatibility: Jupyter 4.x, 5.x
Parameters:

- name: code_prettify.add_toolbar_button
Expand Down Expand Up @@ -55,7 +55,7 @@ Parameters:
default: |
{
"python": {
"library": "import json\nimport yapf.yapflib.yapf_api",
"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.yapflib.yapf_api.FormatCode(u",
"postfix": ")[0]))"
},
Expand Down

0 comments on commit 0a24d76

Please sign in to comment.