zml
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:Concise markup language + templating system inspired by haml, SLiP, sexp2xml, and tenjin.
Current work and issues can be found at
"PivotalTracker":https://www.pivotaltracker.com/projects/65667

Feel free to ping us if you want to be added to the pivotaltracker account.

h2. The Little ZMLer

ZML is a small markup language that uses indentation to represent
hierarchy of tags.

h3. tags

By default, ZML document translates into XML:


:document
  :title My first ZML example
    has a pretty long title
  :table
    :tr
      :td cell 11
      :td cell 12
    :tr
      :td cell 21
      :td cell 22



  My first ZML example has a pretty long title
  
cell 11 cell 12
cell 21 cell 22
h3. indentation matters Note how it treats indentation to mix text and tags:

:document
  :head First line of the HEAD tag.
    Second line of the HEAD - note the indentation.
  :body Obviously, that line belongs to BODY.
    This one is also part of the BODY.
  OOPS, this line is part of the DOCUMENT tag!



  
    First line of the HEAD tag.
    Second line of the HEAD - note the indentation.
  
  
    Obviously, that line belongs to BODY.
    This one is also part of the BODY.
  
  OOPS, this line is part of the DOCUMENT tag!

h3. inline tags Inline tags must have a closing semicolon in the same line:

:document
  :title Here's a :strong big fat; title



  Here's a <strong>big fat</strong> title

h3. comments ZML supports single-line comments and special *comment tags:

:document || Comment to the end of line
  *comment first line of the comment
    second line of the comment
  :body || Note this tag has an empty body!



h3. attributes Syntax for attributes is:

:document(author: Sergei Matusevich
          encoding: UTF-8 language: en-us)
  :title(class: header)



  
</document>
</code></pre>

Note that because we use parenthesis, attributes can span multiple
lines. Multiline attributes must be indented, just like the body of
the tag.


h3. escaping special characters

To escape special characters, we can use backslash or any of the |""|,
|''|, or |``| quotes:

<pre><code>
:document(onload: |"onload();"|)
  :title \:tag escaping
</code></pre>

<pre><code>
<?xml version="1.0"?>
<document onload="onload();">
  <title>:tag escaping

h3. multiline quotes Note that |""| quotes can span multiple lines, but it still must be indented relatively to the enclosing tag:

:document
  :script(type: text/javascript) |"
    function onload() {
      alert("Hello there");
    } "|



  

h3. id and class attributes ZML has special syntax for id and class attributes, common in (X)HTML:

:document#sample-001
  :table#sample-table-id.bigtable-class
    :tr.bigtable-class.odd-row
      :td cell 11
      :td cell 12
    :tr.bigtable-class.even-row
      :td cell 21
      :td cell 22



  
cell 11 cell 12
cell 21 cell 22
Note that each :tr tag has *two* classes that got pasted into a single attribute value. Order of id and class attributes does not matter. h3. div tags If class or id (or both) are used, we can omit :tag name alltogether. ZML uses div tag in such case:

:document
  #header(onclick: |"alert('hello');"|) a header DIV
  #body.grid-3
    .title isn't that neat?
    More text for the body
  :div#footer a footer DIV



  
  
isn't that neat?
More text for the body
We can freely mix shortcuts for div, class, and id with the regular ZML syntax. h3. special tag - *html ZML can be extended with special tags that hook up to the user-defined code for custom syntax. Such tags start with the '*' character instead of ':'. Most useful tag is *html. Compare this:

:html or is it?


or is it?
With this:

*html or is it?




  
    
    
    
  
  or is it?

That is, *html creates a lot of boilerplate HTML for us! h3. *html special attributes It also gives special treatment to many attributes, e.g.

*html(title: That's a document title
      favicon: /img/favicon.ico
      encoding: koi8-r language: ru)
  Here goes the body




  
    
    
    
    That's a document title
    
    
  
  Here goes the body

