def _replace_ipynb_code_cell(ipynb_dict, source_code, code_cell_idx):
    """
    Replace the source code of the code cell of the specified
    index.

    Parameters
    ----------
    ipynb_dict : dict
        Dictionary of notebook data.
    source_code : str
        Source code to set.
    code_cell_idx : int
        The index of the target code cell.

    Returns
    -------
    ipynb_dict : dict
        Dictionary of notebook after replacement.
    """
    cell_dict = ipynb_dict['cells'][code_cell_idx]
    source_code = source_code.strip()
    source_code_line_list = source_code.split('\n')
    for i, source_code in enumerate(source_code_line_list):
        source_code_line_list[i] = source_code + '\n'
    cell_dict['source'] = source_code_line_list
    return ipynb_dict