Skip to content

Commit 2e523f4

Browse files
authored
Merge pull request #87 from soft-eng-practicum/readme-versioning-error
readme error resolved
2 parents b160356 + 7b03727 commit 2e523f4

File tree

3 files changed

+59
-62
lines changed

3 files changed

+59
-62
lines changed

src/Analysim.Web/ClientApp/package-lock.json

Lines changed: 25 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analysim.Web/ClientApp/src/app/projects/project/project.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
.notebook-readme-full{
5555
margin-bottom: 4px;
56+
overflow-x: scroll;
5657
}
5758

5859
.notebook-cell pre code div {

src/Analysim.Web/ClientApp/src/app/projects/project/project.component.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,23 @@ export class ProjectComponent implements OnInit {
9595
if (this.currentUser != null && this.project.projectUsers.find(x => x.userID == this.currentUser.id) != undefined) {
9696
this.projectUser = this.project.projectUsers.find(x => x.userID == this.currentUser.id)
9797
}
98+
// console.log("Result : ", result);
9899
this.readmeNotebook = result.notebooks.filter((notebook) => notebook.name.toLowerCase() === "readme")[0];
100+
// console.log("readme : " ,this.readmeNotebook);
99101
this.projectService.getNotebookVersions(result.notebooks.filter((notebook) => notebook.name.toLowerCase() === "readme")[0]).subscribe(versions => {
100102
this.versions = versions;
101-
//console.log("Versions: ", this.versions);
103+
// console.log("Versions: ", this.versions);
102104
if (this.versions.length > 0) {
103105
this.latestVersion = this.versions[0]; // Default to the latest version
104106
}
105107
// console.log("the loatest version : ", this.latestVersion);
108+
this.projectService.getNotebookFile(result.notebooks.filter((notebook) => notebook.name.toLowerCase() === "readme")[0], this.latestVersion).subscribe(
109+
notebookJson => {
110+
// console.log("the notebook content is : ", notebookJson);
111+
this.notebookContent = this.sanitizer.bypassSecurityTrustHtml(this.renderNotebook(notebookJson));
112+
});
106113
});
107114
// console.log("readme file is : ", result.notebooks.filter((notebook) => notebook.name.toLowerCase() === "readme")[0]);
108-
this.projectService.getNotebookFile(result.notebooks.filter((notebook) => notebook.name.toLowerCase() === "readme")[0], this.latestVersion).subscribe(
109-
notebookJson => {
110-
this.notebookContent = this.sanitizer.bypassSecurityTrustHtml(this.renderNotebook(notebookJson));
111-
// console.log("the notebook content is : ", this.notebookContent);
112-
});
113115
}
114116

115117
)
@@ -174,28 +176,47 @@ export class ProjectComponent implements OnInit {
174176
closeDisplayNotebookModal() {
175177
this.displayNotebookModalRef.hide();
176178
this.router.navigate([this.router.url.split('/').slice(0,5).join('/')])
179+
this.projectService.getNotebookVersions(this.readmeNotebook).subscribe(versions => {
180+
this.versions = versions;
181+
// console.log("Versions: ", this.versions);
182+
if (this.versions.length > 0) {
183+
this.latestVersion = this.versions[0]; // Default to the latest version
184+
}
185+
// console.log("the loatest version : ", this.latestVersion);
186+
this.projectService.getNotebookFile(this.readmeNotebook, this.latestVersion).subscribe(
187+
notebookJson => {
188+
// console.log("the notebook content is : ", notebookJson);
189+
this.notebookContent = this.sanitizer.bypassSecurityTrustHtml(this.renderNotebook(notebookJson));
190+
});
191+
});
177192
}
178193

179194
renderNotebook(notebookJson: any): string {
180-
// Simple rendering of the notebook. Customize as needed.
195+
// console.log("notebook rendering content :" , notebookJson);
181196
let htmlContent = `<div class="notebookClass">`;
182197
for (const cell of notebookJson.cells) {
183198
htmlContent += '<div class="notebook-cell">';
184199
if (cell.cell_type === 'markdown') {
185-
htmlContent += marked(cell.source.join(''));
200+
const markdownContent = Array.isArray(cell.source) ? cell.source.join('') : cell.source;
201+
htmlContent += marked(markdownContent);
186202
} else if (cell.cell_type === 'code') {
187-
htmlContent += '<pre><code><div>' + hljs.highlight(cell.source.join(''), {language: 'python'}).value + '</div></code></pre>';
203+
// console.log("error: ", hljs.highlight(cell.source, {language: 'python'}));
204+
const codeContent = Array.isArray(cell.source) ? cell.source.join('') : cell.source;
205+
htmlContent += '<pre><code><div>' + hljs.highlight(codeContent, { language: 'python' }).value + '</div></code></pre>';
188206
if (cell.outputs) {
189207
for (const output of cell.outputs) {
190208
if (output.data && output.data['text/html']) {
191-
htmlContent += output.data['text/html'].join('');
209+
const htmlOutput = Array.isArray(output.data['text/html']) ? output.data['text/html'].join('') : output.data['text/html'];
210+
htmlContent += htmlOutput;
192211
} else if (output.data && output.data['image/png']) {
193212
htmlContent += `<img src="data:image/png;base64,${output.data['image/png']}" />`;
194213
} else if (output.data && output.data['text/plain']) {
195-
htmlContent += '<pre>' + output.data['text/plain'].join('') + '</pre>';
214+
const plainTextOutput = Array.isArray(output.data['text/plain']) ? output.data['text/plain'].join('') : output.data['text/plain'];
215+
htmlContent += '<pre>' + plainTextOutput + '</pre>';
196216
}
197217
else if (output.text) {
198-
htmlContent += '<pre>' + output.text.join('') + '</pre>';
218+
const outputText = Array.isArray(output.text) ? output.text.join('') : output.text;
219+
htmlContent += '<pre>' + outputText + '</pre>';
199220
}
200221
}
201222
}

0 commit comments

Comments
 (0)