Skip to content

Commit

Permalink
Fix image export in combination with hover text
Browse files Browse the repository at this point in the history
  • Loading branch information
badkeyy committed Nov 27, 2024
1 parent e3ed347 commit 34bf0e8
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public abstract class ExerciseWithSubmissionsExportService {

private static final String EMBEDDED_FILE_MARKDOWN_SYNTAX_REGEX = "\\[.*] *\\(/api/files/markdown/.*\\)";

private static final String EMBEDDED_FILE_MARKDOWN_WITH_HOVERTEXT = "\\(/api/files/markdown/.* \".*\"\\)";

private static final String EMBEDDED_FILE_HTML_SYNTAX_REGEX = "<img src=\"/api/files/markdown/.*\".*>";

private static final String API_MARKDOWN_FILE_PATH = "/api/files/markdown/";
Expand Down Expand Up @@ -129,7 +131,15 @@ private void copyFilesEmbeddedWithMarkdownSyntax(Exercise exercise, List<String>
for (String embeddedFile : embeddedFilesWithMarkdownSyntax) {
// avoid matching other closing ] or () in the squared brackets by getting the index of the last ]
String lastPartOfMatchedString = embeddedFile.substring(embeddedFile.lastIndexOf("]") + 1);
String filePath = lastPartOfMatchedString.substring(lastPartOfMatchedString.indexOf("(") + 1, lastPartOfMatchedString.indexOf(")"));
String filePath;

if (Pattern.compile(EMBEDDED_FILE_MARKDOWN_WITH_HOVERTEXT).matcher(lastPartOfMatchedString).matches()) {
filePath = lastPartOfMatchedString.substring(lastPartOfMatchedString.indexOf("(") + 1, lastPartOfMatchedString.indexOf(" "));
}
else {
filePath = lastPartOfMatchedString.substring(lastPartOfMatchedString.indexOf("(") + 1, lastPartOfMatchedString.indexOf(")"));
}

constructFilenameAndCopyFile(exercise, exportErrors, embeddedFilesDir, filePath);
}
}
Expand Down

0 comments on commit 34bf0e8

Please sign in to comment.