Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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>
  <h1>A. Heading Level Demo</h1>
  <p>
    This is an example for my blog post <cite><a href="http://adrianroselli.com/2016/08/there-is-no-document-outline-algorithm.html">There Is No Document Outline Algorithm</a></cite>.
  </p>
  <p>
    A proof of concept where the same chunks of content with the same headings adapt their headings based on the nesting level of a container. All of this is via a <code>data-level</code> attribute.
  </p>
  <div>
    <section data-level="2">
      <h1>B. Heading Level Demo</h1>
      <p>
        A proof of concept where the same chunks of content with the same headings adapt their headings based on the nesting level of a container. All of this is via a <code>data-level</code> attribute.
      </p>
    </section>
    <section data-level="3">
      <h1>C. Heading Level Demo</h1>
      <p>
        A proof of concept where the same chunks of content with the same headings adapt their headings based on the nesting level of a container. All of this is via a <code>data-level</code> attribute.
      </p>
    </section>
  </div>
  <div>
    <section data-level="2">
      <h1>D. Heading Level Demo</h1>
      <p>
        A proof of concept where the same chunks of content with the same headings adapt their headings based on the nesting level of a container. All of this is via a <code>data-level</code> attribute.
      </p>
    </section>
    <section data-level="3">
      <h1>E. Heading Level Demo</h1>
      <p>
        A proof of concept where the same chunks of content with the same headings adapt their headings based on the nesting level of a container. All of this is via a <code>data-level</code> attribute.
      </p>
    </section>
    <section data-level="3">
      <h1>F. Heading Level Demo</h1>
      <p>
        A proof of concept where the same chunks of content with the same headings adapt their headings based on the nesting level of a container. All of this is via a <code>data-level</code> attribute.
      </p>
    </section>
  </div>
</main>
              
            
!

CSS

              
                body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
}

h1,
h2,
h3 {
  color: #000;
  font-size: 1.75em;
  margin: 0;
}

h2 {
  color: #009;
}

h2::after {
  content: " (h2)"
}

h3 {
  color: #060;
}

h3::after {
  content: " (h3)"
}

main {
  display: block;
  box-sizing: border-box;
  width: 90%;
  margin: 1em auto;
  padding: 1em 2em;
  color: #000;
  border: .07em solid rgba(0, 0, 0, .5);
  border-radius: .5em;
}

@media all and (min-width: 42em) {
  main div {
    display: inline-flex;
    justify-content: space-between;
    width: 100%;
  }
  main div section {
    width: 45%;
  }
  main div + div section {
    width: 30%;
  }
}
              
            
!

JS

              
                /*
THIS IS NOT PRODUCTION READY. DO NOT USE IN PRODUCTION.
*/

function remapHeadings() {
  try {
    // Loop through all 6 levels of headings (I limited it to just 1 here)
    for (var i = 1; i < 2; i++) {
      // Get the heading for the current level
      var headings = document.getElementsByTagName('h' + i);
      // Set the number of headings else it will change and this will stop early
      var headingCount = headings.length;
      // Loop through each of those headings, but
      // since it is a live collection, loop backward
      for (j = headings.length - 1; j >= 0; j--) {
        thisHeading = headings[j];
        // Get the text of the heading
        var headingText = thisHeading.innerText;
        // Find its parent...
        var level = thisHeading.parentElement;
        // ...and then the data-level attribute
        var levelNum = level.getAttribute('data-level');
        // Do not do anything if there is no data-level value
        if (levelNum !== null) {
          // Create new heading using the data-level
          var newHeading = document.createElement('h' + levelNum);
          // Create a text node for the new heading
          var newHeadingTXT = document.createTextNode(headingText);
          // Set the text content of the new heading
          newHeading.appendChild(newHeadingTXT);
          // Replace the old heading
          level.replaceChild(newHeading, thisHeading);
        }
        // A little debugging
        //console.log("h?: "+headingCount+", i: "+i+", j: "+j+", lvl: "+levelNum+", H#: "+headingText);
      }
    }
  } catch (e) {
    console.log('RemapHeadings(): ' + e);
  }
}

remapHeadings();
              
            
!
999px

Console