Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryneeverett committed Aug 4, 2020
1 parent 0042efb commit 7faa45d
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions mkcodes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from pathlib import Path
import re
import glob
import warnings

import click
Expand Down Expand Up @@ -69,18 +68,16 @@ def extendMarkdown(self, md, md_globals):


def get_files(inputs):
""" Take in an iterable of paths, yield the files and parent dirs in those paths"""
""" Yield the files and parent dirs from an iterable of paths. """
markdown_extensions = ['.markdown', '.mdown', '.mkdn', '.mkd', '.md']
for i in inputs:
path = Path(i)
if path.is_dir():
""" let's iterate the directory and yield files """
for child in path.rglob('*'):
if child.is_file() and child.suffix in markdown_extensions:
yield child, path
else:
if path.suffix in markdown_extensions:
yield path, path.parent
elif path.suffix in markdown_extensions:
yield path, path.parent


def makedirs(directory):
Expand Down Expand Up @@ -111,22 +108,16 @@ def makedirs(directory):
help='Allow code blocks without language hints.')
def main(inputs, output, github, safe):
collect_codeblocks = github_codeblocks if github else markdown_codeblocks
# to output deep trees with a file pattern
# we should break out the directory and the filename pattern
outputbasedir = Path(output).parent
outputbasename = Path(output).name

for filepath, input_path in get_files(inputs):
codeblocks = collect_codeblocks(filepath, safe)

if codeblocks:
#we want the path to the file, and the file without an extension
fp = Path(filepath)
filedir =fp.parent.relative_to(input_path)
filedir = fp.parent.relative_to(input_path)
filename = fp.stem

# stitch together the OUTPUT base directory, with the input directories
# add the file format at the end.
outputfilename = outputbasedir / filedir / outputbasename.format(name=filename)

outputdir = os.path.dirname(outputfilename)
Expand Down

0 comments on commit 7faa45d

Please sign in to comment.