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

              
                .js-ide.ide
button.js-reset.button.button--alpha Reset
a(href="https://cld.silvestar.codes" target="_blank").button.button--beta See Project
              
            
!

CSS

              
                body {
  font-size: 16px;
  line-height: calc(20/13);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

::selection {
  background-color: yellowgreen;
  color: black;
}

.ide {
  font-family: monospace;
  flex: 1 1 auto;
  max-width: 800px;
  margin: 100px 0;
  
  p {
    margin: 0;
  }
  
  a {
    color: inherit;
  }
}

.ide__inner {
  background-color: black;
  padding: 0 1rem;
  position: relative;
  border-radius: .25rem;
  
  &:before {
    content: "";
    position: absolute;
    height: .75rem;
    width: .75rem;
    border-radius: .375rem;
    top: .75rem;
    left: 1rem;
    background-color: red;
    box-shadow: 1.25rem 0 0 gold, 2.5rem 0 0 green;
  }
}

.ide__header {
  color: seagreen;
  padding-top: .5rem;
  text-align: center;
}

.ide__body {
  background-color: #333;
  color: lightgreen;
  display: flex;
  flex-direction: column;
  border-radius: .25rem;
  padding: 1rem;
  margin-top: .5rem;
  counter-reset: line;
}

.ide__line {
  counter-increment: line;
  display: flex;

  &:before {
    content: counter(line);
    display: inline-block;
    margin-right: 1rem;
    opacity: 0.5;
  }
}

.ide__footer {
  color: seagreen;
  display: flex;
  justify-content: center;
  padding-top: .5rem;
  padding-bottom: .5rem;
  
  p {
    flex: 0 0 calc(100% / 3);

    &:nth-child(2) {
      text-align: center;
    }
    
    &:nth-child(3) {
      text-align: right;
    }
  }
}

.ide__details {
  font-family: sans-serif;
  margin-top: 1rem;
  
  p {
    &:first-child {
      font-weight: bold;
    }
    
    &:last-child {
      &:before {
        content: "⇒";
        display: inline-block;
        margin-right: .25rem;
        position: relative;
        top: -0.05em;
      }
    }
  }
}

.button {
  background-color: yellowgreen;
  color: black;
  font-family: monospace;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: .25rem;
  padding: .25rem .5rem;
  border: none;
  position: fixed;
  bottom: 1rem;
  cursor: pointer;
}

.button--alpha {
  right: 1rem;
}

.button--beta {
  left: 1rem;
}
              
            
!

JS

              
                const $ide = document.querySelector('.js-ide');
const $reset = document.querySelector('.js-reset');

if($reset) {
  $reset.addEventListener('click', () => {
    // Clear localStorage data and fetch new data
    localStorage.removeItem('cldData');
    getCLD();
  });
}

const htmlEntities = (str) => {
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

const extList = {
  javascript: 'js',
  nodejs: 'js',
}

const ext = (lang) => {
  const l = lang.toLowerCase();
  return extList[l] || l;
}

const buildCLD = (data) => {
  if(!$ide) {
    return false;
  }
  
  $ide.innerHTML = `<div class="ide__inner">
  <div class="ide__header">
    <p><a href="https://cld.silvestar.codes/line/${data.date}/" target="_blank">${data.date}.${ext(data.language)}</a></p>
  </div>
  <div class="ide__body">
    <p class="ide__line">...</p>
    <code class="ide__line">${htmlEntities(data.line)}</code>
    <p class="ide__line">...</p>
  </div>
  <div class="ide__footer">
    <p>Author: ${data.author}</p>
    <p>${data.language}</p>
    <p><a href="https://cld.silvestar.codes/line/${data.date}/" target="_blank">Details</a></p>
  </div>
</div>
<div class="ide__details">
  <p>What does this line do? </p>
  <p>${data.note}</p>
</div>`;
}

// Fetch data from Code Line Daily
const getCLD = () => {
  fetch('https://cld.silvestar.codes/api/get-random-line')
    .then((response) => {
      return response.json();  
    })
    .then((data) => {
      // Build HTML code
      buildCLD(data);
      // Set localStorage data for caching purposes
      localStorage.setItem('cldData', JSON.stringify(data));
    });
}

// Get data from localStorage
const cldData = localStorage.getItem('cldData');
// Parse JSON data, if available
const parsedData = cldData && JSON.parse(cldData);

// Fetch Code Line Daily data if no data in localStorage
// Otherwise append HTML
if(!cldData) {
  getCLD(); 
} else {
  buildCLD(parsedData);
}
              
            
!
999px

Console