Note the link and title tags, as well as the change in meta http-equiv parameters. h3. *html special attributes - complete list Here's the full list of special attributes that *html currently supports: h4. document type * type: HTML type. Can be one of: | html2 | | html3 | | strict | | frameset | | xhtml_strict | | xhtml_frameset | | transitional | | xhtml_transitional | This attribute selects what HTML template to use, e.g.

*html(type:html2) test



  
    
    
    
  
  test


*html(type:xhtml_frameset) test




  
    
    
    
  
  test

h4. encoding and language * encoding: document encoding. UTF-8 by default. * language: content-language part of the http-equiv. Also sets the lang and xml:lang attributes of the html tag, if html type requires so. Default is en-us. h4. other special attributes for *html * nosmarttag: true or false. Controls MSSmartTagsPreventParsing. * stylelibs: Names of ZSS libraries to include * remove_unused_css: false (default) or true. Turns on CSS optimization. * description * keywords * copyright * title * favicon Various shortcuts. The following example uses them all:

*html(description: document description
      keywords: zml zss markup erlang
      copyright: Joseph Wecker
      title: page title
      favicon: /img/favicon.ico)
  test




  
    
    
    
    
    
    
    page title
    
    
  
  test

h3. *table markup Special tag *table implements a simple markup language for tables. It looks like this:

*table
  | a | b |
  | c | d |
This code translates into:


a b
c d
Each row of the table must begin and end with the '|' character. Spaces are treated as-is; note that "||" (with no spaces) is treated as a comment:

*table | a|b |  || comment!
results in


ab
Note that it is OK to start table immediately after the *table tag, on the same line. Comments and quoted strings are also supported. h4. inline tags inside *table It is perfectly fine to have other tags inside the *table markup. '|' characters inside such tags are just regular characters, and are not interpreted as column separators, e.g.

*table | :strong some | text; |
translates into:


some | text
h4. tr and td attributes To specify attributes for tr and td tags, prefix them with "tr_" and "td_", respectively, and define them in the *table tag:

*table#bigtable(tr_class: row td_class: cell border: 0) | a | b |
translates into:


a b
h3. Templating h4. Variables Syntax for variables is:

${variable}
To refer nested data sets, separate identifiers with dots:

${data_set.nestedDataSet.var}
Variables can be used inside the :tag body or in attribute values. Behavior of the *special tags depends on the tag implementation, e.g. *comment and *verbatim treat variables as any other text. h4. Repeated blocks To iterate over a data set, use the *with special tag, e.g.

:table
  *with(id: data_set)
    :tr :td ${user_name}; :td ${user_address};
Here :tr block will be replicated as many times as there are records in the given data_set. Data set ID is specified in the *with id attribute. We can also write *with#data_set to same effect. h3. ZML Gotchas h4. Special characters that begin a tag Remember that '.' period, ':' colon, and '#' hash are special characters that can start inline tags, when immediately followed by one or more alpha characters, e.g.

:a(href: http://github.com) github.com
translates into

 github
i.e. a string ".com" is treated as inline div block here. Oops. To avoid this, escape the dot with the backslash or quote the whole string, and write github\.com or |"github.com"|. Note that tag name *must* begin with the alpha character, so the the strings like "$9.99" or "#1" will remain untouched. h4. Semicolons Remember that ';' semicolon closes the inline tag, but *only* if there is an _inline_ tag to close. Otherwise, semicolon will remain as is. E.g.

.example Check if :i x < y; for every value of x
results in

Check if x < y; for every value of x
Note that the first semicolon that belongs to < string has been translated as the end of the :i tag, but the second semicolon remained as is. The issue occurs only when the extra semicolon is inside the *inline* tag. Since tags that start the line does not have to be closed, there's no need to escape semicolons in such case. h4. Spaces around inline tags Spaces around inline tags are preserved, just like any other spaces between words. The only spaces that ZML truncates are those immediately following the tag name (but not the list of attributes), e.g.

.example   Hello :a (href: #)  world;!
produces

Hello world!
i.e. ZML had removed spaces between ".example" and "Hello", and between "a" and "href". All other spacing remained intact.

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。