hexo
Version:
A fast, simple & powerful blog framework, powered by Node.js.
37 lines (33 loc) • 634 B
JavaScript
/**
* Creates a snippet of HTML tag.
*
* **Examples:**
*
* ```
* html_tag('a', {href: 'http://www.google.com'}, 'Google');
* html_tag('img', {src: 'foo.jpg'});
* ```
*
* yields:
*
* ```
* <a href="http://www.google.com">Google</a>
* <img src="foo.jpg">
* ```
*
* @method html_tag
* @param {String} tag
* @param {Object} attrs
* @param {String} [text]
* @return {String}
* @for util
* @static
*/
module.exports = function(tag, attrs, text){
var result = '<' + tag;
for (var i in attrs){
if (attrs[i]) result += ' ' + i + '="' + attrs[i] + '"';
}
result += text ? '>' + text + '</' + tag + '>' : '>';
return result;
};