codekingpro/portable-devtools
114k
1"""Normalize input string."""2 3import re4 5from .state_core import StateCore6 7# https://spec.commonmark.org/0.29/#line-ending8NEWLINES_RE = re.compile(r"\r\n?|\n")9NULL_RE = re.compile(r"\0")10 11 12def normalize(state: StateCore) -> None:13 # Normalize newlines14 string = NEWLINES_RE.sub("\n", state.src)15 16 # Replace NULL characters17 string = NULL_RE.sub("\ufffd", string)18 19 state.src = string20 