2 # Parse markdown table into tuple of lists
6 from bs4 import BeautifulSoup
13 """Use the markdown module to convert input to HTML"""
15 with open(file, "r", encoding="utf-8") as input_file:
16 return markdown.markdown(input_file.read(), extensions=['tables'])
17 except FileNotFoundError:
18 print(f"lightcards: \"{file}\": No such file or directory")
23 """Use BeautifulSoup to parse the HTML"""
25 return inp.get_text().rstrip()
27 soup = BeautifulSoup(html, 'html.parser')
30 for x in soup.find_all("tr"):
31 outp.append(Card([clean_text(y) for y in x.find_all("td")[:2]]))
33 # Return a tuple of nested lists
34 return ([clean_text(x) for x in soup.find_all("th")][:2], outp[1:])
38 return parse_html(md2html(file))
41 if __name__ == "__main__":
42 print(main(sys.argv[1]))