remove custom markdown rendering (#24538)

* remove custom markdown rendering

* remove from release
old-commit-hash: 222c7cd60d
taco
Adeeb Shihadeh 3 years ago committed by GitHub
parent 29a516bed8
commit d33afc2cac
  1. 48
      common/markdown.py
  2. 26
      common/tests/test_markdown.py
  3. 1
      release/files_common
  4. 4
      selfdrive/updated.py

@ -1,48 +0,0 @@
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("</ul>")
if level > 0:
output.append("</li>")
return end_level
for i, line in enumerate(lines):
if i + 1 < len(lines) and lines[i + 1].startswith("==="): # heading
output.append(f"<h1>{line}</h1>")
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("</li>", "")
output.append("<ul>")
output.append(f"<li>{line.replace('*', '', 1).lstrip()}</li>")
else:
list_level = end_outstanding_lists(list_level, 0)
if len(line) > 0:
output.append(line)
end_outstanding_lists(list_level, 0)
output_str = "\n".join(output) + "\n"
for (fr, to) in HTML_REPLACEMENTS:
output_str = output_str.replace(fr, to)
return output_str

@ -1,26 +0,0 @@
#!/usr/bin/env python3
from markdown_it import MarkdownIt
import os
import unittest
from common.basedir import BASEDIR
from common.markdown import parse_markdown
class TestMarkdown(unittest.TestCase):
# validate that our simple markdown parser produces the same output as `markdown_it` from pip
def test_current_release_notes(self):
self.maxDiff = None
with open(os.path.join(BASEDIR, "RELEASES.md")) as f:
for r in f.read().split("\n\n"):
# No hyperlink support is ok
if '[' in r:
continue
self.assertEqual(MarkdownIt().render(r), parse_markdown(r))
if __name__ == "__main__":
unittest.main()

@ -26,7 +26,6 @@ common/ffi_wrapper.py
common/file_helpers.py common/file_helpers.py
common/logging_extra.py common/logging_extra.py
common/numpy_fast.py common/numpy_fast.py
common/markdown.py
common/params.py common/params.py
common/params_pyx.pyx common/params_pyx.pyx
common/xattr.py common/xattr.py

@ -33,9 +33,9 @@ import time
import threading import threading
from pathlib import Path from pathlib import Path
from typing import List, Tuple, Optional from typing import List, Tuple, Optional
from markdown_it import MarkdownIt
from common.basedir import BASEDIR from common.basedir import BASEDIR
from common.markdown import parse_markdown
from common.params import Params from common.params import Params
from selfdrive.hardware import TICI, HARDWARE from selfdrive.hardware import TICI, HARDWARE
from selfdrive.swaglog import cloudlog from selfdrive.swaglog import cloudlog
@ -126,7 +126,7 @@ def set_params(new_version: bool, failed_count: int, exception: Optional[str]) -
with open(os.path.join(FINALIZED, "RELEASES.md"), "rb") as f: with open(os.path.join(FINALIZED, "RELEASES.md"), "rb") as f:
r = f.read().split(b'\n\n', 1)[0] # Slice latest release notes r = f.read().split(b'\n\n', 1)[0] # Slice latest release notes
try: try:
params.put("ReleaseNotes", parse_markdown(r.decode("utf-8"))) params.put("ReleaseNotes", MarkdownIt().render(r.decode("utf-8")))
except Exception: except Exception:
params.put("ReleaseNotes", r + b"\n") params.put("ReleaseNotes", r + b"\n")
except Exception: except Exception:

Loading…
Cancel
Save