#!/usr/bin/env python3 """This is a python module that will parse gemtext and convert it to html5 """ # -*- coding: utf-8 -*- import sys # Type aliases State = int Tag = str class GemParser: """This is the main parser class """ def __init__(self): """Constructor for the GemParser class """ self.mstate: State = StateEnum.INITIAL self.recurse: bool = False def get_document_from_gemfile(self, filename: str) -> str: """This subroutine will read a file line by line and convert it to html Args: filename (str): A file name corresponing to a file of gemtext Returns: str: A valid html5 document as string """ rdocument: str = '\n\n\n' rdocument += 'gemtext2html\n\n\n' with open(filename) as gemtext: mline: str = gemtext.readline() while mline: rline: str = self.parse_line(mline) if rline is not None and rline != str() and rline != '\n': rdocument += rline mline = gemtext.readline() rdocument += '{}\n\n'.format(self.get_end_tag()) return rdocument def get_end_tag(self) -> str: """A subroutine that will emit the correct end tag for the state Returns: str: A html end tag """ tag: list[str] = list() tag.append('') tag.append('

\n') tag.append('\n') tag.append('\n') tag.append('\n') tag.append('\n') tag.append('\n') return tag[self.mstate] def get_start_tag(self) -> str: """A subroutine to emit the correct html start tag for the state Returns: str: A html start tag """ tag: list[str] = list() tag.append('') tag.append('

\n') tag.append('') tag.append('\n') tag.append('') tag.append('