]> git.armaanb.net Git - lightcards.git/commitdiff
Allow for multiple input files to be given
authorArmaan Bhojwani <me@armaanb.net>
Sun, 14 Feb 2021 00:57:06 +0000 (19:57 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 14 Feb 2021 02:26:10 +0000 (21:26 -0500)
This will concatenate the contents

README.md
lightcards/parse.py
lightcards/runner.py
man/lightcards.1
man/lightcards.1.md

index d51ee1218369c29384bc1ae3d157d82f17545b2c..4c061d00390a704518f6f811ad9ca4d82474b895 100644 (file)
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ pip install git+https://git.sr.ht/~armaan/lightcards@devel
 See `lightcards --help` or `man lightcards` for usage information.
 
 ## Input file
 See `lightcards --help` or `man lightcards` for usage information.
 
 ## Input file
-`contrib/example.md` is an example input file. Lightcards takes the first table from a valid Markdown or HTML file. Each row is a card, and the two columns are the front and back.
+`contrib/example.md` is an example input file. Lightcards takes all of the tables from a valid Markdown or HTML file. Each row is a card, and the two columns are the front and back.
 
 ## Configuration
 Copy the config file at `/etc/lightcards/config.py` to `~/.config/lightcards/config.py` or `~/${XDG_CONFIG_HOME}/lightcards/config.py` and edit.
 
 ## Configuration
 Copy the config file at `/etc/lightcards/config.py` to `~/.config/lightcards/config.py` or `~/${XDG_CONFIG_HOME}/lightcards/config.py` and edit.
index 3a1306bfae98840ba312fc58deff160d667ceeb8..8e0d320f6202f5e0bde347b540bcca36d02cc93e 100644 (file)
@@ -10,12 +10,18 @@ from .deck import Card
 
 def md2html(file):
     """Use the markdown module to convert input to HTML"""
 
 def md2html(file):
     """Use the markdown module to convert input to HTML"""
-    try:
-        return markdown.markdown(open(file, "r").read(), extensions=["tables"])
-    except FileNotFoundError:
-        raise Exception(
-            f'lightcards: "{file}": No such file or directory'
-        ) from None
+    outp = ""
+    for i in file:
+        try:
+            outp += markdown.markdown(
+                open(i, "r").read(), extensions=["tables"]
+            )
+        except FileNotFoundError:
+            raise Exception(
+                f'lightcards: "{i}": No such file or directory'
+            ) from None
+
+    return outp
 
 
 def parse_html(html):
 
 
 def parse_html(html):
@@ -24,21 +30,24 @@ def parse_html(html):
     def clean_text(inp):
         return inp.get_text().rstrip()
 
     def clean_text(inp):
         return inp.get_text().rstrip()
 
-    soup = BeautifulSoup(html, "html.parser").find("table")
+    soup = BeautifulSoup(html, "html.parser").find_all("table")
     outp = []
 
     outp = []
 
-    try:
-        for x in soup.find_all("tr"):
-            outp.append(Card(tuple([clean_text(y) for y in x.find_all("td")])))
-    except AttributeError:
-        raise Exception("lightcards: No table found") from None
+    for table in soup:
+        try:
+            for x in table.find_all("tr"):
+                y = x.find_all("td")
+                if y:
+                    outp.append(Card(tuple([clean_text(z) for z in y])))
+        except AttributeError:
+            raise Exception("lightcards: No table found") from None
 
 
-    ths = soup.find_all("th")
-    if len(ths) != 2:
-        raise Exception("lightcards: Headings malformed")
+        ths = table.find_all("th")
+        if len(ths) != 2:
+            raise Exception("lightcards: Headings malformed")
 
     # Return a tuple of nested lists
 
     # Return a tuple of nested lists
-    return ([clean_text(x) for x in ths], outp[1:])
+    return ([clean_text(x) for x in ths], outp)
 
 
 def main(file):
 
 
 def main(file):
index 8ca91f1157438542172ec03f1e9c66643df2c174..2154c95766aed8cd216863fb9500f166a23fda71 100644 (file)
@@ -33,7 +33,7 @@ def parse_args():
         choices=range(1, 4),
         help="specify which view to start in",
     )
         choices=range(1, 4),
         help="specify which view to start in",
     )
-    parser.add_argument("inp", metavar="input_file", type=str, nargs=1)
+    parser.add_argument("inp", metavar="input_files", type=str, nargs="+")
     parser.add_argument(
         "-a",
         "--alphabetize",
     parser.add_argument(
         "-a",
         "--alphabetize",
@@ -111,7 +111,7 @@ def main(args=sys.argv):
         sys.tracebacklimit = 0
 
     global headers, stack
         sys.tracebacklimit = 0
 
     global headers, stack
-    (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
+    (headers, stack) = parse.parse_html(parse.md2html(args.inp))
 
     show(args, stack, headers, conf)
 
 
     show(args, stack, headers, conf)
 
index 526d82cbbb96fe961d18cf41094d644f90fe1fec..a2e421e6694e51361dd0f9f2595143df18e3e813 100644 (file)
@@ -7,12 +7,12 @@
 lightcards - terminal flashcards from Markdown
 .SH SYNOPSIS
 .PP
 lightcards - terminal flashcards from Markdown
 .SH SYNOPSIS
 .PP
-lightcards [options] [input file]
+lightcards [options] [input files]
 .SH DESCRIPTION
 .PP
 .SH DESCRIPTION
 .PP
-\f[B]lightcards\f[R] is a Python program that reads data from a two
-column Markdown (and by extension, HTML) table in the \f[B]input
-file\f[R], and displays flashcards from their contents.
+\f[B]lightcards\f[R] is a Python program that reads data from two column
+Markdown (and by extension, HTML) tables from the \f[B]input files\f[R],
+and displays flashcards from their contents.
 .SH OPTIONS
 .SS Generic Program Information
 .TP
 .SH OPTIONS
 .SS Generic Program Information
 .TP
index 24e3cd0129b179d63ac6da26f805333eb8b60cee..568aa5eebaa9e76a926b63f1ed0e3b48e68a5eb2 100644 (file)
@@ -10,10 +10,10 @@ date: February 2021
 lightcards - terminal flashcards from Markdown
 
 # SYNOPSIS
 lightcards - terminal flashcards from Markdown
 
 # SYNOPSIS
-lightcards \[options\] \[input file\]
+lightcards \[options\] \[input files\]
 
 # DESCRIPTION
 
 # DESCRIPTION
-**lightcards** is a Python program that reads data from a two column Markdown (and by extension, HTML) table in the **input file**, and displays flashcards from their contents.
+**lightcards** is a Python program that reads data from two column Markdown (and by extension, HTML) tables from the **input files**, and displays flashcards from their contents.
 
 # OPTIONS
 ## Generic Program Information
 
 # OPTIONS
 ## Generic Program Information