Is there an alternative to HTML? [closed]

2019-03-09 01:03发布

问题:

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

回答1:

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>


回答2:

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.

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.

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

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

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

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

I hope it helps and feedback is always welcome!

Regards

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

EDIT (15 Jan, 2015): Demo link added



回答3:

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



回答4:

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



回答5:

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.

If the objective is to be consistent with CoffeeScript, then CoffeeKup is the way to go. Personally, among the ones that I have seen, in the search for terseness, Pug is 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.



回答6:

You may be looking for something like this:

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

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



回答7:

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.