diff --git a/Pipfile b/Pipfile index 10321ae2f..ee865a75c 100644 --- a/Pipfile +++ b/Pipfile @@ -42,6 +42,7 @@ jupyterlab = "*" jupyterlab-vim = "*" keras_applications = "*" lru-dict = "*" +markdown-it-py = "*" matplotlib = "*" mock = "*" mpld3 = "*" diff --git a/Pipfile.lock b/Pipfile.lock index d66e93935..fba21abb9 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7d947b4ec704dbcb974423ac826df3222d956ffd608b989a3ab607e8d25df484" + "sha256": "bda9b34e8525624fd39ac3a78476942df82d79dd1e06555cbd1e38a6c8574976" }, "pipfile-spec": 6, "requires": { @@ -2287,7 +2287,7 @@ "sha256:36be6bb3ad987bfdb839f5ba78ddf094552ca38ccbd784ae4f74a4e1419fc6e3", "sha256:98080fc0bc34c4f2bcf0846a096a9429acbd9d5d8e67ed34026c03c61c464389" ], - "markers": "python_version ~= '3.6'", + "index": "pypi", "version": "==1.1.0" }, "markupsafe": { diff --git a/common/markdown.py b/common/markdown.py new file mode 100755 index 000000000..30c5bc2c0 --- /dev/null +++ b/common/markdown.py @@ -0,0 +1,48 @@ +from typing import List + +HTML_REPLACEMENTS = [ + (r'&', r'&'), + (r'"', r'"'), +] + + +def parse_markdown(text: str, tab_length: int = 2) -> str: + lines = text.split("\n") + output: List[str] = [] + list_level = 0 + + def end_outstanding_lists(level: int, end_level: int) -> int: + while level > end_level: + level -= 1 + output.append("") + if level > 0: + output.append("") + return end_level + + for i, line in enumerate(lines): + if i + 1 < len(lines) and lines[i + 1].startswith("==="): # heading + output.append(f"

{line}

") + elif line.startswith("==="): + pass + elif line.lstrip().startswith("* "): # list + line_level = 1 + line.count(" " * tab_length, 0, line.index("*")) + if list_level >= line_level: + list_level = end_outstanding_lists(list_level, line_level) + else: + list_level += 1 + if list_level > 1: + output[-1] = output[-1].replace("", "") + output.append("