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 sys.exit(f'lightcards: "{file}": No such file or directory')
20 """Use BeautifulSoup to parse the HTML"""
23 return inp.get_text().rstrip()
25 soup = BeautifulSoup(html, "html.parser").find("table")
29 for x in soup.find_all("tr"):
30 outp.append(Card(tuple([clean_text(y) for y in x.find_all("td")])))
31 except AttributeError:
32 sys.exit("lightcards: No table found")
34 ths = soup.find_all("th")
36 sys.exit("lightcards: Headings malformed")
38 # Return a tuple of nested lists
39 return ([clean_text(x) for x in ths], outp[1:])
43 return parse_html(md2html(file))
46 if __name__ == "__main__":
47 print(main(sys.argv[1]))