Use parser argument instead of hard-coded values.
This commit is contained in:
parent
40e78176fb
commit
17c72ba06e
2 changed files with 10 additions and 8 deletions
|
@ -8,8 +8,8 @@
|
||||||
- [tqr.py](./prog/tqr.py): Program to generate a QRCode from
|
- [tqr.py](./prog/tqr.py): Program to generate a QRCode from
|
||||||
clipboard.
|
clipboard.
|
||||||
|
|
||||||
- [mdsplit.py](./prog/mdsplit.py): Program to convert an org-mode file
|
- [mdsplit.py](./prog/mdsplit.py): Program to convert a single
|
||||||
to multiple markdown files used by
|
markdown file to to multiple markdown files used by
|
||||||
[mdbook](https://rust-lang.github.io/mdBook/) program.
|
[mdbook](https://rust-lang.github.io/mdBook/) program.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,23 @@ from pathlib import Path
|
||||||
|
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Convert an org file to mdbook")
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Convert an single markdown file to mdbook"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument("orgfile", help="The org file", type=Path)
|
parser.add_argument("mdfile", help="The org file", type=Path)
|
||||||
parser.add_argument("mdbook", help="mdbook root diretory", type=Path)
|
parser.add_argument("mdbook", help="mdbook root diretory", type=Path)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.orgfile.is_file():
|
if not args.mdfile.is_file():
|
||||||
raise ValueError("`orgfile` must be an existing org-mode file")
|
raise ValueError("`mdfile` must be an existing markdown file")
|
||||||
|
|
||||||
if not args.mdbook.is_dir():
|
if not args.mdbook.is_dir():
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"`mdbook` must be a root mdbook directory initialiezd with `mdbook init`"
|
"`mdbook` must be a root mdbook directory initialiezd with `mdbook init`"
|
||||||
)
|
)
|
||||||
|
|
||||||
with open("cours.md") as f:
|
with open(args.mdfile) as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
|
||||||
data = data.split("```")
|
data = data.split("```")
|
||||||
|
@ -37,7 +39,7 @@ for i, d in enumerate(data[:]):
|
||||||
|
|
||||||
data = "".join(data).splitlines(keepends=True)
|
data = "".join(data).splitlines(keepends=True)
|
||||||
|
|
||||||
output = Path("book") / "src"
|
output = Path(parser.mdbook) / "src"
|
||||||
|
|
||||||
splitn = [idx for (idx, d) in enumerate(data) if d.startswith("# ")]
|
splitn = [idx for (idx, d) in enumerate(data) if d.startswith("# ")]
|
||||||
splitn = list(zip(splitn[:], splitn[1:] + [None]))
|
splitn = list(zip(splitn[:], splitn[1:] + [None]))
|
||||||
|
|
Loading…
Reference in a new issue