diff --git a/server.py b/server.py index cd4e6a0..003384f 100644 --- a/server.py +++ b/server.py @@ -77,55 +77,65 @@ def relay(): print("Unrecognised type: " + i.split(" ")[1]) return Response(" ".join(received.split("\n")[1:]), mimetype=i.split(" ")[1]) else: - if i[0:2] == "# ": - if title == "Something went wrong...": - title = i[2:] - temp = i[2:] - code += f"

{temp}

\n" - elif i[0:3] == "## ": - temp = i[3:] - code += f"

{temp}

\n" - elif i[0:4] == "### ": - temp = i[4:] - code += f"

{temp}

\n" - elif i[0:2] == "* ": - temp = i[2:] - code += f"\n" - elif i[0:2] == "=>": - temp = " ".join(i[2:].strip().replace(" ", " ").split(" ")) - goto = temp.split(" ")[0] - prse = urlparse(goto) - extra = "" - extracomment = goto - if prse.netloc == "" and prse.scheme == "": - isdir = url[len(url) - 1] == "/" - isabs = goto[0] == "/" or goto[0:2] == "//" - dubleslash = goto[0:2] == "//" - if isabs: - tempurl = urlparse(fulladdr).hostname + "/" + (goto[1:] if dubleslash else goto) - elif isdir: - tempurl = url + goto - else: - tempurl = "/".join(url.split("/")[:-1]) + "/" + goto - goto = f"/gem?gemini={tempurl}" - elif prse.scheme != "gemini": - extra = "" - extracomment = f"This link points to an address that isn't gemini ({prse.scheme})" + if escaped: + if i[0:3] == "```": + code += "\n" + escaped = False else: - if prse.hostname != urlparse(fulladdr).hostname: - extra = "" - extracomment = f"This link points to an address that isn't from the server you're currently connecting to ({prse.hostname})" - goto = goto.replace("gemini://", "") - goto = f"/gem?gemini={goto}" - if temp.split(" ") == 1: - comment = goto - else: - comment = " ".join(temp.split(" ")[1:]) - code += f"

{comment} {extra}

\n" - elif i[0:2] == "> ": - code += f"

{i}

\n" + code += i + "\n" else: - code += f"

{i}

\n" + if i[0:2] == "# ": + if title == "Something went wrong...": + title = i[2:] + temp = i[2:] + code += f"

{temp}

\n" + elif i[0:3] == "## ": + temp = i[3:] + code += f"

{temp}

\n" + elif i[0:3] == "```": + code += "
\n"
+                        escaped = True
+                    elif i[0:4] == "### ":
+                        temp = i[4:]
+                        code += f"

{temp}

\n" + elif i[0:2] == "* ": + temp = i[2:] + code += f"\n" + elif i[0:2] == "=>": + temp = " ".join(i[2:].strip().replace(" ", " ").split(" ")) + goto = temp.split(" ")[0] + prse = urlparse(goto) + extra = "" + extracomment = goto + if prse.netloc == "" and prse.scheme == "": + isdir = url[len(url) - 1] == "/" + isabs = goto[0] == "/" or goto[0:2] == "//" + dubleslash = goto[0:2] == "//" + if isabs: + tempurl = urlparse(fulladdr).hostname + "/" + (goto[1:] if dubleslash else goto) + elif isdir: + tempurl = url + goto + else: + tempurl = "/".join(url.split("/")[:-1]) + "/" + goto + goto = f"/gem?gemini={tempurl}" + elif prse.scheme != "gemini": + extra = "" + extracomment = f"This link points to an address that isn't gemini ({prse.scheme})" + else: + if prse.hostname != urlparse(fulladdr).hostname: + extra = "" + extracomment = f"This link points to an address that isn't from the server you're currently connecting to ({prse.hostname})" + goto = goto.replace("gemini://", "") + goto = f"/gem?gemini={goto}" + if temp.split(" ") == 1: + comment = goto + else: + comment = " ".join(temp.split(" ")[1:]) + code += f"

{comment} {extra}

\n" + elif i[0:2] == "> ": + code += f"

{i}

\n" + else: + code += f"

{i}

\n" if title == "Something went wrong...": title = "gemini://" + url except: