<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def script_string_to_notebook_with_links(str, pth, cr=None):
 """ Convert a python script represented as string `str` to a notebook with filename `pth` and replace sphinx cross-references with links to online docs. Parameter `cr` is a CrossReferenceLookup object. """


    if cr is None:
        script_string_to_notebook(str, pth)
    else:
        ntbk = script_string_to_notebook_object(str)
        notebook_substitute_ref_with_url(ntbk, cr)
        with open(pth, 'wt') as f:
            nbformat.write(ntbk, f)