Skip to content

Commit

Permalink
feat: Add markdown support for temporary comment system (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
yammesicka authored Feb 26, 2024
1 parent 9eb5de2 commit ece9ee8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion devops/lms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- lms

rabbitmq:
image: rabbitmq:3.12-management-alpine
image: rabbitmq:3.8-management-alpine
hostname: celery-mq
volumes:
- rabbit-data-volume:/var/lib/rabbitmq
Expand Down
21 changes: 19 additions & 2 deletions lms/static/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function isSolverComment(commentData) {
}

function formatCommentData(commentData) {
let changedCommentText = `<span class="comment-author">${commentData.author_name}:</span> ${commentData.text}`;
const commentText = DOMPurify.sanitize(marked.parse(commentData.text));
let changedCommentText = `<span class="comment-author">${commentData.author_name}:</span> ${commentText}`;
if (window.isUserGrader() || isSolverComment(commentData)) {
const deleteButton = `<i class="fa fa-trash grader-delete" aria-hidden="true" data-commentid="${commentData.id}" onclick="deleteComment(${window.fileId}, ${commentData.id});"></i>`;
changedCommentText = `${deleteButton} ${changedCommentText}`;
Expand All @@ -55,10 +56,14 @@ function addCommentToLine(line, commentData) {
boundary: 'viewport',
placement: 'auto',
});

commentElement.addEventListener('shown.bs.popover', function () {
Prism.highlightAllUnder(existingPopover.tip);
})
}

commentElement.dataset.comment = 'true';
if (commentData.is_auto) {
if ((commentData.is_auto) && (commentElement.dataset.marked !== 'true')) {
markLine(commentElement, FLAKE_COMMENTED_LINE_COLOR);
} else {
const lineColor = window.getLineColorByRole(commentData.author_role);
Expand Down Expand Up @@ -140,6 +145,17 @@ function addLineSpansToPre(items) {
window.dispatchEvent(new Event('lines-numbered'));
}

function configureMarkdownParser() {
marked.use({
renderer: {
code: (code, infoString, _) => {
const language = infoString || 'plaintext';
return `<pre><code class="language-${language}">${code}</code></pre>`;
}
},
});
}

window.markLink = markLine;
window.hoverLine = hoverLine;
window.addCommentToLine = addCommentToLine;
Expand All @@ -152,6 +168,7 @@ window.addEventListener('load', () => {
sessionStorage.setItem('role', codeElementData.role);
sessionStorage.setItem('solver', codeElementData.solver);
sessionStorage.setItem('allowedComment', codeElementData.allowedComment);
configureMarkdownParser();
addLineSpansToPre(document.getElementsByTagName('code'));
pullComments(window.fileId, treatComments);
});
6 changes: 6 additions & 0 deletions lms/static/markdown.js

Large diffs are not rendered by default.

Loading

0 comments on commit ece9ee8

Please sign in to comment.