Added Inline Style Support

This commit is contained in:
CRIMX 2017-06-26 15:51:51 +08:00
parent 0910a7bdb4
commit 2a6607ed9d

View file

@ -88,28 +88,40 @@ if (options.enable !== false) {
}) })
hexo.extend.helper.register('github_emoji', function (name) { hexo.extend.helper.register('github_emoji', function (name) {
return getRender(name); return getRender(name)
}); })
function getRender (emojiName) { function getRender (emojiName) {
if (emojis[emojiName]) { emojiName = String(emojiName)
var codepoints = emojis[emojiName].codepoints if (!emojis[emojiName]) { return emojiName }
if (options.unicode && codepoints) {
codepoints = codepoints.map(function (code) {
return '&#x' + code + ';'
}).join('')
return '<span class="' + options.className + var styles = ''
'" title="' + emojiName + if (_.isObject(options.styles)) {
'" data-src="' + emojis[emojiName].src + // inline styles
'">' + codepoints + '</span>' styles = 'style="' +
} else { Object.keys(options.styles)
return '<img class="' + options.className + .filter(function (k) { return _.isString(options.styles[k]) })
'" title="' + emojiName + '" alt="' + emojiName + '" src="' + .map(function (k) { return k + ':' + options.styles[k] })
emojis[emojiName].src + '" height="20" width="20" />' .join(';') +
} '"'
}
var codepoints = emojis[emojiName].codepoints
if (options.unicode && codepoints) {
codepoints = codepoints.map(function (code) {
return '&#x' + code + ';'
}).join('')
return '<span class="' + options.className + '" ' +
styles +
' title="' + emojiName +
'" data-src="' + emojis[emojiName].src +
'">' + codepoints + '</span>'
} else { } else {
return emojiName; return '<img class="' + options.className + '" ' +
styles +
' title="' + emojiName + '" alt="' + emojiName + '" src="' +
emojis[emojiName].src + '" height="20" width="20" />'
} }
} }
} }