From 34bf0e8e2e0dbe6642a80571c0e90bf3da735214 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Wed, 27 Nov 2024 13:18:32 +0100 Subject: [PATCH] Fix image export in combination with hover text --- .../ExerciseWithSubmissionsExportService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/exercise/service/ExerciseWithSubmissionsExportService.java b/src/main/java/de/tum/cit/aet/artemis/exercise/service/ExerciseWithSubmissionsExportService.java index 1ccd03d928fc..381591ecdb85 100644 --- a/src/main/java/de/tum/cit/aet/artemis/exercise/service/ExerciseWithSubmissionsExportService.java +++ b/src/main/java/de/tum/cit/aet/artemis/exercise/service/ExerciseWithSubmissionsExportService.java @@ -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 = ""; private static final String API_MARKDOWN_FILE_PATH = "/api/files/markdown/"; @@ -129,7 +131,15 @@ private void copyFilesEmbeddedWithMarkdownSyntax(Exercise exercise, List 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); } }