Skip to content

Commit

Permalink
Update render.py (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdremov authored Dec 19, 2024
1 parent be5e9aa commit 0ae6bea
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pages/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def overflowing_div(content):
"</div>"
)

def raw_context(content):
return (
'\n{% raw %}\n<div markdown="0">\n' +
content +
'\n</div>\n{% endraw %}\n'
)


def render(cell):
match cell['cell_type']:
Expand Down Expand Up @@ -71,7 +78,7 @@ def render_code(cell):
if "text/html" in data:
output_text += (
'\n' +
overflowing_div(''.join(data["text/html"])) +
raw_context(overflowing_div(''.join(data["text/html"]))) +
'\n'
)
elif "text/plain" in data:
Expand All @@ -90,7 +97,18 @@ def render_code(cell):
)
elif output['output_type'] == 'display_data':
data = output['data']
if "image/png" in data:
print(data.keys(), "text/html" in data, file=sys.stderr)
if "text/html" in data:
output_text += (
raw_context(''.join(
filter(
lambda x: len(x.strip()) > 0,
data["text/html"]
)
)
)
)
elif "image/png" in data:
output_text += (
f'\n<img src="data:image/png;base64, {data["image/png"]}" alt="{"".join(data.get("text/plain", []))}" />\n'
)
Expand All @@ -109,7 +127,7 @@ def render_code(cell):
def render_markdown(cell):
return (
"\n" +
escape(''.join(cell['source'])) +
''.join(cell['source']) +
"\n"
)

Expand Down

0 comments on commit 0ae6bea

Please sign in to comment.