1- import cheerio from 'cheerio' ;
2-
3- import * as _ from 'underscore' ;
1+ import * as cheerio from 'cheerio' ;
42 import CONFIG from '../config.loader.js' ;
53
64 var defaultPaddingBottom = 100 / CONFIG . DEFAULT_ASPECT_RATIO ;
75
6+ function createCheerioElement ( name ) {
7+ return cheerio . load ( `<${ name } ></${ name } >` ) ( name ) ;
8+ }
9+
810 function wrapContainer ( $element , data , options ) {
911
1012 var aspectWrapperClass = options && options . aspectWrapperClass ;
3032 }
3133 }
3234
33- var $container = cheerio ( '< div> ')
35+ var $container = createCheerioElement ( ' div')
3436 . append ( $element ) ;
3537
3638 if ( aspectWrapperClass ) {
4547 var hasMaxWidth = media && ( media [ "max-width" ] || media [ "min-width" ] || media [ "width" ] || verticalAspect ) ;
4648
4749 if ( hasMaxWidth || forceWidthLimitContainer ) {
48- $widthLimitContainer = cheerio ( '< div> ')
50+ $widthLimitContainer = createCheerioElement ( ' div')
4951 . append ( $container ) ;
5052 }
5153
166168 && data . href ;
167169 } ,
168170 generate : function ( data ) {
169- var $img = cheerio ( '< img> ')
171+ var $img = createCheerioElement ( ' img')
170172 . attr ( 'src' , data . href ) ;
171173 if ( data . title ) {
172174 $img
190192 var givf = data . rel . indexOf ( 'gifv' ) > - 1 ;
191193 var autoplay = data . rel . indexOf ( 'autoplay' ) > - 1 || givf ;
192194
193- var $video = cheerio ( '<video' + ( givf ? ' loop muted webkit-playsinline' : ' controls' ) + ( autoplay ? ' autoplay' : '' ) + '>Your browser does not support HTML5 video.</video>' ) ;
195+ var $video = cheerio . load ( '<video' + ( givf ? ' loop muted webkit-playsinline' : ' controls' ) + ( autoplay ? ' autoplay' : '' ) + '>Your browser does not support HTML5 video.</video>' ) ( 'video ') ;
194196
195197 if ( iframelyData && iframelyData . links ) {
196198
279281 return data . type === "text/html" && data . href ;
280282 } ,
281283 generate : function ( data , options ) {
282-
283- var $iframe = cheerio ( '<iframe>' )
284+ var $iframe = createCheerioElement ( 'iframe' )
284285 . attr ( 'src' , data . href )
285286 . css ( 'border' , '0' )
286287 . attr ( 'allowfullscreen' , '' ) ;
334335 }
335336 } ;
336337
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-
347338 export function generateLinkElementHtml ( link , options ) {
348339 var $el = generateLinkElement ( link , options ) ;
349- if ( _ . isString ( $el ) ) {
340+ if ( typeof $el === 'string' ) {
350341 return $el ;
351342 } else if ( $el ) {
352343 if ( options && options . canonical && link . href !== options . canonical ) {
353344 $el . attr ( 'data-embed-canonical' , options . canonical ) ;
354345 }
355- return cheerio ( '<div>' ) . append ( $el ) . html ( ) ;
346+ return $el . prop ( 'outerHTML' ) ;
356347 } else {
357348 return '' ;
358349 }
647638 sortLinks ( iframely_data . links , options . autoplayMode ) ;
648639 }
649640
650- var player = iframely_data && _ . find ( iframely_data . links , findPlayer ) ;
641+ var player = iframely_data ?. links . find ( findPlayer ) ;
651642
652643 if ( player ) {
653644
674665 }
675666
676667 function getInlineApp ( iframely_data ) {
677- return iframely_data && _ . find ( iframely_data . links , function ( l ) {
668+ return iframely_data ?. links . find ( function ( l ) {
678669 // `html` can be added by `generateLinksHtml`, so also check if no `href`.
679670 return l . html && ! l . href && l . type === 'text/html' ;
680671 } ) ;
706697 }
707698
708699 return selectedLink ;
709- } ;
700+ } ;
0 commit comments