Last active
January 3, 2024 15:43
-
-
Save jishen027/d85de3a71a1b00bcb159fd2cd190029d to your computer and use it in GitHub Desktop.
markdown-it usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- better include github md style for table format --> | |
<!-- Styles --> | |
<link rel="stylesheet" href="./github-md-style.css"> | |
<main> | |
</main> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hljs = window.hljs; | |
var markdownittable = window.markdownittable; | |
var md = window.markdownit({ | |
html: true, | |
linkify: true, | |
typographer: true, | |
breaks: true, | |
table: true, | |
highlight: function (str, lang) { | |
if (lang && hljs.getLanguage(lang)) { | |
try { | |
return '<pre class="hljs"><code>' + | |
hljs.highlight(str, { | |
language: lang, | |
ignoreIllegals: true | |
}).value + | |
'</code></pre>'; | |
} catch (__) { } | |
} | |
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>'; | |
}, | |
}); | |
// render markdown fromr file in public folder | |
await fetch("https://raw.githubusercontent.com/JebLee-OasisStudio/HTC-Api-documentation/main/api-keys-documentation.md") | |
.then(response => response.text()) | |
.then(text => { | |
document.querySelector("main").innerHTML = md.render(text); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment