Skip to content

Commit a1bccaf

Browse files
committed
[docusaurus] Also resolve iframe links inside Markdown files
1 parent 9a5dc27 commit a1bccaf

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

openedu_builder/plugins/docusaurus.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import logging
23
import os
34
import re
@@ -321,6 +322,7 @@ def _resolve_links(self):
321322
log.debug(dst_to_src)
322323

323324
md_link_regex = re.compile(r"\[.*?\]\((\.(?:\.)?\/.*?)\)")
325+
iframe_link_regex = re.compile(r"<iframe.*?src=\"(\.(?:\.)?\/.*?)\".*?>")
324326

325327
dst_files = []
326328

@@ -363,7 +365,10 @@ def _walk_struct(structure):
363365
with open(_file, "r") as f:
364366
content = f.read()
365367

366-
for match in re.finditer(md_link_regex, content):
368+
for match in itertools.chain(
369+
re.finditer(md_link_regex, content),
370+
re.finditer(iframe_link_regex, content),
371+
):
367372
src_link = match.group(1)
368373
log.info(f"Found link {src_link}")
369374
# dst_link = src_to_dst[path_utils.real_join(src_dir, src_link)]
@@ -432,7 +437,7 @@ def run(self):
432437
log.error(f"Command {self.init_command} failed with code {p.returncode}")
433438
log.error(f"STDOUT: {p.stdout.decode('utf-8')}")
434439
log.error(f"STDERR: {p.stderr.decode('utf-8')}")
435-
raise PluginRunError(f"Error while running init command")
440+
raise PluginRunError("Error while running init command")
436441

437442
# Folders we need to delete:
438443
# - blog
@@ -490,16 +495,14 @@ def run(self):
490495
log.error(f"Command {math_command} failed with code {p.returncode}")
491496
log.error(f"STDOUT: {p.stdout.decode('utf-8')}")
492497
log.error(f"STDERR: {p.stderr.decode('utf-8')}")
493-
raise PluginRunError(
494-
f"Error while installing math dependencies command"
495-
)
498+
raise PluginRunError("Error while installing math dependencies command")
496499

497500
p = subprocess.run(self.build_command, capture_output=True)
498501
if p.returncode != 0:
499502
log.error(f"Command {self.build_command} failed with code {p.returncode}")
500503
log.error(f"STDOUT: {p.stdout.decode('utf-8')}")
501504
log.error(f"STDERR: {p.stderr.decode('utf-8')}")
502-
raise PluginRunError(f"Error while running build command")
505+
raise PluginRunError("Error while running build command")
503506

504507
# os.mkdir(path_utils.real_join(self.output_dir, "output"))
505508
if not self.config.get("debug", False):

0 commit comments

Comments
 (0)