Skip to content
Snippets Groups Projects
Commit 97898e9e authored by Mikhail Vanyulin's avatar Mikhail Vanyulin Committed by Jonas Höppner
Browse files

convert_md2html: use gitlab api


Update convert_md2html.py to use gitlab api with gitlab flavor.

Signed-off-by: default avatarMikhail Vanyulin <mikhail.vanyulin@rtsoft.de>
parent 4595835d
No related branches found
No related tags found
1 merge request!382convert_md2html: use gitlab api
......@@ -281,7 +281,11 @@ workflow:
timeout: 5m
script:
- for file in ${FILES}; do
.gitlab-ci/scripts/convert_md2html.py $file;
.gitlab-ci/scripts/convert_md2html.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--project=${CI_PROJECT_PATH}
--filename $file;
done
artifacts:
paths:
......
#!/usr/bin/env python3
import argparse
import codecs
import glob
import os
from markdown2 import markdown_path
from gitlab.client import Gitlab
import common
HEADER = """
<!doctype html>
......@@ -178,35 +179,55 @@ FOOTER = """
"""
def convertmd2html(infile, outfile):
encoding = "utf-8"
fout = codecs.open(outfile, "w", encoding)
fout.write(HEADER)
extras = {"tables": ""}
html = markdown_path(infile, extras=extras)
fout.write(html)
fout.write(FOOTER)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"filename",
"--gitlab-url",
help="""URL to the GitLab instance""",
dest="gitlab_url",
default=common.GITLAB_URL,
required=True,
)
parser.add_argument(
"--token",
help="""GitLab REST API private access token""",
dest="token",
required=True,
)
parser.add_argument(
"--project",
help="""name of the GitLab project""",
dest="project",
required=True,
)
parser.add_argument(
"--filename",
help="""File(s) to convert""",
nargs="+",
required=True,
)
args, _ = parser.parse_known_args()
gitlab = Gitlab(args.gitlab_url, private_token=args.token)
encoding = "utf-8"
for filename in args.filename:
for input_filename in glob.glob(filename):
output_filename = f"{os.path.splitext(input_filename)[0]}.html"
print(f"Converting {input_filename} to {output_filename}")
convertmd2html(input_filename, output_filename)
fin = open(input_filename, encoding=encoding)
fout = open(output_filename, "w", encoding=encoding)
fout.write(HEADER)
html = gitlab.markdown(fin.read(), True, args.project)
fout.write(html)
fout.write(FOOTER)
fin.close()
fout.close()
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment