3

How can one display the contents of a GitHub Gist while parsing a markdown file client-side using Marked.js or with any other client Markdown library? The code below renders the Markdown file except the Gist.

fetch("https://raw.githubusercontent.com/Ayanmullick/test/master/ScriptTagTest.md")
    .then(response => response.blob())  // Unwrap to a blob...
    .then(blob => blob.text())          // ...then to raw text...
    .then(markdown => {        // .pass raw text into marked.parse
document.getElementById("content").innerHTML=marked.parse(markdown)
    })
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>

<div id="content"></div>

However, the Gist renders OK in Visual Studio Code after disabling Markdown content preview settings : Disable preview security warning in this workspace.

enter image description here

Ayan Mullick
  • 67
  • 2
  • 11
  • 38
  • Maybe this can give you a heads up : https://stackoverflow.com/questions/11622509/github-how-to-embed-a-gist-into-readme-md – SARAN SURYA Mar 29 '23 at 04:44
  • @SARANSURYA, [This answer](https://stackoverflow.com/a/32030995/2748772) provides a solution for [Jekyll](https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-jekyll-build-errors-for-github-pages-sites#viewing-jekyll-build-error-messages-with-github-actions) that renders the pages to HTML in the repository. I'm trying to fetch and render the Markdown file client-side. – Ayan Mullick Mar 29 '23 at 05:00

1 Answers1

0

This might be occurring because Marked.js is not executing the script in the parsed markdown file. I'm not sure which libraries would allow you to do this but according to this you might be able to do this in Docsify-JS https://gist.github.com/MichaelCurrin/c2bece08f27c4277001f123898d16a7c

You need to enable this executescript:true in order to run the inline scripts https://docsify.js.org/#/configuration?id=executescript

mushahidq
  • 96
  • 4
  • I had tried that too. The [Docsify team confirmed on Discord](https://discord.com/channels/713647066802421792/1087565808856735818/1087761151510712456) that [they didn't support it](https://gist.github.com/MichaelCurrin/c2bece08f27c4277001f123898d16a7c#gist-embedded-with-a-script-tag). – Ayan Mullick Mar 29 '23 at 07:38