Last active
March 4, 2022 09:51
-
-
Save CarsonSlovoka/3c3bbf1e4d3e8bc9655c555c40ae8a69 to your computer and use it in GitHub Desktop.
markdown-it tutorial (pure javascript only)
This file contains 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/12.3.2/markdown-it.min.js" | |
integrity="sha512-TIDbN32lXOg2Mw1VcnKrQLZgfALryJogWCu/NHWtlMCR1jget+mOwMtdehBBZz2f9PKeK2AQPwVxkbl4u/1H5g==" | |
crossorigin="anonymous" referrerpolicy="no-referrer"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.14.0/mermaid.js"></script> | |
<div data-com="markdown-it"> | |
# [Markdown-it](https://github.com/markdown-it/markdown-it#plugins-load) USAGE | |
## Table | |
| Name | desc | | |
|:----: | ---- | | |
Hi | 1234 | |
cls | clear | |
## utils | |
- `code` | |
- **bold** | |
- *italic* | |
## Image | |
[![Build Status](https://travis-ci.org/markdown-it/markdown-it.svg)](https://travis-ci.org/markdown-it/markdown-it) | |
```go | |
package main | |
import ( | |
"fmt" | |
"log" | |
) | |
func main() { | |
} | |
``` | |
## mermaid test | |
<div class="mermaid"> | |
flowchart TD | |
A[Start] --> B{Is it?} | |
B -->|Yes| C[OK] | |
C --> D[Rethink] | |
D --> B | |
B ---->|No| E[End] | |
</div> | |
</div> | |
<script> | |
mermaid.initialize({ | |
theme: 'forest', // forest dark, base, default | |
logLevel: "fatal", // debug, fatal | |
securityLevel: 'loose', // strict, loose, antiscript, sandbox // https://github.com/mermaid-js/mermaid/blob/b141f24068e9c5f6979706383a29db6380ffdf31/docs/usage.md?plain=1#L114-L117 | |
flowchart: {curve: 'basis'}, | |
}) | |
window.onload = () => { | |
document.querySelectorAll(`[data-com="markdown-it"]`).forEach(elem => { | |
if (elem.dataset.com === undefined) { | |
return | |
} | |
const md = window.markdownit({ | |
html: true, | |
linkify: true, | |
typographer: true | |
}) | |
elem.outerHTML = md.render(elem.innerHTML) | |
}) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:
![image](https://user-images.githubusercontent.com/17170765/156738923-b56d57d5-5217-4eb1-b5e4-a8aaaab042c6.png)