是否可以在 php/html 风格的情况下正确完成嵌套?

发布于 2024-09-30 00:06:29 字数 410 浏览 5 评论 0原文

我怀疑甚至可能有一个数学证明来证明这个问题的答案是“不”,但是,问题是:是否可以发明一种类似 php 的语言(即一些在幕后评估代码的行,以及一些在幕后评估代码的行)评估显示的html)它总是可以正确嵌套的?举一个我正在谈论的例子,在rails/haml中,

%table
  %tr
    %th Title
    %th Content
    %th Owner
    %th Categories
  - @posts.each do |post|
    %tr
      %td

第二个%tr应该与第一个%tr垂直对齐(因为它们在输出html中是兄弟姐妹),但是开始每个块的行导致它是多缩进一行。是否有人可以开发某种 html 元语言,其中缩进可以反映控制结构和正确的嵌套,而不会相互冲突?如果有的话,这样的事情存在吗?

I suspect that there might even be a mathematical proof that the answer to this is "no", but, question: Could one invent a type of php-like language (ie with some lines that evaluate code behind the scenes, and some lines that evaluate to displayed html) where it could always be properly nested? To give an example of what I'm talking about, in rails/haml

%table
  %tr
    %th Title
    %th Content
    %th Owner
    %th Categories
  - @posts.each do |post|
    %tr
      %td

the second %tr should be aligned vertically with the first (as they are siblings in the output html), but the line that begins the each block causes it to be indented one additional line. Is it possible that someone could develop some sort of of html meta-language where indentation can reflect both control structures and proper nesting, without each coming into conflict with the other? If so, does such a thing exist?

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

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

发布评论

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

评论(1

风吹短裙飘 2024-10-07 00:06:29

我可以想一些办法。编译器/解释器只需要做出一些仔细且明确概述的假设。

例如,假设为了解释页面结构而删除了控制结构的缩进,那么上面的代码会将数据 %tr 置于与 %td 相同的缩进级别。请注意,这会使某些页面结构难以阅读。

另一个例子,使控制结构语法与给定缩进级别的页面结构共存。控制结构可以单独存在,也可以存在于页结构语句之后。这样做的优点是代码和页面结构都可读。

%table  
  %tr  
    %th Title  
    %th Content  
    %th Owner  
    %th Categories  
  %tr @posts.each do |post|     
    %td  

I can think of some ways. The compiler/interpreter simply needs to make some assumptions that are carefully and explicitly outlined.

For example, assume that indents for control structures are removed for interpreting page structure, then your code above would put the data %tr at the same indentation level as the %td. Note that this would make some of the page structure hard to read.

Another example, make the control structure syntax coexist with page structure at a given indentation level. A control structure can exist alone or after a page structure statement. This has the advantage of being readable both in terms of code and page structure.

%table  
  %tr  
    %th Title  
    %th Content  
    %th Owner  
    %th Categories  
  %tr @posts.each do |post|     
    %td  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文