import json


def _mds(s, iscode=False):
    """
    Convert a string to a 'markdown' string by escaping control and syntax highlighting characters

    :param s: The string to escape
    :param iscode: The string appears in a (tick)(tick)code(tick)(tick) block
    :return: The escaped string
    """
    # P Is this json?

    if iscode and type(s) == dict:
        try:
            js = json.dumps(s, sort_keys=True, indent=4, separators=(',', ': '))
            return js
        except:
            return s
            pass
    elif iscode:
        return s
    else:
        ms = s.replace("_", "\_")

    return ms