Skip to content

Commit d7dc97c

Browse files
committed
Fix missing support for imgbasedir in md2html
1 parent 7126935 commit d7dc97c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

problemtools/md2html.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ def convert(problem_root: Path, options: argparse.Namespace, statement_file: Pat
2323
options: command-line arguments. See problem2html.py
2424
"""
2525
destfile = string.Template(options.destfile).safe_substitute(problem=problem_root.name)
26+
imgbasedir = string.Template(options.imgbasedir).safe_substitute(problem=problem_root.name)
2627

2728
command = ['pandoc', str(statement_file), '-t', 'html', '--mathjax']
2829
statement_html = subprocess.run(command, capture_output=True, text=True, shell=False, check=True).stdout
2930

30-
statement_html = sanitize_html(statement_file.parent, statement_html)
31+
statement_html = sanitize_html(statement_file.parent, statement_html, imgbasedir)
3132

3233
templatepaths = [
3334
os.path.join(os.path.dirname(__file__), 'templates/markdown_html'),
@@ -76,7 +77,7 @@ def convert(problem_root: Path, options: argparse.Namespace, statement_file: Pat
7677
return True
7778

7879

79-
def sanitize_html(statement_dir: Path, statement_html: str) -> str:
80+
def sanitize_html(statement_dir: Path, statement_html: str, imgbasedir: str) -> str:
8081
# Allow footnote ids (the anchor points you jump to)
8182
def is_fn_id(s):
8283
pattern_id_top = r'^fn\d+$'
@@ -106,7 +107,7 @@ def attribute_filter(tag, attribute, value):
106107
nonlocal image_fail_reason
107108
image_fail_reason.append(e)
108109
return None
109-
return copy_image(statement_dir, value)
110+
return copy_image(statement_dir, value, imgbasedir)
110111
return None
111112

112113
statement_html = nh3.clean(
@@ -132,7 +133,7 @@ def attribute_filter(tag, attribute, value):
132133
return statement_html
133134

134135

135-
def copy_image(statement_dir: Path, img_src: str) -> str:
136+
def copy_image(statement_dir: Path, img_src: str, imgbasedir: str) -> str:
136137
"""Copy image to working directory (with new filename) and returns the new filename
137138
138139
Args:
@@ -147,4 +148,4 @@ def copy_image(statement_dir: Path, img_src: str) -> str:
147148

148149
if not os.path.isfile(filename): # check if already copied
149150
shutil.copyfile(statement_dir / img_src, filename)
150-
return filename
151+
return imgbasedir + filename

0 commit comments

Comments
 (0)