Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add white background to inscription content #1054

Merged
merged 4 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/subcommand/server/templates/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ impl<'a> Display for ContentHtml<'a> {
text.escape(f, false)?;
write!(f, "</pre>")
}
Some(Content::Image) => write!(f, "<img src=/content/{}>", self.inscription_id),
Some(Content::Image) => write!(
f,
"<img class=inscription src=/content/{}>",
self.inscription_id
),
Some(Content::IFrame) => {
write!(f, "<iframe src=/content/{}></iframe>", self.inscription_id)
write!(
f,
"<iframe class=inscription src=/content/{}></iframe>",
self.inscription_id
)
}
None => write!(f, "<p>UNKNOWN</p>"),
}
Expand All @@ -26,6 +34,18 @@ impl<'a> Display for ContentHtml<'a> {
mod tests {
use super::*;

#[test]
fn unknown() {
assert_eq!(
ContentHtml {
content: None,
inscription_id: txid(1),
}
.to_string(),
"<p>UNKNOWN</p>"
);
}

#[test]
fn text() {
assert_eq!(
Expand All @@ -38,6 +58,18 @@ mod tests {
);
}

#[test]
fn text_is_escaped() {
assert_eq!(
ContentHtml {
content: Some(Content::Text("<script>alert('hello!')</script>")),
inscription_id: txid(1),
}
.to_string(),
"<pre>&lt;script&gt;alert(&apos;hello!&apos;)&lt;/script&gt;</pre>",
);
}

#[test]
fn image() {
assert_eq!(
Expand All @@ -46,7 +78,7 @@ mod tests {
inscription_id: txid(1),
}
.to_string(),
"<img src=/content/1111111111111111111111111111111111111111111111111111111111111111>"
"<img class=inscription src=/content/1111111111111111111111111111111111111111111111111111111111111111>"
);
}

Expand All @@ -58,7 +90,7 @@ mod tests {
inscription_id: txid(1),
}
.to_string(),
"<iframe src=/content/1111111111111111111111111111111111111111111111111111111111111111></iframe>"
"<iframe class=inscription src=/content/1111111111111111111111111111111111111111111111111111111111111111></iframe>"
);
}
}
68 changes: 1 addition & 67 deletions src/subcommand/server/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
use super::*;

#[test]
fn txt_inscription() {
fn html() {
pretty_assert_eq!(
InscriptionHtml {
genesis_height: 0,
Expand Down Expand Up @@ -56,70 +56,4 @@ mod tests {
.unindent()
);
}

#[test]
fn png_inscription() {
pretty_assert_eq!(
InscriptionHtml {
genesis_height: 0,
inscription_id: InscriptionId::from_str(
"ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc"
)
.unwrap(),
inscription: inscription("image/png", [1; 100]),
satpoint: satpoint(1, 0),
}
.to_string(),
"
<h1>Inscription ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</h1>
<a class=content href=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
<img src=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
</a>
<dl>
<dt>content size</dt>
<dd>100 bytes</dd>
<dt>content type</dt>
<dd>image/png</dd>
<dt>genesis height</dt>
<dd>0</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</a></dd>
<dt>location</dt>
<dd class=monospace>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
</dl>
"
.unindent()
);
}

#[test]
fn empty_inscription() {
pretty_assert_eq!(
InscriptionHtml {
genesis_height: 0,
inscription_id: InscriptionId::from_str(
"ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc"
)
.unwrap(),
inscription: Inscription::new(None, None),
satpoint: satpoint(1, 0),
}
.to_string(),
"
<h1>Inscription ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</h1>
<a class=content href=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
<p>UNKNOWN</p>
</a>
<dl>
<dt>genesis height</dt>
<dd>0</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</a></dd>
<dt>location</dt>
<dd class=monospace>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
</dl>
"
.unindent()
);
}
}
22 changes: 16 additions & 6 deletions static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ a.mythic {
border-radius: 2%;
}

.inscriptions a img {
.inscriptions img.inscription {
overflow: auto;
max-width: 100%;
min-width: 100%;
image-rendering: pixelated;
}

.inscriptions a iframe {
width: 100%;
height: 100%;
.inscriptions iframe.inscription {
width: 101%;
height: 101%;
overflow: hidden;
}

.content {
Expand All @@ -190,7 +190,6 @@ a.mythic {

.content img {
min-width: 50%;
image-rendering: pixelated;
}

iframe {
Expand All @@ -208,3 +207,14 @@ a.content {
color: inherit;
text-decoration: none;
}

img.inscription {
image-rendering: pixelated;
background-color: white;
}

iframe.inscription {
border: none;
pointer-events: none;
background-color: white;
}
4 changes: 2 additions & 2 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn inscribe_png() {
ord_server.assert_response_regex(
"/sat/5000000000",
&format!(
".*<dt>inscription</dt>\n <dd><a href=/inscription/{txid}><img src=/content/{txid}.*"
".*<dt>inscription</dt>\n <dd><a href=/inscription/{txid}><img class=inscription src=/content/{txid}.*"
),
)
}
Expand Down Expand Up @@ -684,7 +684,7 @@ fn inscribe_gif() {
ord_server.assert_response_regex(
"/sat/5000000000",
&format!(
".*<dt>inscription</dt>\n <dd><a href=/inscription/{txid}><img src=/content/{txid}.*"
".*<dt>inscription</dt>\n <dd><a href=/inscription/{txid}><img class=inscription src=/content/{txid}.*"
),
)
}