Skip to content

Commit

Permalink
Merge pull request #83 from MatsMoll/develop
Browse files Browse the repository at this point in the history
Minor rendering changes
  • Loading branch information
MatsMoll authored Oct 24, 2020
2 parents fac46df + 5f508e7 commit f3bcfed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
25 changes: 18 additions & 7 deletions Public/assets/js/markdown-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ function renderKatex(plainText) {
output += leftovers.substring(0, index);
leftovers = leftovers.substring(index + 2, leftovers.length);
let endIndex = leftovers.indexOf("$$");
if (endIndex != -1) {
let katexSubstring = new DOMParser().parseFromString(leftovers.substring(0, endIndex), "text/html").documentElement.textContent;
output += katex.renderToString(katexSubstring);
leftovers = leftovers.substring(endIndex + 2, leftovers.length);
} else {
output += "$$";
try {
if (endIndex != -1) {
let katexSubstring = new DOMParser().parseFromString(leftovers.substring(0, endIndex), "text/html").documentElement.textContent;

output += katex.renderToString(katexSubstring);
leftovers = leftovers.substring(endIndex + 2, leftovers.length);
} else {
output += "$$";
}
index = leftovers.indexOf("$$");
} catch (error) {
index = leftovers.indexOf("$$");
if (endIndex != -1) {
output += "<span class='text-warning'>" + leftovers.substring(0, endIndex) + "<br/></span><span class='text-danger'>" + error + "</span><br/>"
leftovers = leftovers.substring(endIndex + 2, leftovers.length);
} else {
output += "<span class='text-warning'>" + leftovers + "</span><span class='text-danger'>" + error + "</span>"
}
}
index = leftovers.indexOf("$$");
}
return output + leftovers;
}
Expand Down
33 changes: 20 additions & 13 deletions Sources/App/Task/Protocols/RenderPracticing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,26 @@ extension TaskType: RenderTaskPracticing {
}

func renderTypingTask(sessionID: PracticeSession.ID, preview: TaskPreviewContent, lastResult: TaskResult?, taskIndex: Int, progress: Int, user: User, on req: Request) -> EventLoopFuture<Response> {
req.repositories.typingTaskRepository
.typingTaskAnswer(in: sessionID, taskID: preview.task.id)
.map { answer in
TypingTask.Templates.Execute.Context(
taskPreview: preview,
user: user,
currentTaskIndex: taskIndex,
practiceProgress: progress,
sessionID: sessionID,
lastResult: lastResult,
prevAnswer: answer
)

req.repositories.practiceSessionRepository
.find(sessionID)
.flatMap { session in

req.repositories.typingTaskRepository
.typingTaskAnswer(in: sessionID, taskID: preview.task.id)
.map { answer in
TypingTask.Templates.Execute.Context(
taskPreview: preview,
user: user,
currentTaskIndex: taskIndex,
practiceProgress: progress,
sessionID: sessionID,
lastResult: lastResult,
prevAnswer: answer,
numberOfTaskGoal: session.numberOfTaskGoal
)
}
.flatMapThrowing { try req.htmlkit.render(TypingTask.Templates.Execute.self, with: $0) }
}
.flatMapThrowing { try req.htmlkit.render(TypingTask.Templates.Execute.self, with: $0) }
}
}

0 comments on commit f3bcfed

Please sign in to comment.