Skip to content

Commit

Permalink
Programming exercises: Fix table overflow in rendered markdown (#9957)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabeatwork authored Dec 10, 2024
1 parent d312eae commit f01b5eb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ export class ProgrammingExerciseInstructionComponent implements OnChanges, OnDes
const updatedMarkdown = htmlForMarkdown(this.examExerciseUpdateHighlighterComponent.updatedProblemStatement, this.markdownExtensions);
const diffedMarkdown = diff(outdatedMarkdown, updatedMarkdown);
const markdownWithoutTasks = this.prepareTasks(diffedMarkdown);
this.renderedMarkdown = this.sanitizer.bypassSecurityTrustHtml(markdownWithoutTasks);
const markdownWithTableStyles = this.addStylesForTables(markdownWithoutTasks);
this.renderedMarkdown = this.sanitizer.bypassSecurityTrustHtml(markdownWithTableStyles ?? markdownWithoutTasks);
// Differences between UMLs are ignored, and we only inject the current one
setTimeout(() => {
const injectUML = this.injectableContentForMarkdownCallbacks[this.injectableContentForMarkdownCallbacks.length - 1];
Expand All @@ -317,7 +318,8 @@ export class ProgrammingExerciseInstructionComponent implements OnChanges, OnDes
this.injectableContentForMarkdownCallbacks = [];
const renderedProblemStatement = htmlForMarkdown(this.exercise.problemStatement, this.markdownExtensions);
const markdownWithoutTasks = this.prepareTasks(renderedProblemStatement);
this.renderedMarkdown = this.sanitizer.bypassSecurityTrustHtml(markdownWithoutTasks);
const markdownWithTableStyles = this.addStylesForTables(markdownWithoutTasks);
this.renderedMarkdown = this.sanitizer.bypassSecurityTrustHtml(markdownWithTableStyles ?? markdownWithoutTasks);
setTimeout(() => {
this.injectableContentForMarkdownCallbacks.forEach((callback) => {
callback();
Expand All @@ -327,6 +329,23 @@ export class ProgrammingExerciseInstructionComponent implements OnChanges, OnDes
}
}

addStylesForTables(markdownWithoutTasks: string): string | undefined {
if (!markdownWithoutTasks?.includes('<table')) {
return;
} else {
const parser = new DOMParser();
const doc = parser.parseFromString(markdownWithoutTasks as string, 'text/html');
const tables = doc.querySelectorAll('table');

tables.forEach((table) => {
table.style.maxWidth = '100%';
table.style.overflowX = 'scroll';
table.style.display = 'block';
});
return doc.body.innerHTML;
}
}

prepareTasks(problemStatementHtml: string) {
const tasks = Array.from(problemStatementHtml.matchAll(taskRegex));
if (!tasks) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="d-flex justify-content-between horizontal-scroll">
<div class="d-flex horizontal-scroll">
@if (course) {
@if (!isShownViaLti) {
<div [ngClass]="{ 'sidebar-collapsed': isCollapsed }">
Expand All @@ -14,7 +14,11 @@
}

@if (exerciseSelected) {
<div class="vw-100 module-bg rounded-3" [ngStyle]="isShownViaLti ? { height: '90vh', position: 'relative' } : {}">
<div
[ngClass]="{ 'exercise-content-sidebar-width': !isCollapsed }"
class="exercise-content-width module-bg rounded-3"
[ngStyle]="isShownViaLti ? { height: '90vh', position: 'relative' } : {}"
>
<router-outlet (deactivate)="onSubRouteDeactivate()" />
</div>
} @else {
Expand Down
10 changes: 10 additions & 0 deletions src/main/webapp/app/overview/course-overview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,13 @@ canvas#complete-chart {
opacity: 1;
}
}

.exercise-content-sidebar-width {
// magic number is 255px sidebar width + 8px margin
width: calc(100% - 263px) !important;
transition: width 0.1s 0s ease-in-out;
}
.exercise-content-width {
width: 100%;
transition: width 0.1s 0s ease-in-out;
}

0 comments on commit f01b5eb

Please sign in to comment.