Skip to content

Commit

Permalink
Fixed build,
Browse files Browse the repository at this point in the history
added Dompurify,
Marked working
  • Loading branch information
elocremarc committed Sep 5, 2023
1 parent a161008 commit bf353b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,9 @@ impl Server {
Media::Markdown => Ok(
(
[(
header::CONTENT_SECURITY_POLICY,
"default-src 'self' https://cdn.jsdelivr.net",
)],
header::CONTENT_SECURITY_POLICY,
"script-src-elem 'self' https://cdn.jsdelivr.net",
)],
PreviewMarkdownHtml { inscription_id },
)
.into_response(),
Expand Down
2 changes: 1 addition & 1 deletion src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) use {
output::{OutputHtml, OutputJson},
page_config::PageConfig,
preview::{
PreviewAudioHtml, PreviewImageHtml, PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml,
PreviewAudioHtml, PreviewImageHtml, PreviewModelHtml, PreviewPdfHtml, PreviewMarkdownHtml, PreviewTextHtml,
PreviewUnknownHtml, PreviewVideoHtml,
},
range::RangeHtml,
Expand Down
4 changes: 4 additions & 0 deletions static/preview-markdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
html {
color: #98a3ad;
background-color: #131516;
}
11 changes: 6 additions & 5 deletions static/preview-markdown.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import marked from 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
import { marked } from 'https://cdn.jsdelivr.net/npm/marked@8.0.0/+esm'
import DOMPurify from 'https://cdn.jsdelivr.net/npm/dompurify@3.0.5/+esm'

async function renderMarkdown() {
const contentDiv = document.getElementById('content');

const inscriptionId = contentDiv.dataset.inscription;
const response = await fetch(`/content/${inscriptionId}`);
const markdownContent = await response.text();
const rawMarkdown = await response.text();

const htmlContent = marked.parse(markdownContent);
contentDiv.innerHTML = htmlContent;
const html = DOMPurify.sanitize(marked.parse(rawMarkdown));

contentDiv.innerHTML = html;
}

window.addEventListener('DOMContentLoaded', renderMarkdown);
3 changes: 2 additions & 1 deletion templates/preview-markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<html lang="en">
<head>
<meta charset="utf-8">
<script src="/static/preview-markdown.js" defer type="module"></script>
<link rel=stylesheet href="/static/preview-markdown.css"></link>
</head>
<body>
<div id="content" data-inscription="{{self.inscription_id}}"></div>
<script src="/static/preview-markdown.js" defer type="module"></script>
</body>
</html>

0 comments on commit bf353b8

Please sign in to comment.