Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Fix table overflow in rendered markdown #9957

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && markdownWithoutTasks.includes('<table')) {
return;
} else {
const parser = new DOMParser();
const doc = parser.parseFromString(markdownWithoutTasks as string, 'text/html');
const tables = doc.querySelectorAll('table');
rabeatwork marked this conversation as resolved.
Show resolved Hide resolved

tables.forEach((table) => {
table.style.maxWidth = '100%';
table.style.overflowX = 'scroll';
table.style.display = 'block';
});
return doc.body.innerHTML;
}
}
rabeatwork marked this conversation as resolved.
Show resolved Hide resolved

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;
}
Loading