<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def preprocess_notebook(ntbk, cr):
 """ Process notebook object `ntbk` in preparation for conversion to an rst document. This processing replaces links to online docs with corresponding sphinx cross-references within the local docs. Parameter `cr` is a CrossReferenceLookup object. """


    # Iterate over cells in notebook
    for n in range(len(ntbk['cells'])):
        # Only process cells of type 'markdown'
        if ntbk['cells'][n]['cell_type'] == 'markdown':
            # Get text of markdown cell
            txt = ntbk['cells'][n]['source']
            # Replace links to online docs with sphinx cross-references
            txt = cr.substitute_url_with_ref(txt)
            # Replace current cell text with processed text
            ntbk['cells'][n]['source'] = txt