def convert_rst_formatting()

in utils/convert_doc_to_notebooks.py [0:0]


def convert_rst_formatting(text):
    """ Convert rst syntax for formatting to markdown in text."""
    # Remove :class:, :func: and :meth: markers. Simplify what's inside and put double backquotes
    # (to not be caught by the italic conversion).
    def _rep_func_class(match):
        name = match.groups()[0]
        splits = name.split('.')
        i = 0
        while i < len(splits)-1 and not splits[i][0].isupper():
            i += 1
        return f"``{'.'.join(splits[i:])}``"
    text = _re_func_class.sub(_rep_func_class, text)
    # Remove :obj: markers. What's after is in a single backquotes so we put in double backquotes 
    # (to not be caught by the italic conversion).
    text = _re_obj.sub(r"``\1``", text)
    # Remove :math: markers.
    text = _re_math.sub(r"$\1$", text)
    # Convert content in stars to bold
    text = _re_stars.sub(r'**\1**', text)
    # Convert content in single backquotes to italic.
    text = _re_single_backquotes.sub(r'\1*\2*\3', text)
    # Convert content in double backquotes to single backquotes.
    text = _re_double_backquotes.sub(r'`\1`', text)
    # Remove remaining ::
    text = re.sub(r"::\n", "", text)
    return text