Skip to content

Commit

Permalink
[code_prettify] added support for IPython magics, cf ipython-contrib#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbercher committed Jul 8, 2017
1 parent e80e0c4 commit 0e2f74d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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 @@ -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

0 comments on commit 0e2f74d

Please sign in to comment.