Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/sql/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)