I've run into a big issue in my code.
TL;DR: After a few comments, I decided to post the entire code here:
https://repl.it/repls/AustereShinyBetatest
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"#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):
1. Here goes some text. {tag} A wonderful day. It's soon cristmas.
2. Happy 2019, soon. {Some useful tag!} Something else goes here.
3. Happy ending. Yeppe! See you.
4.
5 Happy KKK!
6. Happy B-Day!
7
8. Universe is cool!
9.
10. {Tagish}.
11.
12. {Slugish}. Here goes another line. {Slugish} since this is a new sentence.
13.
14. 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!
highlight_nonmodified
andhighligh_merge
are used, or in what order; I would clarify your question to include a small driver, showing exactly how you take in some sample input, process it, and spit it out. It would also help to clarify that Modified.txt is the "wrong output", and End result is the "desired output".