Fix issue for when an assignment text has no paragraph tag
This commit is contained in:
parent
6a98a5b3ad
commit
4ed03ac5f3
|
|
@ -9,7 +9,7 @@
|
|||
class="assignment__main-text assignment-text"
|
||||
data-cy="assignment-main-text"
|
||||
v-if="assignment.assignment > ''"
|
||||
v-html="assignment.assignment"
|
||||
v-html="assignmentHtml"
|
||||
/>
|
||||
|
||||
<assignment-solution
|
||||
|
|
@ -211,6 +211,19 @@ const feedbackText = computed(() => {
|
|||
let sanitizedFeedbackText = sanitize(feedback.text);
|
||||
return `<span class="inline-title">Feedback von ${feedback.teacher.firstName} ${feedback.teacher.lastName}:</span> ${sanitizedFeedbackText}`;
|
||||
});
|
||||
const containsParagraphs = (str: string) => {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(str, 'text/html');
|
||||
return doc.querySelectorAll('p') > 0;
|
||||
};
|
||||
const assignmentHtml = computed(() => {
|
||||
const assignmentText = assignment.value.assignment;
|
||||
if (containsParagraphs(assignmentText)) {
|
||||
return assignmentText;
|
||||
}
|
||||
// text needs to be inside a paragraph, otherwise the highlighting will fail
|
||||
return `<p>${assignmentText}</p>`;
|
||||
});
|
||||
|
||||
const childElements = computed(() => {
|
||||
// todo: refactor and merge with the one in ContentComponent.vue
|
||||
|
|
|
|||
Loading…
Reference in New Issue