dist/showdown.js
function substitutePreCodeTags (doc) {

      var pres = doc.querySelectorAll('pre'),
          presPH = [];

      for (var i = 0; i < pres.length; ++i) {

        if (pres[i].childElementCount === 1 && pres[i].firstChild.tagName.toLowerCase() === 'code') {
          var content = pres[i].firstChild.innerHTML.trim(),
              language = pres[i].firstChild.getAttribute('data-language') || '';

          // if data-language attribute is not defined, then we look for class language-*
          if (language === '') {
            var classes = pres[i].firstChild.className.split(' ');
            for (var c = 0; c < classes.length; ++c) {
              var matches = classes[c].match(/^language-(.+)$/);
              if (matches !== null) {
                language = matches[1];
                break;
              }
            }
          }

          // unescape html entities in content
          content = showdown.helper.unescapeHTMLEntities(content);

          presPH.push(content);
          pres[i].outerHTML = '<precode language="' + language + '" precodenum="' + i.toString() + '"></precode>';
        } else {
          presPH.push(pres[i].innerHTML);
          pres[i].innerHTML = '';
          pres[i].setAttribute('prenum', i.toString());
        }
      }
      return presPH;
    }
function substitutePreCodeTags (doc) {

      var pres = doc.querySelectorAll('pre'),
          presPH = [];

      for (var i = 0; i < pres.length; ++i) {

        if (pres[i].childElementCount === 1 && pres[i].firstChild.tagName.toLowerCase() === 'code') {
          var content = pres[i].firstChild.innerHTML.trim(),
              language = pres[i].firstChild.getAttribute('data-language') || '';

          // if data-language attribute is not defined, then we look for class language-*
          if (language === '') {
            var classes = pres[i].firstChild.className.split(' ');
            for (var c = 0; c < classes.length; ++c) {
              var matches = classes[c].match(/^language-(.+)$/);
              if (matches !== null) {
                language = matches[1];
                break;
              }
            }
          }

          // unescape html entities in content
          content = showdown.helper.unescapeHTMLEntities(content);

          presPH.push(content);
          pres[i].outerHTML = '<precode language="' + language + '" precodenum="' + i.toString() + '"></precode>';
        } else {
          presPH.push(pres[i].innerHTML);
          pres[i].innerHTML = '';
          pres[i].setAttribute('prenum', i.toString());
        }
      }
      return presPH;
    }
function substitutePreCodeTags ( doc ) { var pres = doc . querySelectorAll ( 'pre' ) , presPH = [ ] ; for ( var i = 0 ; i < pres . length ; ++ i ) { if ( pres [ i ] . childElementCount === 1 && pres [ i ] . firstChild . tagName . toLowerCase ( ) === 'code' ) { var content = pres [ i ] . firstChild . innerHTML . trim ( ) , language = pres [ i ] . firstChild . getAttribute ( 'data-language' ) || '' ; // if data-language attribute is not defined, then we look for class language-* if ( language === '' ) { var classes = pres [ i ] . firstChild . className . split ( ' ' ) ; for ( var c = 0 ; c < classes . length ; ++ c ) { var matches = classes [ c ] . match ( / ^language-(.+)$ / ) ; if ( matches !== null ) { language = matches [ 1 ] ; break ; } } } // unescape html entities in content content = showdown . helper . unescapeHTMLEntities ( content ) ; presPH . push ( content ) ; pres [ i ] . outerHTML = '<precode language="' + language + '" precodenum="' + i . toString ( ) + '"></precode>' ; } else { presPH . push ( pres [ i ] . innerHTML ) ; pres [ i ] . innerHTML = '' ; pres [ i ] . setAttribute ( 'prenum' , i . toString ( ) ) ; } } return presPH ; }
find all pre tags and replace contents with placeholder we need this so that we can remove all indentation from html to ease up parsing
find all pre tags and replace contents with placeholder we need this so that we can remove all indentation from html to ease up parsing