Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main class="cte">
  <p>Shortcodes de type {{ mustache }} :</p>
  {{https://www.youtube.com/watch?v=3Bs4LOtIuxg}}
  <p class="message">Ici le code est en front dans son entièreté, mais au final le thumbnail est côté back (sous Node.js). Pour le PHP il faudra peut-être adapter la regex. Pour le code avec la vidéo en direct <a href="https://codepen.io/olivier-c/pen/WNXggjQ?editors=1010">c'est ici</a>.<br><s>Pour l'instant cette solution n'est pas accessible</s> (édit. : c'est bon).</p>
  <hr>
  <p>Si thumbnail servi côté serveur :</p>
  <div class="video video-click"><a href="#" class="thumbnail-youtube" style="background-image: url('https://img.youtube.com/vi/3Bs4LOtIuxg/maxresdefault.jpg')"></a></div>
</main>
              
            
!

CSS

              
                .video
  position relative
  padding-bottom 56.25%
  background-color #000
  box-shadow .5rem .5rem 2rem rgba(0, 0, 0, .25)
  user-select none
  & iframe
  & embed
  & object
    position absolute
    border none

.thumbnail-youtube
  position absolute
  width 100%
  height 100%
  background-size cover
  cursor pointer
  &:focus-within
  &:hover
    outline 5px solid Orange

// for demo: /////////////////////////////////////////////////////////////////////////

_hrSize = 5px

html
.message
  font-family Ubuntu, Roboto, Arial, sans-serif
  color #e9dac5
  background-color #444
  
body
  max-width 40em
  margin 0 auto
  font-size 1.2em
a
  text-decoration none

main
  margin 2em

hr
  //clear both
  overflow visible // @bugfix Show the overflow @affected Edge and IE.
  box-sizing content-box // @bugfix Add the correct box sizing @affected Firefox.
  height .5em // @bugfix Add the correct box sizing @affected Firefox @note Toujours définir une valeur.
  margin 2.5em 0
  color transparent // inherit // @bugfix Reset gray color. @affected Firefox.
  background-image repeating-linear-gradient(-45deg, transparent 0 _hrSize, rgba(255, 255, 255, .1) _hrSize _hrSize * 2)
  border none

iframe
  overflow hidden
  width 100%
  height 100%
  border none

[class*=message]
  padding 1em
  border-radius .2em
  background-color #515151
  box-shadow .5rem .5rem 2rem rgba(0, 0, 0, .15)
  & a
    color #fff
    &:hover
      text-decoration underline

              
            
!

JS

              
                /**
  * Thumbnail YouTube en qualité maximale :
  https://img.youtube.com/vi/<idVideoYoutube>/maxresdefault.jpg
  * @see https://www.thewebtaylor.com/articles/how-to-get-a-youtube-videos-thumbnail-image-in-high-quality
  * @toto oEmbed @see https://oembed.com/ @example : https://youtube.com/oembed?url=http://www.youtube.com/watch?v=3Bs4LOtIuxg&format=json
*/

const customTemplateEngine = (() => {

  const youtubeVideo = (() => {

    document.querySelectorAll('.cte').forEach(
      e => e.innerHTML = e.innerHTML.replace(
        /{{https:\/\/www.youtube.com\/watch\?v=(.*?)}}/g,
        '<div class="video video-click"><a href="#" class="thumbnail-youtube" style="background-image: url(\'https://img.youtube.com/vi/$1/maxresdefault.jpg\')"></a></div>'
      )
    )

    document.querySelectorAll('.video-click').forEach(e => {
      e.addEventListener('click', () => {
        e.innerHTML = e.innerHTML.replace(/^.*\/vi\/([\w]*)\/.*$/, '<iframe title="" src="https://www.youtube.com/embed/$1?feature=oembed" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
      })
    })

  })()

})()

              
            
!
999px

Console