Repository navigation
Expand file tree
/
Copy pathm4r.py
More file actions
64 lines (56 loc) · 1.77 KB
/
Copy pathm4r.py
File metadata and controls
64 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import subprocess
import argparse
import os
# from common.utils import get_metadata
# from common import __main__
# 调用pandoc
def call_pandoc(args):
# 获取输入文件的绝对路径
input_path = os.path.abspath(args.input_file)
template_path = os.path.abspath(args.template)
vscode_light = os.path.abspath(os.path.join(os.path.dirname(__file__), "backend/common/utils/assets/vscode_light.theme"))
if not args.output:
# 没有指定输出路径,则使用输入文件的路径和文件名
output_path = os.path.splitext(input_path)[0] + ".docx"
else:
output_path = os.path.abspath(args.output)
# 构建 pandoc 命令
command = ["pandoc", "-s", input_path, "--reference-doc", template_path, "-o", output_path, "--highlight-style", vscode_light]
# 执行命令
subprocess.run(command, cwd=os.path.dirname(input_path))
def call_handle(args):
input_path = os.path.abspath(args.input_file)
template_path = os.path.abspath(args.template)
command = ["python3", "-m", "backend/common", input_path, "exp"]
subprocess.run(command)
# 打开文件路径
def open_dir(file_path):
'''在文件管理器中显示生成的文件'''
pass
# 命令行主体
parser = argparse.ArgumentParser(prog='md4report')
# 输入文件
parser.add_argument(
"input_file",
help="input markdown file",
# required=True
)
# 引用文件
parser.add_argument(
"-t",
"--template",
help="template name",
default="backend/common/ref/exp.docx",
required=False
)
# 输出文件
parser.add_argument(
"-o",
"--output",
help="output docx file",
required=False
)
args = parser.parse_args()
# 调用 pandoc
call_pandoc(args)
call_handle(args)