import sys import re for filename in sys.argv[1:]: with open(filename, 'r') as infile: content = infile.readlines() to_use = content.pop(0).replace('|',', ') html_header = 'volabula: ' + ''.join(to_use) + '
' # Replace _string_ with html html_span_head = '' html_input_head = '' html_span_tail = '' for i in range(len(content)): content[i] = re.sub(r'(\s|\"|)([a-zA-Z\-\ÿ]+|)_([āēīōūa-zA-Z\-]+)_(\.|\,|)', r'\1' + html_span_head + r'\2' + html_input_head + r'\3' + html_input_tail + r'\4' + html_span_tail, content[i].rstrip('\n')) # Replace vowel-dash-vowel with vowels with macrons content[i] = content[i].replace('A-A', 'Ā') content[i] = content[i].replace('a-a', 'ā') content[i] = content[i].replace('E-E', 'Ē') content[i] = content[i].replace('e-e', 'ē') content[i] = content[i].replace('I-I', 'Ī') content[i] = content[i].replace('i-i', 'ī') content[i] = content[i].replace('O-O', 'Ō') content[i] = content[i].replace('o-o', 'ō') content[i] = content[i].replace('U-U', 'Ū') content[i] = content[i].replace('u-u', 'ū') html_list_header = '
    \n' html_list_element_header = '
  1. ' html_list_element_trailer = '
  2. \n' html_list_trailer = '
' with open(filename + '.html', 'w') as outfile: outfile.write(html_header) outfile.write(html_list_header) for line in content: outfile.write(html_list_element_header + line.rstrip('\n') + html_list_element_trailer) outfile.write(html_list_trailer)