有没有替代HTML? [英] Is there an alternative to HTML?

查看:156
本文介绍了有没有替代HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种语言可以用来编写我的网站的HTML:
$ b


  • 转换为HTML,而不必直接写HTML

  • 具有HTML的所有功能

  • 不像HTML和XML那样冗长



例如,它应该是HTML对CoffeeScript来说是JS的。



另外,你有什么经验与你的建议? p>

另请参阅网页模板引擎比较 a>和 Scala Tags

解决方案

一个好的选择是 Haml 。在Haml中,你编写了高度结构化的标记,类似于精简的HTML格式,常见的东西都有简单的捷径。例如,添加一个元素 div id class

它甚至可以让你按照你选择的语言传递变量并对它们进行操作,并遵循脚本语言。它实际上比HTML更强大,因为隐式脚本使它完成图灵。



下面是一个例子:

 %body 
#header
%h1 Bob Loblaw的法律博客
%h2由Bob Loblaw
#content
- @entries。每个做|入| |
.entry
%h3.title = entry.title
%p.date = entry.posted
#footer
%p
所有内容版权所有© Bob Loblaw。

这就像是:

 < div id ='header'> 
< h1> Bob Loblaw's Law Blog< / h1> bob Loblaw的
< h2>< / h2>
< / div>
< div id ='content'>
< div class ='entry'>
< h3 class ='title'>你不需要双重对话;你需要Bob Loblaw< / h3>
< p class ='date'> 2006年10月31日,星期二< / p>
< / div>
< div class ='entry'>
< h3 class ='title'>为什么你应该因监狱犯罪而入狱?< / h3>
< p class ='date'> 2006年8月11日星期五< / p>
< / div>
< / div>
< div id ='footer'>
< p>
所有内容版权©Bob Loblaw。
< / p>
< / div>


Is there a language I can use to write my website's HTML, which:

  • converts to HTML without having to write the HTML directly
  • has all the power of HTML
  • is less verbose than HTML and XML

For example, it should be to HTML what CoffeeScript is to JS.

Also, what is your experience with whatever you suggest?

Also have a look at Comparison of web template engines and Scala Tags

解决方案

A good choice is Haml. In Haml, you write highly structured markup that resembles a stripped-down form of HTML, and where common things have easy shortcuts. For example, adding an element, div, id, or class is done just by changing one character.

It even lets you pass variables in and operate on them in the language of your choice by deferring to a scripting language, so it's actually more powerful than HTML since the implicit scripting makes it Turing-complete.

Here's an example:

  %body
    #header
      %h1 Bob Loblaw's Law Blog
      %h2 by Bob Loblaw
    #content
      - @entries.each do |entry|
        .entry
          %h3.title= entry.title
          %p.date= entry.posted
    #footer
      %p
        All content copyright © Bob Loblaw.

This becomes something like:

<div id='header'>
  <h1>Bob Loblaw's Law Blog</h1>
  <h2>by Bob Loblaw</h2>
</div>
<div id='content'>
  <div class='entry'>
    <h3 class='title'>You don't need double-talk; you need Bob Loblaw</h3>
    <p class='date'>Tuesday, October 31, 2006</p>
  </div>
  <div class='entry'>
    <h3 class='title'>Why should you go to jail for a crime someone else noticed?</h3>
    <p class='date'>Friday, August 11, 2006</p>
  </div>
</div>
<div id='footer'>
  <p>
    All content copyright © Bob Loblaw.
  </p>
</div>

这篇关于有没有替代HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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