|
5 | 5 |
|
6 | 6 | var defaultPaddingBottom = 100 / CONFIG.DEFAULT_ASPECT_RATIO; |
7 | 7 |
|
| 8 | + function createCheerioElement(name) { |
| 9 | + return cheerio.load(`<${name}></${name}>`)(name); |
| 10 | + } |
| 11 | + |
8 | 12 | function wrapContainer($element, data, options) { |
9 | 13 |
|
10 | 14 | var aspectWrapperClass = options && options.aspectWrapperClass; |
|
30 | 34 | } |
31 | 35 | } |
32 | 36 |
|
33 | | - var $container = cheerio('<div>') |
| 37 | + var $container = createCheerioElement('div') |
34 | 38 | .append($element); |
35 | 39 |
|
36 | 40 | if (aspectWrapperClass) { |
|
45 | 49 | var hasMaxWidth = media && (media["max-width"] || media["min-width"] || media["width"] || verticalAspect); |
46 | 50 |
|
47 | 51 | if (hasMaxWidth || forceWidthLimitContainer) { |
48 | | - $widthLimitContainer = cheerio('<div>') |
| 52 | + $widthLimitContainer = createCheerioElement('div') |
49 | 53 | .append($container); |
50 | 54 | } |
51 | 55 |
|
|
166 | 170 | && data.href; |
167 | 171 | }, |
168 | 172 | generate: function(data) { |
169 | | - var $img = cheerio('<img>') |
| 173 | + var $img = createCheerioElement('img') |
170 | 174 | .attr('src', data.href); |
171 | 175 | if (data.title) { |
172 | 176 | $img |
|
190 | 194 | var givf = data.rel.indexOf('gifv') > -1; |
191 | 195 | var autoplay = data.rel.indexOf('autoplay') > -1 || givf; |
192 | 196 |
|
193 | | - var $video = cheerio('<video' + (givf ? ' loop muted webkit-playsinline' : ' controls') + (autoplay ? ' autoplay' : '') + '>Your browser does not support HTML5 video.</video>'); |
| 197 | + var $video = cheerio.load('<video' + (givf ? ' loop muted webkit-playsinline' : ' controls') + (autoplay ? ' autoplay' : '') + '>Your browser does not support HTML5 video.</video>')('video'); |
194 | 198 |
|
195 | 199 | if (iframelyData && iframelyData.links) { |
196 | 200 |
|
|
279 | 283 | return data.type === "text/html" && data.href; |
280 | 284 | }, |
281 | 285 | generate: function(data, options) { |
282 | | - |
283 | | - var $iframe = cheerio('<iframe>') |
| 286 | + var $iframe = createCheerioElement('iframe') |
284 | 287 | .attr('src', data.href) |
285 | 288 | .css('border', '0') |
286 | 289 | .attr('allowfullscreen', ''); |
|
334 | 337 | } |
335 | 338 | }; |
336 | 339 |
|
337 | | - export function generateElementWrapperHtml(element, link, options) { |
338 | | - |
339 | | - if (typeof element === 'string') { |
340 | | - element = cheerio(element); |
341 | | - } |
342 | | - |
343 | | - var $el = wrapContainer(element, link, options); |
344 | | - return cheerio('<div>').append($el).html(); |
345 | | - }; |
346 | | - |
347 | 340 | export function generateLinkElementHtml(link, options) { |
348 | 341 | var $el = generateLinkElement(link, options); |
349 | 342 | if (_.isString($el)) { |
|
352 | 345 | if (options && options.canonical && link.href !== options.canonical) { |
353 | 346 | $el.attr('data-embed-canonical', options.canonical); |
354 | 347 | } |
355 | | - return cheerio('<div>').append($el).html(); |
| 348 | + return $el.prop('outerHTML'); |
356 | 349 | } else { |
357 | 350 | return ''; |
358 | 351 | } |
|
0 commit comments