#!/usr/bin/python3
# Copyright 2023 Ted Clark
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License, version 2, as published by the Free
# Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
from sys import argv, exit, stderr
def assert_head():
if not document_head:
stderr.write('Missing document head\n')
exit(1)
def close_tags():
if state == 'QUOTE' or state == 'QUOTE2':
print('')
elif state == 'TD' or state == 'TD2':
print('')
elif state == 'TH' or state == 'TH2':
print('')
elif state == 'ULIST' or state == 'ULIST2':
print('')
def decode_string(string):
decoded_str = ''
skip = 0
for ii in range(0, len(string)):
if skip:
# Skip over HTML codes and tags
skip -= 1
continue
if string[ii] == '&':
# Replace '&' with &, but don't change HTML codes such as
# to .
codes = ('-', '✓', '&', 'ε', '>', '<',
'—', ' ', '–')
found = False
for code in codes:
if string[ii:ii + len(code)] == code:
decoded_str += code
skip = len(code) - 1
found = True
break
if found:
continue
decoded_str += '&'
elif string[ii] == '<':
# Replace '<' with <, but don't change HTML tags such as
# to <br>.
tags = ('
',
'', '
',
'', '',
'', '',
'', '',
'', '',
'
', '
', '', '', '', '', '', '', '', '', ) found = False for tag in tags: if string[ii:ii + len(tag)] == tag: decoded_str += tag skip = len(tag) - 1 found = True break if found: continue decoded_str += '<' elif string[ii] == '>': decoded_str += '>' else: decoded_str += string[ii] return decoded_str def get_state(line): global document_head, in_css, in_table, paragraph_num, state if line == '---': close_tags() state = 'NO_OP' return True elif line == '---body': if in_css: print('') in_css = False if not document_head: print('\n') document_head = True state = 'NO_OP' return True elif line == '---br': assert_head() # ---br does not close tags or change state, so table rows and tables # have to be explicitly closed. if in_table: print('\n') in_table = False state = 'NO_OP' print('