Exemplo n.º 1
0
def iterate_image_strings(images, latex):
    for image in images:
        raw_image_url = image[2]
        logger.info('raw image url: {}'.format(raw_image_url))

        image_source_path = extract_image_path(raw_image_url)

        image_target_path = file_path('/assets/{}{}'.format(
            file_name(image_source_path), file_extension(image_source_path)))

        logger.info('image source path: {}'.format(image_source_path))
        logger.info('image target path: {}'.format(image_target_path))

        resource = download(unquote(raw_image_url).replace('\\', ''))

        if resource:
            logger.info('writing {}'.format(image_source_path))
            write_file(image_source_path, 'wb', resource)

        latex = replace_image(image_source_path, image_target_path,
                              raw_image_url, latex)

        logger.info('image sequence run has finished returning\n')

    return latex
Exemplo n.º 2
0
def extract_image_path(raw_image_url):
    image_file = urlparse(raw_image_url).path

    image_source_path = file_path('/assets/{}{}'.format(
        str(uuid.uuid4()), file_extension(image_file)))

    return image_source_path
Exemplo n.º 3
0
def check_convert_image(image_source_path, image_target_path):
    svg_file_types = ['image/svg+xml', 'image/svg']
    dimensions = None

    image_target_path = file_path('/assets/{}.png'.format(
        file_name(image_target_path)))

    if file_type(image_source_path) in svg_file_types:
        dimensions = convert_svg_image(image_source_path, image_target_path)

    elif file_type(image_source_path) == 'image/gif':
        dimensions = convert_gif_image(image_source_path, image_target_path)

    return dimensions
Exemplo n.º 4
0
def initialize():
    args = argparser()

    source = args.input
    format = args.format

    makedir(file_path('/output'))
    makedir(file_path('/assets'))

    if args.format == 'gfm':
        resource = convert_other(source, 'html', format)
        source = file_path('/output/{}.html'.format(args.output))
        logger.info('writing {}'.format(source))
        write_file(source, 'w', resource)
    elif args.format == 'rst':
        resource = convert_other(source, 'md', format)
        source = file_path('/output/{}.md'.format(args.output))
        logger.info('writing {}'.format(source))
        write_file(source, 'w', resource)

    latex = convert_markdown(source, format)
    latex = replace_urls(args.input, latex)
    latex = replace_rule(latex)
    latex = replace_emoji(latex)
    latex = replace_quote(latex)
    latex = replace_unicode(latex)
    latex = replace_verbatim(latex)
    images = find_all_images(latex)

    latex = iterate_image_strings(images, latex)
    target = file_path('/output/{}.tex'.format(args.output))
    logger.info('writing {}'.format(target))
    write_file(target, 'w', latex)

    if not args.dry:
        convert_latex(args.output)
Exemplo n.º 5
0
def convert_latex(target):
    subprocess.call(
        'xelatex -interaction nonstopmode -output-directory {} {}'.
        format(  # noqa: E501
            file_path('/output'), file_path('/output/{}.tex'.format(target))),
        shell=True)