Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
newline.py45 linesDownload Raw Back to rules_inline
1"""Proceess '\n'."""2 3from ..common.utils import charStrAt, isStrSpace4from .state_inline import StateInline5 6 7def newline(state: StateInline, silent: bool) -> bool:8    pos = state.pos9 10    if state.src[pos] != "\n":11        return False12 13    pmax = len(state.pending) - 114    maximum = state.posMax15 16    # '  \n' -> hardbreak17    # Lookup in pending chars is bad practice! Don't copy to other rules!18    # Pending string is stored in concat mode, indexed lookups will cause19    # conversion to flat mode.20    if not silent:21        if pmax >= 0 and charStrAt(state.pending, pmax) == " ":22            if pmax >= 1 and charStrAt(state.pending, pmax - 1) == " ":23                # Find whitespaces tail of pending chars.24                ws = pmax - 125                while ws >= 1 and charStrAt(state.pending, ws - 1) == " ":26                    ws -= 127                state.pending = state.pending[:ws]28 29                state.push("hardbreak", "br", 0)30            else:31                state.pending = state.pending[:-1]32                state.push("softbreak", "br", 0)33 34        else:35            state.push("softbreak", "br", 0)36 37    pos += 138 39    # skip heading spaces for next line40    while pos < maximum and isStrSpace(state.src[pos]):41        pos += 142 43    state.pos = pos44    return True45 
codekingpro/portable-devtools · Team Ai