cib*_*en1 7 php macros html5 m4
我会做的很棒
<define tag="myTag" options="3">
<h1> #1 </h1>
<ul>
<li> #2
<li> #3
</ul>
</define>
Run Code Online (Sandbox Code Playgroud)
然后使用它:
<myTag option="foo" option="bar" option="bean" />
Run Code Online (Sandbox Code Playgroud)
我认为宏是非常大的优势.
解决方法是使用像m4这样的宏处理器,或者使用php来模拟宏的效果.还有其他要考虑的技术吗?
也许很明显,但 C 预处理器可以完成这项工作。
索引._html
#define _em(a) <em> a </em>
#define _image(a, b) <img src="a" b/>
#define _list(a, b, c) <h1> a </h1> \
<ul> \
<li> b </li> \
<li> c </li> \
</ul>
<!-- ___________________________________________________ -->
<!doctype html>
<html>
#define _theTile The Bar Title
#include "head._html"
<body>
_list(foo, bar, bean)
This is really _em(great)
_image(media/cat.jpg, )
_image(media/dog.jpg, width="25%" height="10px")
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
成为头._html
<head>
<meta charset="utf-8"/>
<title> _theTile </title>
<!-- more stuff ... -->
</head>
Run Code Online (Sandbox Code Playgroud)
然后,
cpp -P index._html > index.html
Run Code Online (Sandbox Code Playgroud)
产生:
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title> The Bar Title </title>
<!-- more stuff ... -->
</head>
<body>
<h1> foo </h1> <ul> <li> bar </li> <li> bean </li> </ul>
This is really <em> great </em>
<img src="media/cat.jpg" />
<img src="media/dog.jpg" width="25%" height="10px"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)