DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML和Xhtml
Zen Coding:用簡短縮寫快速生成 HTML 代碼
編輯:HTML和Xhtml     

Zen Coding 是一款文本編輯器外掛。在使用它的編輯器中,你可以用簡短的縮寫來書寫常規的 HTML 代碼,大幅簡化編寫流程。

例如以下這段 HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>
<body>
<div id="header">
<div id="logo"></div>
<ul id="nav">
<li class="item-1"><a href=""></a></li>
<li class="item-2"><a href=""></a></li>
<li class="item-3"><a href=""></a></li>
<li class="item-4"><a href=""></a></li>
<li class="item-5"><a href=""></a></li>
</ul>
</div>
</body>
</html>

透過 Zen Coding,只需一行即可生成:

html:xt>div#header>div#logo+ul#nav>li.item-$*5>a

這裡提供一個在線 DEMO(若快捷鍵失效,請檢查是否有衝突,例如搜狗輸入法會佔用「Ctrl+,」)。

縮寫規則類似 CSS 選擇器

  • id 與 class:如 div#main.list.item 表示 <div id="main" class="list item"></div>;
  • 其他屬性:如 div[title]、a[title="Hello world" rel]、td[colspan=2];
  • 重複元素:li*3 會輸出 3 個 <li></li>;
  • 數字序號:li.list-$$*2 會展開成 <li class="list-01"></li><li class="list-02"></li>,多個 $ 連寫時,前面的 $ 會以 0 補位;
  • 用括號分組:div#page>(div#header>ul#nav>li*4>a)+(div#page>(h1>span)+p*2)+div#footer;
  • 支持 Filters:使用不同參數會得到完全不同的結果。

其他主要功能

簡寫包裹(Wrap with Abbreviation)

依據光標位置或選取的文本,輸入縮寫後即可將其包裹成想要的結構。以下列歌詞為例,用「ul>li*>span」包裹後:

You walk into the room
With your pencil in your hand
You see somebody naked
And you say, Who is that man?

會得到:

<ul>
<li><span>You walk into the room</span></li>
<li><span>With your pencil in your hand</span></li>
<li><span>You see somebody naked</span></li>
<li><span>And you say, Who is that man?</span></li>
</ul>

標籤匹配(Balance Tag)

Zen Coding 提供了一個快速選取元素內全部內容的方法。

編輯點(Edit Point)

由 Zen Coding 擴展出來的代碼本身沒有內容,此功能能快速定位到需要填寫內容的編輯點。

最後

常見的 IDE 如 Eclipse/Aptana、Notepad++、TextMate、Dreamweaver、UltraEdit、Visual Studio 等,都已有官方或第三方外掛支持。由於 Zen Coding 的核心代碼有 JavaScript 與 Python 兩個版本,只要引入相應的 JS 文件,瀏覽器中的文本編輯區域也能使用 Zen Coding。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved