code: function findBlocks(editor, modeName) {
          // Start scanning from beginning of file
          var ctx = TokenUtils.getInitialContext(editor._codeMirror, {line: 0, ch: 0}),
              blocks = [],
              currentBlock = null,
              inBlock = false,
              outerMode = editor._codeMirror.getMode(),
              tokenModeName,
              previousMode;
  
          while (TokenUtils.moveNextToken(ctx, false)) {
              tokenModeName = CodeMirror.innerMode(outerMode, ctx.token.state).mode.name;
              if (inBlock) {
                  if (!currentBlock.end) {
                      // Handle empty blocks
                      currentBlock.end = currentBlock.start;
                  }
                  // Check for end of this block
                  if (tokenModeName === previousMode) {
                      // currentBlock.end is already set to pos of the last token by now
                      currentBlock.text = editor.document.getRange(currentBlock.start, currentBlock.end);
                      inBlock = false;
                  } else {
                      currentBlock.end = { line: ctx.pos.line, ch: ctx.pos.ch };
                  }
              } else {
                  // Check for start of a block
                  if (tokenModeName === modeName) {
                      currentBlock = {
                          start: { line: ctx.pos.line, ch: ctx.pos.ch }
                      };
                      blocks.push(currentBlock);
                      inBlock = true;
                  } else {
                      previousMode = tokenModeName;
                  }
                  // else, random token: ignore
              }
          }
  
          return blocks;
      }
docs: Returns an Array of info about all blocks whose token mode name matches that passed in,
  in the given Editor's HTML document (assumes the Editor contains HTML text).
  @param {!Editor} editor - the editor containing the HTML text
  @param {string} modeName - the mode name of the tokens to look for
  @return {Array.<{start:{line:number, ch:number}, end:{line:number, ch:number}, text:string}>}