1 # Parse markdown table into tuple of lists
5 from bs4 import BeautifulSoup
12 """Use the markdown module to convert input to HTML"""
16 outp += markdown.markdown(
17 open(i, "r").read(), extensions=["tables"]
19 except FileNotFoundError:
21 f'lightcards: "{i}": No such file or directory'
27 def parse_html(html, lenient):
28 """Use BeautifulSoup to parse the HTML"""
31 return inp.get_text().rstrip()
33 soup = BeautifulSoup(html, "html.parser")
36 for table in soup.find_all("table"):
37 ths = table.find_all("th")
40 raise Exception("lightcards: Headings malformed")
43 for x in table.find_all("tr"):
46 outp.append(Card(tuple([clean_text(z) for z in y])))
47 except AttributeError:
48 raise Exception("lightcards: No table found") from None
50 # Return a tuple of nested lists
51 return ([clean_text(x) for x in ths], outp)