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:
16 print(f'lightcards: "{file}": No such file or directory')
21 """Use BeautifulSoup to parse the HTML"""
24 return inp.get_text().rstrip()
26 soup = BeautifulSoup(html, "html.parser")
29 for x in soup.find_all("tr"):
30 outp.append(Card([clean_text(y) for y in x.find_all("td")[:2]]))
32 # Return a tuple of nested lists
33 return ([clean_text(x) for x in soup.find_all("th")][:2], outp[1:])
37 return parse_html(md2html(file))
40 if __name__ == "__main__":
41 print(main(sys.argv[1]))