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

Jupyter notebook cell contents saved in source codes #29

Open
PSSF23 opened this issue Oct 10, 2020 · 2 comments
Open

Jupyter notebook cell contents saved in source codes #29

PSSF23 opened this issue Oct 10, 2020 · 2 comments

Comments

@PSSF23
Copy link

PSSF23 commented Oct 10, 2020

Environment:

  • python: 3.8.5
  • notebook: 6.1.3
  • nb-black: 1.0.7

Description:
When running nb-black in jupyter notebooks, the following type of codes would be added to every cell that has been reformatted.

   "outputs": [
    {
     "data": {
      "application/javascript": [
       "\n",
       "            setTimeout(function() {\n",
       "                var nbb_cell_id = 1;\n",
       "                var nbb_unformatted_code = \"%load_ext nb_black\";\n",
       "                var nbb_formatted_code = \"%load_ext nb_black\";\n",
       "                var nbb_cells = Jupyter.notebook.get_cells();\n",
       "                for (var i = 0; i < nbb_cells.length; ++i) {\n",
       "                    if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
       "                        if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
       "                             nbb_cells[i].set_text(nbb_formatted_code);\n",
       "                        }\n",
       "                        break;\n",
       "                    }\n",
       "                }\n",
       "            }, 500);\n",
       "            "
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],

It repeats the cell contents twice and fortunately would not show anything on the notebook or on the script converted from the notebook. But the text greatly increases the source code sizes and makes notebook changes unfriendly to read.

Could someone help me address this issue? Thanks!

@PSSF23
Copy link
Author

PSSF23 commented Oct 10, 2020

After a little tweaking, I did find this type of codes necessary for showing the formatted cells. But I will leave this issue open for considerations and hope to find a simpler way of integrating javascript in the future.

@PSSF23
Copy link
Author

PSSF23 commented Oct 10, 2020

Unclever Workaround:
Before executing anything, use %load_ext lab_black to format all cells (run-all). Then delete the command, restart the kernel, and run everything as normal. This solution would only work for executions that take little effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant