动态生成的HTML格式 - 没有人关心? [英] Formatting of dynamically generated HTML - does no one care?

查看:178
本文介绍了动态生成的HTML格式 - 没有人关心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在web开发方面经验很少,所以这可能是一个非常基本的问题。

这只是从有限的经验我做了(有一点PHP和一些Ruby on Rails),看起来动态生成HTML的方式是格式化,只是没关系。它会变得丑陋,带有奇怪的缩进,没有人在意,因为这不是用户所看到的。



当然,除非用户是一个开发人员,甚至只是一个好奇的人来看看一个小的HTML来尝试学习一些东西。



也许你不知道我在说什么;所以让我举个例子。

在一个Ruby文件中,我可能有这样的代码:

 < H1>标题< / H1> 

< div>
<%= render:partial => '/ layouts / body'%>
< / div>

然后,在我的/layouts/_body.html.erb文件中,我可能会这样:

 < p>以下是一些内容!< / p> 

< ul>
< li>清单项目1< / li>
< li>清单项目2< / li>
< li>清单项目3< / li>
< / ul>

当所有这些都被渲染时,它会看起来很好。但是,如果用户试图查看源代码,HTML将显得很糟糕:

 < h1>标题< / h1> 

< div>
< p>以下是一些内容!< / p>

< ul>
< li>清单项目1< / li>
< li>清单项目2< / li>
< li>清单项目3< / li>
< / ul>

< / div>

显然,这不是什么大不了的事。而且我完全可以理解,如果主流意见只是没关系。但是,这只是它的方式吗? HTML的可读性对任何人都无关紧要吗?

我只是很好奇,想知道这样做是否让任何人有足够的理由想出一个解决方案(对于这个问题,显然它必须是被视为问题的人)。

解决方案

HAML 模板引擎是为了生成正确缩进,嵌套和格式化的HTML而专门创建的。没有理由为什么其他模板引擎不能这样做。



所以,这只是懒惰而已。


I have very little experience in web development, so this may be a very basic question.

It's just, from the limited experience I do have (a little PHP, and a little Ruby on Rails), it seems that the way dynamically generated HTML is formatted just "doesn't matter"; it ends up ugly, with weird indentation, and nobody cares because that isn't what the users sees.

Unless, of course, the user is a developer, or even just someone who's curious to look at a little HTML to try and learn something.

Maybe you don't know what I'm talking about; so let me give an example.

In a Ruby file I might have some code like this:

<h1>Heading</h1>

<div>
    <%= render :partial => '/layouts/body' %>
</div>

Then, in my "/layouts/_body.html.erb" file, I might have this:

<p>Here is some content!</p>

<ul>
    <li>List item 1</li>
    <li>List item 2</li>
    <li>List item 3</li>
</ul>

When all this gets rendered, it'll look fine. But if the user tries to view the source, the HTML will look pretty crappy:

    <h1>Heading</h1>

    <div>
        <p>Here is some content!</p>

<ul>
    <li>List item 1</li>
    <li>List item 2</li>
    <li>List item 3</li>
</ul>

    </div>

Obviously, this is not a big deal. And I can totally understand if the prevailing opinion is simply "It doesn't matter." But is that just the way it has to be? Does the readability of HTML not matter to anyone?

I'm just curious to know if this ever bugged anyone else enough for him/her to come up with a "solution" for it (obviously it would have to be someone who viewed it as a "problem" in the first place).

解决方案

The HAML templating engine was specifically created with the goal of generating properly indented, nested and formatted HTML. There's no reason why other templating engines couldn't do the same.

So, yes, it is just laziness.

这篇关于动态生成的HTML格式 - 没有人关心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