当前位置:甜馍馍地理信息网 >> 网站开发 >> 综合知识 >> 正文 >>  [阅读资讯:HTML文档规范化简洁化 HTML TIDY介绍及使用]

HTML文档规范化简洁化 HTML TIDY介绍及使用

[ 来源:W3C | 时间:2008年03月17日 | 收藏本文 ] 【
Limited support for ASP, JSTE and PHP

Tidy is somewhat aware of the preprocessing language called ASP which uses a pseudo element syntax <% ... %> to include preprocessor directives. ASP is normally interpreted by the web server before delivery to the browser. JSTE shares the same syntax, but sometimes also uses <# ... #>. Tidy can also cope with another such language called PHP, which uses the syntax <?php ... ?>

Tidy will cope with ASP, JSTE and PHP pseudo elements within element content and as replacements for attributes, for example:

  <option <% if rsSchool.Fields("ID").Value
    = session("sessSchoolID")
    then Response.Write("selected") %>
    value='<%=rsSchool.Fields("ID").Value%>'>
    <%=rsSchool.Fields("Name").Value%>
    (<%=rsSchool.Fields("ID").Value%>)
  </option>

Note that Tidy doesn't understand the scripting language used within pseudo elements and attributes, and can easily get confused. Tidy may report missing attributes when these are hidden within preprocessor code. Tidy can also get things wrong if the code includes quote marks, e.g. if the example above is changed to:

    value="<%=rsSchool.Fields("ID").Value%>"

Tidy will now see the quote mark preceding ID as ending the attribute value, and proceed to complain about what follows. Note you can choose whether to allow line wrapping on spaces within pseudo elements or not using the wrap-asp option. If you used ASP, JSTE or PHP to create a start tag, but placed the end tag explicitly in the markup, Tidy won't be able to match them up, and will delete the end tag for you. So in this case you are advise to make the start tag explicit and to use ASP, JSTE or PHP for just the attributes, e.g.

   <a href="<%=random.site()%>">do you feel lucky?</a>

Tidy allows you to control whether line wrapping is enabled for ASP, JSTE and PHP instructions, see the wrap-asp, wrap-jste and wrap-php config options, respectively.

I regret that Tidy does not support Tango preprocessing instructions which look like:

<@if variable_1='a'>
    do something
<@else>
    do nothing
</@if>
<@include <@cgi><@appfilepath>includes/message.html>

Tidy supports another preprocessing syntax called "Tango", but only for attribute values. Adding support for pseudo elements written in Tango looks as if it would be quite tough, so I would like to gauge the level of interest before committing to this work.

Limited support for XML

XML processors compliant with W3C's XML 1.0 recommendation are very picky about which files they will accept. Tidy can help you to fix errors that cause your XML files to be rejected. Tidy doesn't yet recognize all XML features though, e.g. it doesn't understand CDATA sections or DTD subsets.

Indenting text for a better layout

Indenting the content of elements makes the markup easier to read. Tidy can do this for all elements or just for those where it's needed. The auto-indent mode has been used below to avoid indenting the content of title, p and li elements:

<html>
  <head>
    <title>Test document</title>
  </head>
  <body>
    <p>para which has enough text to cause a line break,
    and so test the wrapping mechanism for long lines.</p>
<pre>
This is
<em>genuine
       preformatted</em>
   text
</pre>
    <ul>
      <li>1st list item</li>
      <li>2nd list item</li>
    </ul>
    <!-- end comment -->
  </body>
</html>

上一页      下一页
本文共 6 页,第  [1]  [2]  [3]  [4]  [5]  [6]  页

【推荐本文】 【打印本页】 【返回顶部
最新文章
推荐文章