import re


def _convert_to_code(val):
    """
    Convert ' to code(`) or ''' code blocks(```) and convert ' within code blocks to "
      e.g.: 'display_name' converts to `display_name`
      e.g.: '''pip install -U 'resilient-circuits'''' converts to
            ```shell
            $ pip install -U "resilient-circuits"
            ```
    """
    return re.sub(r"'{3}(.*)'(.*)'(.*)'{3}", r'\n\n```shell\n$ \1"\2"\3\n```\n', val).replace("'", "`").replace("\t\t", "\t")