Skip to content

Commit c264c94

Browse files
authored
Revert "Add html mime type (#82)" (#84)
This reverts commit c93ecbb.
1 parent aa4a5e1 commit c264c94

3 files changed

Lines changed: 2056 additions & 2074 deletions

File tree

python/Demonstration.ipynb

Lines changed: 2041 additions & 2057 deletions
Large diffs are not rendered by default.

python/circuitsvis/utils/render.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44
import os
55
from pathlib import Path
6-
from typing import Dict, Tuple, Union
76
from urllib import request
87
from uuid import uuid4
98

@@ -43,29 +42,28 @@ def __init__(self, local_src: str, cdn_src: str):
4342
self.local_src = local_src
4443
self.cdn_src = cdn_src
4544

46-
def _repr_html_(self) -> Tuple[str, Dict]:
45+
def _repr_html_(self) -> str:
4746
"""Jupyter/Colab HTML Representation
4847
4948
When Jupyter sees this method, it renders the HTML.
5049
5150
Returns:
52-
HTML for Jupyter/Colab
51+
str: HTML for Jupyter/Colab
5352
"""
54-
# Use local source if we're in dev mode, or offline. Otherwise use the CDN.
55-
src: str
56-
if is_in_dev_mode() or not internet_on():
57-
src = self.local_src
58-
else:
59-
src = self.cdn_src
53+
# Use local source if we're in dev mode
54+
if is_in_dev_mode():
55+
return self.local_src
6056

61-
# Return html
62-
mime = {"Content-Type": "text/html"}
63-
return src, mime
57+
# Use local source if we're offline
58+
if not internet_on():
59+
return self.local_src
60+
61+
# Otherwise use the CDN
62+
return self.cdn_src
6463

6564
def __html__(self) -> str:
6665
"""Used by some tooling as an alternative to _repr_html_"""
67-
# Just return the source code (not the MIME data), as some tools may not support this.
68-
return self._repr_html_()[0]
66+
return self._repr_html_()
6967

7068
def show_code(self) -> str:
7169
"""Show the code as HTML source code

python/circuitsvis/utils/tests/test_render.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_jupyter_renders(self):
3737
html = RenderedHTML(src, src)
3838

3939
# Check the _repr_html_ method is defined (as Jupyter Lab displays this)
40-
assert html._repr_html_()[0] == src
40+
assert html._repr_html_() == src
4141

4242
def test_show_code(self):
4343
src = "<p>Hi</p>"
@@ -85,10 +85,10 @@ def test_stringified_render_is_from_cdn(self, monkeypatch):
8585
res = render("Hello", name="Bob")
8686
assert str(res) == str(prod)
8787

88-
def test_jupyter_version_is_from_local(self, monkeypatch):
88+
def test_jupyter_verson_is_from_local(self, monkeypatch):
8989
monkeypatch.setattr(circuitsvis.utils.render, "uuid4", lambda: "mock")
9090
monkeypatch.setattr(circuitsvis, "__version__", "1.0.0")
9191

9292
dev = render_local("Hello", name="Bob")
9393
res = render("Hello", name="Bob")
94-
assert res._repr_html_()[0] == dev
94+
assert res._repr_html_() == dev

0 commit comments

Comments
 (0)