def _get_standard_build_folder() -> typing.Tuple[Context, Path]: ctx = Context() pandoc = Path('pandoc') pandoc.touch() src_folder = Path('./test').absolute() src_folder.mkdir() ctx.source_folder = src_folder source_file = Path('./test/index.md') source_file.touch() ctx.source_file = source_file ctx.markdown_text = '' return ctx, pandoc
def _build_folder(ctx: Context): ctx.info(f'making PDF') with TempDir(ctx): get_media_folders(ctx) get_template(ctx) get_index_file(ctx) get_settings(ctx) get_includes(ctx) ctx.template_file = Path(ctx.temp_dir, 'template.tex').absolute() title = ctx.source_folder.name ctx.title = title out_folder = elib.path.ensure_dir('.', must_exist=False, create=True) ctx.out_folder = out_folder for paper_size in ctx.settings.papersize: ctx.paper_size = paper_size _set_max_image_width(ctx) if paper_size.lower() == 'a4' or len(ctx.settings.papersize) == 1: ctx.out_file = Path(out_folder, f'{title}.PDF').absolute() else: ctx.out_file = Path(out_folder, f'{title}_{paper_size}.PDF').absolute() _download_existing_file(ctx) if skip_file(ctx): continue process_markdown(ctx) check_for_unused_images(ctx) process_latex(ctx) ctx.source_file = Path(ctx.temp_dir, 'source.md').absolute() ctx.source_file.write_text(ctx.markdown_text, encoding='utf8') ctx.info(f'building format: {paper_size}') ctx.debug(f'context:\n{elib.pretty_format(ctx.__repr__())}') # noinspection SpellCheckingInspection pandoc_cmd = [ '-s', '--toc', f'--template "{ctx.template_file}"', f'--listings "{ctx.source_file}"', f'-o "{ctx.out_file}"', '-V geometry:margin=1.5cm', '-V test', '-V geometry:headheight=17pt', '-V geometry:includehead', '-V geometry:includefoot', '-V geometry:heightrounded', '-V lot', '-V lof', '--pdf-engine=xelatex', f'-V papersize:{ctx.paper_size}', '-N', ] PANDOC(' '.join(pandoc_cmd)) add_metadata_to_pdf(ctx)