有没有 HTML 的替代品?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6604707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:26:18  来源:igfitidea点击:

Is there an alternative to HTML?

htmlcross-compiling

提问by Alex

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

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

  • converts to HTML without having to write the HTML directly
  • has all the power of HTML
  • is less verbose than HTML and XML
  • 无需直接编写 HTML 即可转换为 HTML
  • 拥有 HTML 的所有功能
  • 没有 HTML 和 XML 冗长

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

例如,对于 HTML 而言,CoffeeScript 之于 JS。

Also, what is your experience with whatever you suggest?

另外,你对你的建议有什么经验?

Also have a look at Comparison of web template enginesand Scala Tags

另请查看Web 模板引擎Scala 标签的比较

采纳答案by John Feminella

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 classis done just by changing one character.

一个不错的选择是Haml。在 Haml 中,您编写高度结构化的标记,类似于 HTML 的精简形式,并且其中常见的事物都有简单的快捷方式。例如,只需更改一个字符即可添加元素 、dividclass

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.

它甚至允许您通过遵循脚本语言,以您选择的语言传递变量并对其进行操作,因此它实际上比 HTML 更强大,因为隐式脚本使其图灵完备。

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>

回答by axelbrz

A friend and I just started Layx: a new layout language based on Cassowary, the constraint solving toolkit that Apple is using for their user interfaces. It's only for web now, but it will be multiplatform -mobile natively- someday.

我和一个朋友刚刚开始使用 Layx:一种基于 Cassowary 的新布局语言,这是 Apple 用于其用户界面的约束解决工具包。它现在仅适用于网络,但总有一天它会成为多平台 - 原生移动 - 。

It is designed to be extremely simple and easy (like python), and as asked, it compiles internally to HTML, dynamically, as the interface has to be updated if layers have to be moved or resized.

它被设计得非常简单和容易(如python),并且根据要求,它在内部动态编译为HTML,因为如果必须移动或调整图层大小,则必须更新界面。

It's a really new project -alpha version-, so try it knowing that.

这是一个非常新的项目-alpha 版本-,所以尝试一下就知道了。

Project website: http://www.layx.org/

项目网址:http: //www.layx.org/

Online demo: http://www.layx.org/demo/

在线演示:http: //www.layx.org/demo/

Open Source repository: http://github.com/layxlang/layx

开源库:http: //github.com/layxlang/layx

I hope it helps and feedback is always welcome!

我希望它有所帮助,并随时欢迎反馈!

Regards

问候

EDIT (8 Jan, 2015): Open source link added

编辑(2015 年 1 月 8 日):添加了开源链接

EDIT (15 Jan, 2015): Demo link added

编辑(2015 年 1 月 15 日):添加了演示链接

回答by Trylks

I know the question is old but I got to it searching for answers, and I thought I would update the replies with my own.

我知道这个问题很老,但我开始寻找答案,我想我会用我自己的回复来更新。

As already pointed, the question asks primarily for template engines(not so much languages) as the point is generating HTML.

正如已经指出的那样,该问题主要询问模板引擎(不是语言),因为重点是生成 HTML。

If the objective is to be consistent with CoffeeScript, then CoffeeKupis the way to go. Personally, among the ones that I have seen, in the search for terseness, Pugis the one that looks best to me, it is heavily influenced by Haml (accepted and top answer), and improves it (IMHO) in several aspects: more terse, more elegant and clear (subjective, fair enough) and does not require Ruby, as it is JavaScript based.

如果目标是与 CoffeeScript 保持一致,那么CoffeeKup就是要走的路。就我个人而言,在我所看到的寻求简洁性方面,Pug是我认为最好的一个,它深受 Haml(接受和最佳答案)的影响,并在几个方面对其进行了改进(恕我直言): 更多简洁,更优雅和清晰(主观,足够公平)并且不需要 Ruby,因为它是基于 JavaScript 的。

回答by jwodder

You're essentially asking for a lightweight markup languagethat can be converted to HTML, popular/well-known examples of which include BBCode, Markdown, and MediaWiki markup.

您本质上是在寻求一种可以转换为 HTML的轻量级标记语言,其中流行/众所周知的示例包括BBCodeMarkdownMediaWiki 标记

回答by Chris Dennett

You can define your website as XML using your own custom format, and then convert to HTML using XSLT. Done it in the past :)

您可以使用自己的自定义格式将网站定义为 XML,然后使用XSLT转换为 HTML 。过去做过:)

回答by arkigos

You may be looking for something like this:

你可能正在寻找这样的东西:

http://code.google.com/p/zen-coding/

http://code.google.com/p/zen-coding/

Though I seem to recall someone already answered this question a while ago.

虽然我似乎记得不久前有人已经回答了这个问题。

回答by Roger Sodré

You can try Processing.js. You'll still need a HTML shell to host the canvas, but you can actually code your site with Processing/Java.

你可以试试Processing.js。您仍然需要一个 HTML shell 来托管画布,但您实际上可以使用 Processing/Java 对您的站点进行编码。