Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
escape.py94 linesDownload Raw Back to rules_inline
1"""2Process escaped chars and hardbreaks3"""4 5from ..common.utils import isStrSpace6from .state_inline import StateInline7 8 9def escape(state: StateInline, silent: bool) -> bool:10    """Process escaped chars and hardbreaks."""11    pos = state.pos12    maximum = state.posMax13 14    if state.src[pos] != "\\":15        return False16 17    pos += 118 19    # '\' at the end of the inline block20    if pos >= maximum:21        return False22 23    ch1 = state.src[pos]24    ch1_ord = ord(ch1)25    if ch1 == "\n":26        if not silent:27            state.push("hardbreak", "br", 0)28        pos += 129        # skip leading whitespaces from next line30        while pos < maximum:31            ch = state.src[pos]32            if not isStrSpace(ch):33                break34            pos += 135 36        state.pos = pos37        return True38 39    escapedStr = state.src[pos]40 41    if ch1_ord >= 0xD800 and ch1_ord <= 0xDBFF and pos + 1 < maximum:42        ch2 = state.src[pos + 1]43        ch2_ord = ord(ch2)44        if ch2_ord >= 0xDC00 and ch2_ord <= 0xDFFF:45            escapedStr += ch246            pos += 147 48    origStr = "\\" + escapedStr49 50    if not silent:51        token = state.push("text_special", "", 0)52        token.content = escapedStr if ch1 in _ESCAPED else origStr53        token.markup = origStr54        token.info = "escape"55 56    state.pos = pos + 157    return True58 59 60_ESCAPED = {61    "!",62    '"',63    "#",64    "$",65    "%",66    "&",67    "'",68    "(",69    ")",70    "*",71    "+",72    ",",73    "-",74    ".",75    "/",76    ":",77    ";",78    "<",79    "=",80    ">",81    "?",82    "@",83    "[",84    "\\",85    "]",86    "^",87    "_",88    "`",89    "{",90    "|",91    "}",92    "~",93}94 
codekingpro/portable-devtools · Team Ai