Embed GitHub markdown doc within a page #7360
-
I am trying to embed the Github markdown content for documentation within a page. I am sharing a sample code for example: <title>Embed GitHub Markdown</title> <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <style> body { font-family: Arial, sans-serif; padding: 20px; } #markdown-content { border: 1px solid #ddd; padding: 10px; border-radius: 5px; background-color: #f9f9f9; } </style>GitHub Markdown ContentLoading...
<script>
// Define the new GitHub raw markdown URL and the proxy URL
const markdownURL = 'https://raw.githubusercontent.com/requarks/wiki-docs/refs/heads/master/home.md';
const proxyURL = 'https://corsproxy.io/?';
// Log the final URL for debugging
console.log('Fetching Markdown content from:', proxyURL + encodeURIComponent(markdownURL));
// Fetch and render the markdown content
fetch(proxyURL + encodeURIComponent(markdownURL))
.then(response => {
// Check if the response is ok
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.status + ' - ' + response.statusText);
}
return response.text();
})
.then(mdContent => {
// Parse and render the markdown content
document.getElementById('markdown-content').innerHTML = marked(mdContent);
})
.catch(error => {
// Display an error message if something goes wrong
document.getElementById('markdown-content').innerHTML = 'Error loading Markdown content';
console.error('Error fetching the content:', error);
});
</script>
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Any comments? It's a simple request to re-use the markdown content from GITHub without doing the sync. Please help. |
Beta Was this translation helpful? Give feedback.
-
You can't run javascript inside a page. Use the script feature from the Page properties dialog instead. However what you're trying to do is very hacky and a terrible way to include content. Just link to the page instead... |
Beta Was this translation helpful? Give feedback.
You can't run javascript inside a page. Use the script feature from the Page properties dialog instead.
However what you're trying to do is very hacky and a terrible way to include content. Just link to the page instead...