diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 8e9de34..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -/.idea/ -/.vscode/ \ No newline at end of file diff --git a/src/convert.py b/src/convert/__init__.py similarity index 75% rename from src/convert.py rename to src/convert/__init__.py index c24f0bd..336675c 100755 --- a/src/convert.py +++ b/src/convert/__init__.py @@ -1,32 +1,117 @@ #!/usr/bin/env python3 +"""This is a python module that will parse gemtext and convert it to html5 +""" # -*- coding: utf-8 -*- import sys -class State: - INITIAL = 0 - TEXT = 1 - LINK = 2 - PRETEXT = 3 - HEADING = 4 - UNORDERED = 5 - QUOTE = 6 - - -class Tag: - LINK = '=>' - PRE = '```' - HEADING = '#' - UNORDERED = '*' - QUOTE = '>' - - class GemParser: + """This is the main parser class + """ + def __init__(self): + """Constructor for the GemParser class + """ self.mstate = State.INITIAL self.recurse = False + def get_document_from_gemfile(self, filename): + """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 = '\n\n\n' + rdocument += 'gemtext2html\n\n\n' + with open(filename) as gemtext: + mline: str = gemtext.readline() + while mline: + rline = 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): + """A subroutine that will emit the correct end tag for the state + + Returns: + str: A html end tag + """ + tag = 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): + """A subroutine to emit the correct html start tag for the state + + Returns: + str: A html start tag + """ + tag = list() + tag.append('') + tag.append('

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