Highlight all code elements @param {Function(lang, body) -> String} highlight @param {HTMLDom} $ @return {Promise}
(highlight, $)
| 39 | @return {Promise} |
| 40 | */ |
| 41 | function highlightCode(highlight, $) { |
| 42 | return editHTMLElement($, 'code', function($code) { |
| 43 | var classNames = ($code.attr('class') || '').split(' '); |
| 44 | var lang = getLanguageForClass(classNames); |
| 45 | var source = $code.text(); |
| 46 | |
| 47 | return Promise(highlight(lang, source)) |
| 48 | .then(function(r) { |
| 49 | if (is.string(r.html)) { |
| 50 | $code.html(r.html); |
| 51 | } else { |
| 52 | $code.text(r.text); |
| 53 | } |
| 54 | }); |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | module.exports = highlightCode; |
no test coverage detected
searching dependent graphs…