1 # Parse markdown table into tuple of lists
5 from bs4 import BeautifulSoup
12 """Use the markdown module to convert input to HTML"""
14 return markdown.markdown(open(file, "r").read(), extensions=["tables"])
15 except FileNotFoundError:
17 f'lightcards: "{file}": No such file or directory'
22 """Use BeautifulSoup to parse the HTML"""
25 return inp.get_text().rstrip()
27 soup = BeautifulSoup(html, "html.parser").find("table")
31 for x in soup.find_all("tr"):
32 outp.append(Card(tuple([clean_text(y) for y in x.find_all("td")])))
33 except AttributeError:
34 raise Exception("lightcards: No table found") from None
36 ths = soup.find_all("th")
38 raise Exception("lightcards: Headings malformed")
40 # Return a tuple of nested lists
41 return ([clean_text(x) for x in ths], outp[1:])
45 return parse_html(md2html(file))
48 if __name__ == "__main__":
49 print(main(sys.argv[1]))