diff --git a/src/sql/magic.py b/src/sql/magic.py index f2c3c3207..a585b28b3 100644 --- a/src/sql/magic.py +++ b/src/sql/magic.py @@ -286,9 +286,14 @@ def _persist_dataframe(self, raw, conn, user_ns, append=False): def load_ipython_extension(ip): """Load the extension in IPython.""" - # this fails in both Firefox and Chrome for OS X. - # I get the error: TypeError: IPython.CodeCell.config_defaults is undefined - - # js = "IPython.CodeCell.config_defaults.highlight_modes['magic_sql'] = {'reg':[/^%%sql/]};" - # display_javascript(js, raw=True) + js = """ + let codeCell = (window.Jupyter ?? window.IPython)?.CodeCell; + if (codeCell) { + let highlightModes = (codeCell.options_default ?? codeCell.config_defaults).highlight_modes; + if (!highlightModes['magic_sql']) + highlightModes['magic_sql'] = {'reg': []}; + highlightModes['magic_sql']['reg'].push(/^%%sql/); + } + """ + display_javascript(js, raw=True) ip.register_magics(SqlMagic)