def slides(): parser = argparse.ArgumentParser( description='Generate slides from markdown files.') parser.add_argument('filename', nargs='+', help='the source markdown files') parser.add_argument('--tab', default=None, help='the tab') args = parser.parse_args(sys.argv[2:]) tab = args.tab cf = config.Config() sd = Slides(cf) for fn in args.filename: fns = glob.glob(fn) if not len(fns): logging.warning('Not found ' + fn) return for md in fns: with open(md, 'r') as f: nb = notebook.read_markdown(f.read()) if tab: nb = notebook.split_markdown_cell(nb) nb = notebook.get_tab_notebook(nb, tab, cf.default_tab) output_fn = str(pathlib.Path(md).with_suffix('')) + ( '_' + tab if tab else '_') + '_slides.ipynb' sd.generate(nb, output_fn)
def translate(): parser = argparse.ArgumentParser( description='Translate to another language') # Example usage: d2lbook translate --commit 35a64ab chapter_optimization chapter_computer-vision/anchor.md parser.add_argument( 'source', nargs='+', help='chapter directories or markdown files to activate') parser.add_argument('--commit', default='latest', help='the commit of the base repo') args = parser.parse_args(sys.argv[2:]) cf = config.Config() trans = Translate(cf, args.commit) for source in args.source: # Check if source is a file or a chapter dir if not source.endswith(".md"): chap_dir = os.path.join(trans.repo_dir, source) if os.path.isdir(chap_dir): logging.info(f'Translating all sections of {source}') all_chap_secs = os.listdir(chap_dir) for sec_name in all_chap_secs: if sec_name.endswith(".md"): trans.translate(os.path.join(source, sec_name)) else: logging.error(f'Invalid directory {source}: Please provide' 'a valid chapter name for translation') else: trans.translate(source)
def activate(): parser = argparse.ArgumentParser(description='Activate tabs') parser.add_argument('tab', default='all', help='the tab to activate') parser.add_argument('filename', nargs='+', help='the markdown files to activate') args = parser.parse_args(sys.argv[2:]) cf = config.Config() for fn in args.filename: for f in glob.glob(fn): _activate_tab(f, args.tab, cf.default_tab)
def translate(): parser = argparse.ArgumentParser( description='Translate to another language') parser.add_argument('filename', nargs='+', help='the markdown files to activate') parser.add_argument('--commit', default='latest', help='the commit of the base repo') args = parser.parse_args(sys.argv[2:]) cf = config.Config() trans = Translate(cf, args.commit) for fn in args.filename: trans.translate(fn)