I design a notebook so that variables that could be changed by the user are grouped into distinct cells throughout the notebook. I would like to highlight those cells with a
Small addition to krassowski's code (tried to add it as comment but couldn't get the formatting to work).
from IPython.core.magic import register_cell_magic
from IPython.display import HTML, display
@register_cell_magic
def bgc(color, cell=None):
script = (
"var cell = this.closest('.jp-CodeCell');"
"var editor = cell.querySelector('.jp-Editor');"
"editor.style.background='{}';"
"this.parentNode.removeChild(this)"
).format(color)
display(HTML('
'.format(script)))
This way you can use it both as magic and with normal function call:
bgc('yellow')
bla = 'bla'*3
or
%%bgc yellow
bla = 'bla'*3