Skip to content

Commit 07dc31e

Browse files
committed
refactor a function for detecting HTML output
1 parent e58739c commit 07dc31e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

scripts/diffable.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def fix_sample(line):
2323
return re.sub(r"\.sample\((\d+)\)", r".sample(\1, random_state=1)", line)
2424

2525

26+
def has_html_output(output):
27+
return "data" in output and "text/html" in output["data"]
28+
29+
2630
input_str = sys.stdin.read()
2731
notebook = json.loads(input_str)
2832

@@ -51,8 +55,8 @@ def fix_sample(line):
5155
# ignore all the execution count numbers
5256
output["execution_count"] = 1
5357

54-
# clear HTML output, since it often has generated IDs (from displacy, plotly, etc.) that change with each execution
55-
if "data" in output and "text/html" in output["data"]:
58+
if has_html_output(output):
59+
# clear HTML output, since it often has generated IDs (from displacy, plotly, etc.) that change with each execution
5660
cell["outputs"] = []
5761
# go to next cell
5862
break

0 commit comments

Comments
 (0)