This will concatenate the contents
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.
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 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")
- 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)
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",
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)
lightcards - terminal flashcards from Markdown
.SH SYNOPSIS
.PP
lightcards - terminal flashcards from Markdown
.SH SYNOPSIS
.PP
-lightcards [options] [input file]
+lightcards [options] [input files]
-\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
lightcards - terminal flashcards from Markdown
# SYNOPSIS
lightcards - terminal flashcards from Markdown
# SYNOPSIS
-lightcards \[options\] \[input file\]
+lightcards \[options\] \[input files\]
-**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