index.js
function validateCodeBlock (codeBlock, file) {
  var lang = codeBlock.lang;
  var code = codeBlock.code;

  if (lang === 'json') {
    try {
      JSON.parse(code);
    } catch (e) {
      console.log(e);
      console.log(code);
      return false;
    }
    return true;
  } else if (lang === 'js' || lang === 'javascript') {
    code = preprocessCode(code);
    try {
      esprima.parse(code, { tolerant: true });
    } catch (e) {

      // Get indeces from lineNumber and column
      var line   = e.lineNumber - 1;
      var column = e.column - 1;

      // Highlight error in code
      code = code.split('\n');

      code[line] = code[line].slice(0, column).magenta +
                   code[line][column].red +
                   code[line].slice(column + 1).magenta;

      code = code.join('\n');

      if (!didLogFileBreak) {
        logFileBreak(file);
        didLogFileBreak = true;
      }

      console.log(e);
      console.log(code);

      return false;
    }
    return true;
  }
}
function validateCodeBlock (codeBlock, file) {
  var lang = codeBlock.lang;
  var code = codeBlock.code;

  if (lang === 'json') {
    try {
      JSON.parse(code);
    } catch (e) {
      console.log(e);
      console.log(code);
      return false;
    }
    return true;
  } else if (lang === 'js' || lang === 'javascript') {
    code = preprocessCode(code);
    try {
      esprima.parse(code, { tolerant: true });
    } catch (e) {

      // Get indeces from lineNumber and column
      var line   = e.lineNumber - 1;
      var column = e.column - 1;

      // Highlight error in code
      code = code.split('\n');

      code[line] = code[line].slice(0, column).magenta +
                   code[line][column].red +
                   code[line].slice(column + 1).magenta;

      code = code.join('\n');

      if (!didLogFileBreak) {
        logFileBreak(file);
        didLogFileBreak = true;
      }

      console.log(e);
      console.log(code);

      return false;
    }
    return true;
  }
}
function validateCodeBlock ( codeBlock , file ) { var lang = codeBlock . lang ; var code = codeBlock . code ; if ( lang === 'json' ) { try { JSON . parse ( code ) ; } catch ( e ) { console . log ( e ) ; console . log ( code ) ; return false ; } return true ; } else if ( lang === 'js' || lang === 'javascript' ) { code = preprocessCode ( code ) ; try { esprima . parse ( code , { tolerant : true } ) ; } catch ( e ) { // Get indeces from lineNumber and column var line = e . lineNumber - 1 ; var column = e . column - 1 ; // Highlight error in code code = code . split ( '\n' ) ; code [ line ] = code [ line ] . slice ( 0 , column ) . magenta + code [ line ] [ column ] . red + code [ line ] . slice ( column + 1 ) . magenta ; code = code . join ( '\n' ) ; if ( ! didLogFileBreak ) { logFileBreak ( file ) ; didLogFileBreak = true ; } console . log ( e ) ; console . log ( code ) ; return false ; } return true ; } }
Validates that code blocks are valid JavaScript
@param  {Object} code A block of code from the markdown file containg the lang and code
@param  {String} file Name of file currently being validated
Validates that code blocks are valid JavaScript