Created
June 14, 2020 09:30
-
-
Save sizhky/dfa8a8a8b737c911b9a18f16302746ca to your computer and use it in GitHub Desktop.
set background in jupyter cells
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.core.magic import register_cell_magic | |
from IPython.display import HTML, display | |
def set_background(color): | |
script = ( | |
"var cell = this.closest('.jp-CodeCell');" | |
"var editor = cell.querySelector('.jp-Editor');" | |
"editor.style.background='{}';" | |
"this.parentNode.removeChild(this)" | |
).format(color) | |
display(HTML('<img src onerror="{}">'.format(script))) | |
@register_cell_magic | |
def background(color, cell): | |
set_background(color) | |
# found at https://stackoverflow.com/a/50824920/4296772 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment