You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.7 KiB

#!/usr/bin/env python3
import argparse
import re
import sys
from typing import List
import os
# Import local files
from transform import transform
from util import *
from context import Context
from group import Group
from katex import KatexClient
from html import html
from tex import tex
from images import ImageProcessor
from mj_show import show
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--img-lookup-dirs", help="Image lookup directories. When processing images, the program will try to find the image in them first. By default contains the directory of each MarkDown file.", nargs="+", default=[])
parser.add_argument("-p", "--img-public-dir", help="Directory to put processed images into. The program will not overwrite existing images.", nargs=1, default="public")
parser.add_argument("-i", "--img-web-path", help="Path where the processed images are available on the website.", nargs=1, default="/")
parser.add_argument("-w", "--output-html", help="The HTML file (for Web) to write into.", nargs=1, default="output.html")
parser.add_argument("-t", "--output-tex", help="The TEX file to write into.", nargs=1, default="output.tex")
parser.add_argument("input_filename", help="The MarkDown file to process.")
args = parser.parse_args()
doc = import_md(open(args.input_filename, "r").read())
language = doc.get_metadata("language", None, True)
context = Context(doc, args.input_filename)
doc = doc.walk(transform, context)
doc.content = [Group(*doc.content, metadata={"language":language})]
katexClient = KatexClient()
imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, *args.img_lookup_dirs)
open(args.output_html, "w").write(html(doc, katexClient, imageProcessor))
open(args.output_tex, "w").write(tex(doc, imageProcessor))