Open the given URL in the user's browser
(url: str)
| 109 | ################################################################################ |
| 110 | # Output |
| 111 | def open_in_browser(url: str): |
| 112 | """Open the given URL in the user's browser""" |
| 113 | from datapane.ipython.environment import get_environment |
| 114 | |
| 115 | environment = get_environment() |
| 116 | |
| 117 | # TODO - this is a bit of a hack, but works for now. JupyterLab (Codespaces) doesn't support webbrowser.open. |
| 118 | if environment.is_notebook_environment and not environment.can_open_links_from_python: |
| 119 | ip = environment.get_ipython() |
| 120 | ip.run_cell_magic("javascript", "", f'window.open("{url}", "_blank")') |
| 121 | else: |
| 122 | import webbrowser |
| 123 | |
| 124 | webbrowser.open(url, new=1) |
| 125 | |
| 126 | |
| 127 | class MarkdownFormatter(string.Formatter): |
no test coverage detected