I've run into a big issue in my code.
Here's my code:
def highlight_nonmodified(content: str) -> str:
regex = re.compile(r'(?s)(\{.*?[^\}]+\})', re.I | re.S)
replace = r'#\1'
content = regex.sub(replace, content)
return content
def get_line(string_t: str, original: str) -> int:
original = original.splitlines(True)
for (i, line) in enumerate(original, 1):
if string_t[1:] in line:
return i
return -1
def highligh_merge(original: str, modified: str) -> str:
for line in modified.splitlines(True):
if line.startswith('#'):
numer = get_line(line, original)
error = r"#Error: Tag not supported at line{0}\n".format(numer)
error = error + line
modified = modified.replace(line, error)
My issue is that here's what happens:
Textfile.txt (original):
Here goes some text. {tag} A wonderful day. It's soon cristmas.
Happy 2019, soon. {Some useful tag!} Something else goes here.
Happy ending. Yeppe! See you.
Happy KKK!
Happy B-Day!
Universe is cool!
{Tagish}.
{Slugish}. Here goes another line. {Slugish} since this is a new sentence.
endline.
Modified.txt:
Here goes some text. A wonderful day. It's soon cristmas.
Happy 2019, soon. #{Some useful tag!} Something else goes here.
Happy ending. Yeppe! See you.
Happy KKK!
Happy B-Day!
Universe is cool!
.
#Error: Tag not supported at line-1\n#{Slugish}. Here goes another line. #{Slugish} since this is a new sentence.
endline.
I cannot seem to get precise line numbering and comparing of lines, what am I doing wrong here, I am obviously, storing two copies, original and modified and then I pick then I try to pick out the line number from the original text by looping over line by line. But still without any success, is this even possible. Thanks a lot in advance!
from How to get accurate highlighting of modified lines in textfile
No comments:
Post a Comment