是否可以创建 HTML quine?

发布于 2024-12-20 01:22:38 字数 498 浏览 4 评论 0原文

根据标题,是否可以创建一个(不平凡的)quine HTML?

我对 HTML quine 的定义:

假设 HTML 文件中的某些字符串由浏览器呈现为纯文本,则非平凡的 HTML quine 不为 null,并且至少使用一个 HTML 标记。 HTML quine 的定义是,由标准浏览器呈现的 q.html 的输出q.html 本身的内容。

(我愿意接受对此定义的任何评论,我现在就对它进行了修改)

HTML 不是图灵完备的,因此不能应用定点定理来证明它确实是可能的。

然而,这并不一定意味着 HTML quine 是不可能的。或者实际上可以证明 HTML quine 是不可能的吗?

Per the title, is it possible to create a (non-trivial) quine in HTML?

My definition of an HTML quine:

A non-trivial HTML quine is one that is not null and uses at least one HTML tag, under the assumption that some string in an HTML file is rendered by a browser as plain text. An HTML quine is defined such that the output of the q.html as rendered by a standard browser is the contents of q.html itself.

(I'm open for any comments on this definition, I kind of hacked it up right now)

HTML is not turing-complete, therefore the fixed-point theorem cannot be applied to prove that it is indeed possible.

However, this does not necessarily mean an HTML quine is impossible. Or can it in fact be proven that an HTML quine is impossible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

木格 2024-12-27 01:22:38

对于“纯”HTML 来说这当然是不可能的。显然,可以使用 JavaScript 来完成,但也可以使用 CSS 来完成:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is the title</title>
<style type="text/css"><![CDATA[ 
* {
  display:inline;
  white-space:pre;
}
html:last-child {
  white-space:normal;
}
html:before  {content:'<html xmlns="http://www.w3.org/1999/xhtml">';}
html:after   {content:'</html>';}
head:before  {content:'<head>';}
head:after   {content:'</head>';}
title:before {content:'<title>';}
title:after  {content:'</title>';}
style:before {content:'<style type="text/css"><![CDATA[';}
style:after  {content:']]\00003e</style>';}
body:before  {content:'<body/>';position:absolute;left:0;}
]]></style>
</head>
<body/>
</html>

It's certainly not possible with "plain" HTML. Obviously it would be possible to do with JavaScript, but it's also possible with CSS:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is the title</title>
<style type="text/css"><![CDATA[ 
* {
  display:inline;
  white-space:pre;
}
html:last-child {
  white-space:normal;
}
html:before  {content:'<html xmlns="http://www.w3.org/1999/xhtml">';}
html:after   {content:'</html>';}
head:before  {content:'<head>';}
head:after   {content:'</head>';}
title:before {content:'<title>';}
title:after  {content:'</title>';}
style:before {content:'<style type="text/css"><![CDATA[';}
style:after  {content:']]\00003e</style>';}
body:before  {content:'<body/>';position:absolute;left:0;}
]]></style>
</head>
<body/>
</html>
你在我安 2024-12-27 01:22:38

这是不可能的。由于每个未转义的元素都将被浏览器解释为标记,因此浏览器将尝试呈现或处理这些元素的内容或作为控件。您无法显示未以某种方式转义的元素,例如使用

 标记。但这样的标签也不会显示。

当然,您可以将其作为带有适当 HTTP 标头的文本/纯文本来提供,但这不是 HTML。在大多数(所有?)情况下,仅使用 .html 扩展名将使浏览器将其呈现为 html。

This is not possible. Since every unescaped element will be interpreted as markup by the browser, the browser will attempt to render or handle the contents of those elements or as a control. You cannot display an element that is not escaped in some way, such as with the <pre> tag. But then such tags will also not be displayed.

Of course, you could serve it as text/plain with appropriate HTTP headers but, then, that's not HTML. Just using the .html extension will make browsers render it as html anyway in most (all?) cases.

忆依然 2024-12-27 01:22:38

你不能。

<!DOCTYPE html>
<html>
<head>
<title></title>
<head>
<body>
<div id="quine" ></div>
<script>
document.getElementById("quine").innerHTML = document.documentElement.innerHTML.replace(/\&/g, "&" ).replace(/\</g, "<" ).replace(/\>/g, ">");
</script>
</body>
</html>

但你可以作弊并做

<body onload="document.getElementById("quine").innerHTML = document.documentElement.innerHTML.replace(/\&/g, "&" ).replace(/\</g, "<" ).replace(/\>/g, ">");" >
<div id="quine" ></div>
</body>

You can't.

<!DOCTYPE html>
<html>
<head>
<title></title>
<head>
<body>
<div id="quine" ></div>
<script>
document.getElementById("quine").innerHTML = document.documentElement.innerHTML.replace(/\&/g, "&" ).replace(/\</g, "<" ).replace(/\>/g, ">");
</script>
</body>
</html>

You can cheat though and do

<body onload="document.getElementById("quine").innerHTML = document.documentElement.innerHTML.replace(/\&/g, "&" ).replace(/\</g, "<" ).replace(/\>/g, ">");" >
<div id="quine" ></div>
</body>
岁月染过的梦 2024-12-27 01:22:38

当然,就像所有 HTML“假设”一样,答案就是使用 JQuery!

Sure, just like with all HTML "what ifs", the answer is just use JQuery!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文