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'
28 """Use BeautifulSoup to parse the HTML"""
31 return inp.get_text().rstrip()
33 soup = BeautifulSoup(html, "html.parser").find_all("table")
38 for x in table.find_all("tr"):
41 outp.append(Card(tuple([clean_text(z) for z in y])))
42 except AttributeError:
43 raise Exception("lightcards: No table found") from None
45 ths = table.find_all("th")
47 raise Exception("lightcards: Headings malformed")
49 # Return a tuple of nested lists
50 return ([clean_text(x) for x in ths], outp)
54 return parse_html(md2html(file))
57 if __name__ == "__main__":
58 print(main(sys.argv[1]))