The code below did what I needed.
with open("finalfile.txt", 'w', encoding='utf-8') as File2, open("test.txt", "r", encoding='utf-8') as File1:
previous_line = ""
new_line = ""
double_dash_prev_line = False
single_dash_prev_line = False
for line in File1:
current_line = line
if line[0] == "-":
if line[1] != "-":
if single_dash_prev_line == False and double_dash_prev_line == False:
new_line = "<ul><li> " + current_line[1:]
File2.write(new_line)
single_dash_prev_line = True
double_dash_prev_line = False
elif single_dash_prev_line == True:
new_line = "</li><li> " + current_line[1:]
File2.write(new_line)
single_dash_prev_line = True
double_dash_prev_line = False
elif double_dash_prev_line == True:
new_line = "</ul></li></ul><ul><li> " + current_line[1:]
File2.write(new_line)
single_dash_prev_line = True
double_dash_prev_line = False
elif line[1] == "-":
if single_dash_prev_line == True:
new_line = "<ul><li> " + line[2:]
File2.write(new_line)
double_dash_prev_line = True
single_dash_prev_line = False
elif double_dash_prev_line_line == True:
new_line = "</li><li> " + line[2:]
File2.write(new_line)
double_dash_prev_line = True
single_dash_prev_line = False
elif single_dash_prev_line == True:
new_line = "</li></ul> " + current_line[1:]
File2.write(new_line)
single_dash_prev_line = False
double_dash_prev_line = False
elif double_dash_prev_line_line == True:
new_line = "</li></ul></ul> " + current_line[1:]
File2.write(new_line)
double_dash_prev_line = False
single_dash_prev_line = False
else:
single_dash_prev_line = False
double_dash_prev_line = False
File2.write(current_line)
solved Add HTML tags to text using Python