docs: function to_normal(stream, state) {
      var token = null;
  
      if (stream.sol() && stream.match(rx_examples, false)) {
        change(state, to_mode, {
          mode: mode_python, local: CodeMirror.startState(mode_python)
        });
      } else if (stream.sol() && stream.match(rx_explicit)) {
        change(state, to_explicit);
        token = 'meta';
      } else if (stream.sol() && stream.match(rx_section)) {
        change(state, to_normal);
        token = 'header';
      } else if (phase(state) == rx_role_pre ||
                 stream.match(rx_role_pre, false)) {
  
        switch (stage(state)) {
        case 0:
          change(state, to_normal, context(rx_role_pre, 1));
          assert(stream.match(/^:/));
          token = 'meta';
          break;
        case 1:
          change(state, to_normal, context(rx_role_pre, 2));
          assert(stream.match(rx_NAME));
          token = 'keyword';
  
          if (stream.current().match(/^(?:math|latex)/)) {
            state.tmp_stex = true;
          }
          break;
        case 2:
          change(state, to_normal, context(rx_role_pre, 3));
          assert(stream.match(/^:`/));
          token = 'meta';
          break;
        case 3:
          if (state.tmp_stex) {
            state.tmp_stex = undefined; state.tmp = {
              mode: mode_stex, local: CodeMirror.startState(mode_stex)
            };
          }
  
          if (state.tmp) {
            if (stream.peek() == '`') {
              change(state, to_normal, context(rx_role_pre, 4));
              state.tmp = undefined;
              break;
            }
  
            token = state.tmp.mode.token(stream, state.tmp.local);
            break;
          }
  
          change(state, to_normal, context(rx_role_pre, 4));
          assert(stream.match(rx_TEXT2));
          token = 'string';
          break;
        case 4:
          change(state, to_normal, context(rx_role_pre, 5));
          assert(stream.match(/^`/));
          token = 'meta';
          break;
        case 5:
          change(state, to_normal, context(rx_role_pre, 6));
          assert(stream.match(rx_TAIL));
          break;
        default:
          change(state, to_normal);
          assert(stream.current() == '');
        }
      } else if (phase(state) == rx_role_suf ||
                 stream.match(rx_role_suf, false)) {
  
        switch (stage(state)) {
        case 0:
          change(state, to_normal, context(rx_role_suf, 1));
          assert(stream.match(/^`/));
          token = 'meta';
          break;
        case 1:
          change(state, to_normal, context(rx_role_suf, 2));
          assert(stream.match(rx_TEXT2));
          token = 'string';
          break;
        case 2:
          change(state, to_normal, context(rx_role_suf, 3));
          assert(stream.match(/^`:/));
          token = 'meta';
          break;
        case 3:
          change(state, to_normal, context(rx_role_suf, 4));
          assert(stream.match(rx_NAME));
          token = 'keyword';
          break;
        case 4:
          change(state, to_normal, context(rx_role_suf, 5));
          assert(stream.match(/^:/));
          token = 'meta';
          break;
        case 5:
          change(state, to_normal, context(rx_role_suf, 6));
          assert(stream.match(rx_TAIL));
          break;
        default:
          change(state, to_normal);
          assert(stream.current() == '');
        }
      } else if (phase(state) == rx_role || stream.match(rx_role, false)) {
  
        switch (stage(state)) {
        case 0:
          change(state, to_normal, context(rx_role, 1));
          assert(stream.match(/^:/));
          token = 'meta';
          break;
        case 1:
          change(state, to_normal, context(rx_role, 2));
          assert(stream.match(rx_NAME));
          token = 'keyword';
          break;
        case 2:
          change(state, to_normal, context(rx_role, 3));
          assert(stream.match(/^:/));
          token = 'meta';
          break;
        case 3:
          change(state, to_normal, context(rx_role, 4));
          assert(stream.match(rx_TAIL));
          break;
        default:
          change(state, to_normal);
          assert(stream.current() == '');
        }
      } else if (phase(state) == rx_substitution_ref ||
                 stream.match(rx_substitution_ref, false)) {
  
        switch (stage(state)) {
        case 0:
          change(state, to_normal, context(rx_substitution_ref, 1));
          assert(stream.match(rx_substitution_text));
          token = 'variable-2';
          break;
        case 1:
          change(state, to_normal, context(rx_substitution_ref, 2));
          if (stream.match(/^_?_?/)) token = 'link';
          break;
        default:
          change(state, to_normal);
          assert(stream.current() == '');
        }
      } else if (stream.match(rx_footnote_ref)) {
        change(state, to_normal);
        token = 'quote';
      } else if (stream.match(rx_citation_ref)) {
        change(state, to_normal);
        token = 'quote';
      } else if (stream.match(rx_link_ref1)) {
        change(state, to_normal);
        if (!stream.peek() || stream.peek().match(/^\W$/)) {
          token = 'link';
        }
      } else if (phase(state) == rx_link_ref2 ||
                 stream.match(rx_link_ref2, false)) {
  
        switch (stage(state)) {
        case 0:
          if (!stream.peek() || stream.peek().match(/^\W$/)) {
            change(state, to_normal, context(rx_link_ref2, 1));
          } else {
            stream.match(rx_link_ref2);
          }
          break;
        case 1:
          change(state, to_normal, context(rx_link_ref2, 2));
          assert(stream.match(/^`/));
          token = 'link';
          break;
        case 2:
          change(state, to_normal, context(rx_link_ref2, 3));
          assert(stream.match(rx_TEXT2));
          break;
        case 3:
          change(state, to_normal, context(rx_link_ref2, 4));
          assert(stream.match(/^`_/));
          token = 'link';
          break;
        default:
          change(state, to_normal);
          assert(stream.current() == '');
        }
      } else if (stream.match(rx_verbatim)) {
        change(state, to_verbatim);
      }
  
      else {
        if (stream.next()) change(state, to_normal);
      }
  
      return token;
    }