X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=lightcards%2Fparse.py;h=65cad627d4cd25e38dce77973fb9b25ae958a6dd;hb=852be3a599b3686e20b2f3bfe10291380fcc5ff7;hp=6f3c25f6baf0d40b75fbdcfcf6ecbe4e850fae98;hpb=fa534964b6dd5eb9311d235a6b3ec51174e750a4;p=lightcards.git diff --git a/lightcards/parse.py b/lightcards/parse.py index 6f3c25f..65cad62 100755 --- a/lightcards/parse.py +++ b/lightcards/parse.py @@ -10,11 +10,13 @@ from .deck import Card def md2html(file): + """Use the markdown module to convert input to HTML""" with open(file, "r", encoding="utf-8") as input_file: return markdown.markdown(input_file.read(), extensions=['tables']) def parse_html(html): + """Use BeautifulSoup to parse the HTML""" def clean_text(inp): return inp.get_text().rstrip() @@ -30,6 +32,7 @@ def parse_html(html): for x in soup.find_all("tr"): outp.append(Card([clean_text(y) for y in x.find_all("td")])) + # Return a tuple of nested lists return ([clean_text(x) for x in soup.find_all("th")], clean_list(outp))