Skip to content

Commit de3930f

Browse files
authored
Merge pull request #133 from AnswerDotAI/fix/132-do-not-prepend-imgdir-to-data-uri
2 parents 9ba682a + 3d57aac commit de3930f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

monsterui/franken.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ def render_image(self, token):
15531553
template = '<img src="{}" alt="{}"{} class="max-w-full h-auto rounded-lg mb-6">'
15541554
title = f' title="{token.title}"' if hasattr(token, 'title') else ''
15551555
src = token.src
1556-
if img_dir and not src.startswith(('http://', 'https://', '/')):
1556+
if img_dir and not src.startswith(('http://', 'https://', '/', 'attachment:', 'blob:', 'data:')):
15571557
src = f'{pathlib.Path(img_dir)}/{src}'
15581558
return template.format(src, token.children[0].content if token.children else '', title)
15591559
return FrankenRenderer

nbs/02_franken.ipynb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@
451451
{
452452
"data": {
453453
"text/html": [
454-
"<iframe src=\"http://localhost:8000/_jRNIGvTsQISfQ9f4u9CJAQ\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
454+
"<iframe src=\"http://localhost:8000/_5LD0Qk7fQG2BpDyC1VAEbw\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
455455
" let frame = this;\n",
456456
" window.addEventListener('message', function(e) {\n",
457457
" if (e.source !== frame.contentWindow) return; // Only proceed if the message is from this iframe\n",
@@ -1167,7 +1167,7 @@
11671167
{
11681168
"data": {
11691169
"text/html": [
1170-
"<a href=\"http://localhost:8000/_M6zpWKgqTvKGSmFW1LZNRg\" target=\"_blank\">Open in new tab</a>"
1170+
"<a href=\"http://localhost:8000/_w3FTt22HRf23fdXTLi4eGw\" target=\"_blank\">Open in new tab</a>"
11711171
],
11721172
"text/plain": [
11731173
"<IPython.core.display.HTML object>"
@@ -1179,7 +1179,7 @@
11791179
{
11801180
"data": {
11811181
"text/html": [
1182-
"<iframe src=\"http://localhost:8000/_M6zpWKgqTvKGSmFW1LZNRg\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
1182+
"<iframe src=\"http://localhost:8000/_w3FTt22HRf23fdXTLi4eGw\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
11831183
" let frame = this;\n",
11841184
" window.addEventListener('message', function(e) {\n",
11851185
" if (e.source !== frame.contentWindow) return; // Only proceed if the message is from this iframe\n",
@@ -1600,7 +1600,7 @@
16001600
{
16011601
"data": {
16021602
"text/html": [
1603-
"<iframe src=\"http://localhost:8000/_i3dfd3ZcRNiJUQ_VWokKtQ\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
1603+
"<iframe src=\"http://localhost:8000/_iAoSfI6gSuKeaSNqrKohlA\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
16041604
" let frame = this;\n",
16051605
" window.addEventListener('message', function(e) {\n",
16061606
" if (e.source !== frame.contentWindow) return; // Only proceed if the message is from this iframe\n",
@@ -1867,7 +1867,7 @@
18671867
{
18681868
"data": {
18691869
"text/html": [
1870-
"<iframe src=\"http://localhost:8000/_jDd25C_CTIajV0bsMTjzOg\" style=\"width: 100%; height: 500px; border: none;\" onload=\"\" allow=\"accelerometer; autoplay; camera; clipboard-read; clipboard-write; display-capture; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; identity-credentials-get; idle-detection; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; usb; web-share; xr-spatial-tracking\"></iframe> "
1870+
"<iframe src=\"http://localhost:8000/_BKeCyjE2TAyJCPV2_Le9Og\" style=\"width: 100%; height: 500px; border: none;\" onload=\"\" allow=\"accelerometer; autoplay; camera; clipboard-read; clipboard-write; display-capture; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; identity-credentials-get; idle-detection; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; usb; web-share; xr-spatial-tracking\"></iframe> "
18711871
],
18721872
"text/plain": [
18731873
"<IPython.core.display.HTML object>"
@@ -2970,7 +2970,7 @@
29702970
{
29712971
"data": {
29722972
"text/html": [
2973-
"<iframe src=\"http://localhost:8008/_lcysiC5NRne3jeT4Roy0Jg\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
2973+
"<iframe src=\"http://localhost:8008/_Z8F24y_hQMiCbnED9WguJg\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
29742974
" let frame = this;\n",
29752975
" window.addEventListener('message', function(e) {\n",
29762976
" if (e.source !== frame.contentWindow) return; // Only proceed if the message is from this iframe\n",
@@ -3130,7 +3130,7 @@
31303130
" template = '<img src=\"{}\" alt=\"{}\"{} class=\"max-w-full h-auto rounded-lg mb-6\">'\n",
31313131
" title = f' title=\"{token.title}\"' if hasattr(token, 'title') else ''\n",
31323132
" src = token.src\n",
3133-
" if img_dir and not src.startswith(('http://', 'https://', '/')):\n",
3133+
" if img_dir and not src.startswith(('http://', 'https://', '/', 'attachment:', 'blob:', 'data:')):\n",
31343134
" src = f'{pathlib.Path(img_dir)}/{src}'\n",
31353135
" return template.format(src, token.children[0].content if token.children else '', title)\n",
31363136
" return FrankenRenderer"
@@ -3167,15 +3167,21 @@
31673167
"output_type": "stream",
31683168
"text": [
31693169
"<p class=\"text-lg leading-relaxed mb-6\"><img src=\"/users/isaac-flath/my_image.png\" alt=\"test\" title=\"\" class=\"max-w-full h-auto rounded-lg mb-6 max-w-full h-auto rounded-lg mb-6\"></p>\n",
3170+
"\n",
31703171
"<p class=\"text-lg leading-relaxed mb-6\"><img src=\"static/my_image.png\" alt=\"test\" title=\"\" class=\"max-w-full h-auto rounded-lg mb-6 max-w-full h-auto rounded-lg mb-6\"></p>\n",
3171-
"<p class=\"text-lg leading-relaxed mb-6\"><img src=\"https://example.com/img.png\" alt=\"test\" title=\"\" class=\"max-w-full h-auto rounded-lg mb-6 max-w-full h-auto rounded-lg mb-6\"></p>\n"
3172+
"\n",
3173+
"<p class=\"text-lg leading-relaxed mb-6\"><img src=\"https://example.com/img.png\" alt=\"test\" title=\"\" class=\"max-w-full h-auto rounded-lg mb-6 max-w-full h-auto rounded-lg mb-6\"></p>\n",
3174+
"\n",
3175+
"<p class=\"text-lg leading-relaxed mb-6\"><img src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiB\" alt=\"test\" title=\"\" class=\"max-w-full h-auto rounded-lg mb-6 max-w-full h-auto rounded-lg mb-6\"></p>\n",
3176+
"\n"
31723177
]
31733178
}
31743179
],
31753180
"source": [
31763181
"print(render_md('![test](/users/isaac-flath/my_image.png)', img_dir='static'))\n",
31773182
"print(render_md('![test](my_image.png)', img_dir='static'))\n",
3178-
"print(render_md('![test](https://example.com/img.png)', img_dir='static'))"
3183+
"print(render_md('![test](https://example.com/img.png)', img_dir='static'))\n",
3184+
"print(render_md('![test](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiB)', img_dir='static'))"
31793185
]
31803186
},
31813187
{
@@ -3222,7 +3228,7 @@
32223228
{
32233229
"data": {
32243230
"text/html": [
3225-
"<iframe src=\"http://localhost:8008/_9sqkIqasTvOdm8snfj32IA\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
3231+
"<iframe src=\"http://localhost:8008/_Rjgl0haMQ2iP59xOmxmqig\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
32263232
" let frame = this;\n",
32273233
" window.addEventListener('message', function(e) {\n",
32283234
" if (e.source !== frame.contentWindow) return; // Only proceed if the message is from this iframe\n",
@@ -3294,7 +3300,7 @@
32943300
{
32953301
"data": {
32963302
"text/html": [
3297-
"<iframe src=\"http://localhost:8008/_N-s11_PFTo2VVA-wtJUCwA\" style=\"width: 100%; height: 350px; border: none;\" onload=\"\" allow=\"accelerometer; autoplay; camera; clipboard-read; clipboard-write; display-capture; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; identity-credentials-get; idle-detection; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; usb; web-share; xr-spatial-tracking\"></iframe> "
3303+
"<iframe src=\"http://localhost:8008/_GXhX1QgfStivfBjaSa8ayw\" style=\"width: 100%; height: 350px; border: none;\" onload=\"\" allow=\"accelerometer; autoplay; camera; clipboard-read; clipboard-write; display-capture; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; identity-credentials-get; idle-detection; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; usb; web-share; xr-spatial-tracking\"></iframe> "
32983304
],
32993305
"text/plain": [
33003306
"<IPython.core.display.HTML object>"
@@ -3601,7 +3607,7 @@
36013607
{
36023608
"data": {
36033609
"text/html": [
3604-
"<iframe src=\"http://localhost:8008/_bL-ObMZ2Qqyzn1fQ73N3EA\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
3610+
"<iframe src=\"http://localhost:8008/_1XCdP2InSESFkkurKNnfHw\" style=\"width: 100%; height: auto; border: none;\" onload=\"{\n",
36053611
" let frame = this;\n",
36063612
" window.addEventListener('message', function(e) {\n",
36073613
" if (e.source !== frame.contentWindow) return; // Only proceed if the message is from this iframe\n",

0 commit comments

Comments
 (0)