Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code_prettify] added support for IPython magics, cf #1018 #1019

Merged
merged 2 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 +25,20 @@ 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)",
"prefix": "cat(paste(tidy_source(text=",
"postfix": ")[['text.tidy']], collapse='\n'))"
"prefix": "cat(toJSON(paste(tidy_source(text=",
"postfix": ", output=FALSE)[['text.tidy']], collapse='\n')))"
},
"javascript": {
"library": "jsbeautify = require(" + "'js-beautify')",
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,14 +55,14 @@ 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]))"
},
"r": {
"library": "library(formatR)\nlibrary(jsonlite)",
"prefix": "cat(paste(tidy_source(text=",
"postfix": ")[['text.tidy']], collapse='\n'))"
"prefix": "cat(toJSON(paste(tidy_source(text=",
"postfix": ", output=FALSE)[['text.tidy']], collapse='\n')))"
},
"javascript": {
"library": "jsbeautify = require('js-beautify')",
Expand Down