]> git.armaanb.net Git - lightcards.git/commitdiff
Add table number option
authorArmaan Bhojwani <me@armaanb.net>
Sun, 14 Feb 2021 03:04:21 +0000 (22:04 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 14 Feb 2021 03:04:21 +0000 (22:04 -0500)
lightcards/parse.py
lightcards/runner.py
man/lightcards.1
man/lightcards.1.md

index 95319f4628c5aecc1f683267be547f3f0fbbaf72..5d9b4024fd15f7d8491a6271fd163464279f5bc2 100644 (file)
@@ -24,7 +24,7 @@ def md2html(file):
     return outp
 
 
-def parse_html(html, lenient):
+def parse_html(html, args):
     """Use BeautifulSoup to parse the HTML"""
 
     def clean_text(inp):
@@ -33,12 +33,12 @@ def parse_html(html, lenient):
     soup = BeautifulSoup(html, "html.parser")
     outp, ths = [], []
 
-    for table in soup.find_all("table"):
+    for i, table in enumerate(soup.find_all("table")):
         ths = table.find_all("th")
         if len(ths) != 2:
-            if not lenient:
+            if not args.lenient:
                 raise Exception("lightcards: Headings malformed")
-        else:
+        elif args.table == i:
             try:
                 for x in table.find_all("tr"):
                     y = x.find_all("td")
index fdbbf9267573e0f50112454e2bb6855e37cdd6fb..b40328da14d1d6a40baec51f1a97ac04e8502e82 100644 (file)
@@ -40,6 +40,13 @@ def parse_args():
         action="store_true",
         help="don't raise exception if tables are malformed",
     )
+    parser.add_argument(
+        "-t",
+        "--table",
+        metavar="num_table",
+        type=int,
+        help="specify which table to use if multiple are given",
+    )
     parser.add_argument(
         "-a",
         "--alphabetize",
@@ -117,7 +124,7 @@ def main(args=sys.argv):
         sys.tracebacklimit = 0
 
     global headers, stack
-    (headers, stack) = parse.parse_html(parse.md2html(args.inp), args.lenient)
+    (headers, stack) = parse.parse_html(parse.md2html(args.inp), args)
 
     show(args, stack, headers, conf)
 
index 247b6b1bfae9cc77171cc8a8e6bb01e7ed5e1e6d..d12d70ba6918fbae877b6ee85983439a7aeddf0c 100644 (file)
@@ -43,6 +43,9 @@ Specify a custom config file
 .TP
 \f[B]-l\f[R], \f[B]--lenient\f[R]
 Don\[cq]t raise exception if tables are malformed
+.TP
+\f[B]-t\f[R] [int], \f[B]--table\f[R] [int]
+If multiple tables are provided in the input files, specify which
 .SH KEYS
 .TP
 \f[B]l\f[R], \f[B]right\f[R]
index 64b55db53b99beea0813857609b68cde9a44d29b..40d8783b9280171e0114422c8f04ff2b579221d3 100644 (file)
@@ -45,6 +45,9 @@ lightcards \[options\] \[input files\]
 **-l**, **\--lenient**
 : Don't raise exception if tables are malformed
 
+**-t** \[int\], **\--table** \[int\]
+: If multiple tables are provided in the input files, specify which
+
 # KEYS
 **l**, **right**
 : Next card