Prettify Render of Markdown Results in Web Interface

This commit is contained in:
Debanjum Singh Solanky
2022-07-28 20:56:37 +04:00
parent a6ae74f52e
commit a9bc17a6b0
2 changed files with 8493 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
<title>Khoj</title> <title>Khoj</title>
</head> </head>
<script type="text/javascript" src="static/assets/org.js"></script> <script type="text/javascript" src="static/assets/org.js"></script>
<script type="text/javascript" src="static/assets/markdown-it.js"></script>
<script> <script>
function render_image(item) { function render_image(item) {
@@ -25,8 +26,17 @@
return orgHTMLDocument.toString(); return orgHTMLDocument.toString();
} }
function render_markdown(query, data) {
var md = window.markdownit();
return md.render(`# Query: ${query}\n` + data.map(function (item) {
return `${item.entry}`
}).join("\n"));
}
function render_json(data, query, type) { function render_json(data, query, type) {
if (type === "org") { if (type === "markdown") {
return render_markdown(query, data);
} else if (type === "org") {
return render_org(query, data); return render_org(query, data);
} else if (type === "image") { } else if (type === "image") {
return data.map(render_image).join(''); return data.map(render_image).join('');
@@ -160,6 +170,11 @@
white-space: pre-wrap; white-space: pre-wrap;
} }
#results-markdown {
text-align: left;
white-space: pre-line;
}
#results-org { #results-org {
text-align: left; text-align: left;
white-space: pre-line; white-space: pre-line;