我会做的很棒
<define tag="myTag" options="3"> <h1> #1 </h1> <ul> <li> #2 <li> #3 </ul> </define>
然后使用它:
<myTag option="foo" option="bar" option="bean" />
我认为宏是
真的很大的优势.
也许显而易见,但C预处理器可以完成这项工作.
index._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>
是head._html
<head> <Meta charset="utf-8"/> <title> _theTile </title> <!-- more stuff ... --> </head>
然后,
cpp -P index._html > index.html
生产:
<!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>