Skip to content

Commit

Permalink
Merge pull request #1350 from codalab/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
Didayolo authored Mar 5, 2024
2 parents b650ce8 + 39c9e5c commit ca2af84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
49 changes: 25 additions & 24 deletions src/static/js/ours/latex_markdown_html.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
// Function to render Markdown, HTML and Latex and return updated content
function renderMarkdownWithLatex(content) {
if(content === null){
return []
}
const parsedHtml = new DOMParser().parseFromString(marked(content), "text/html")
const traverseAndRenderLatex = (node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
const latexPattern = /\$\$([\s\S]*?)\$\$|\$([^\$\n]*?)\$/g
const hasLatex = latexPattern.test(node.textContent)
if (hasLatex) {
const tempDiv = document.createElement('div')
tempDiv.innerHTML = node.innerHTML.replace(latexPattern, (_, formula1, formula2) => {
const formula = formula1 || formula2
return katex.renderToString(formula, { throwOnError: false })
});
node.innerHTML = tempDiv.innerHTML
}
if(content === null){
return []
}
const parsedHtml = new DOMParser().parseFromString(marked(content), "text/html")

const traverseAndRenderLatex = (node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
const latexPattern = /\$\$([\s\S]*?)\$\$|\$([^\$\n]*?)\$/g
const hasLatex = latexPattern.test(node.textContent)
if (hasLatex) {
const tempDiv = document.createElement('div')
tempDiv.innerHTML = node.innerHTML.replace(latexPattern, (_, formula1, formula2) => {
const formula = formula1 || formula2
const decodedFormula = formula.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
return katex.renderToString(decodedFormula, { throwOnError: false })
});
node.innerHTML = tempDiv.innerHTML
}

node.childNodes.forEach(traverseAndRenderLatex)
};

traverseAndRenderLatex(parsedHtml.body)

return parsedHtml.body.childNodes
}

node.childNodes.forEach(traverseAndRenderLatex)
};

traverseAndRenderLatex(parsedHtml.body)

return parsedHtml.body.childNodes
}
9 changes: 4 additions & 5 deletions src/static/riot/tasks/management.tag
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<i class="checkmark box icon green" show="{ task.is_public }"></i>
</td>
<td>
<div if="{ task.created_by == CODALAB.state.user.id }">
<div if="{ task.created_by == CODALAB.state.user.username }">
<button class="mini ui button blue icon" onclick="{show_edit_modal.bind(this, task)}">
<i class="icon pencil"></i>
</button>
Expand All @@ -55,7 +55,7 @@
</div>
</td>
<td class="center aligned">
<div class="ui fitted checkbox" if="{ task.created_by == CODALAB.state.user.id }">
<div class="ui fitted checkbox" if="{ task.created_by == CODALAB.state.user.username }">
<input type="checkbox" name="delete_checkbox" onclick="{ mark_task_for_deletion.bind(this, task) }">
<label></label>
</div>
Expand All @@ -69,9 +69,8 @@
</tr>
</tbody>
<tfoot>
<!-------------------------------------
Pagination
-------------------------------------->

<!-- Pagination -->
<tr if="{tasks.length > 0}">
<th colspan="7">
<div class="ui right floated pagination menu" if="{tasks.length > 0}">
Expand Down

0 comments on commit ca2af84

Please sign in to comment.