Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/timhaj/md2html

Markdown to HTML parser
https://github.com/timhaj/md2html

html javascript javascript-library markdown markdown-to-html parser

Last synced: 2 days ago
JSON representation

Markdown to HTML parser

Awesome Lists containing this project

README

        

# md2HTML
A lightweight markdown to HTML parser (5 kB standrad, 3 kB .min version).

## Usage
- Download `main.js` or `main.min.js` if you're having to much overhead (weird, but ok).
- Make sure you're using the correct markdown syntax, as shown [here](https://www.markdownguide.org/cheat-sheet/).
- You can use it in two ways:
- Static: by just calling `md2HTML()`, the parser will select all div's with `md2HTML` class, and apply the parsing inside its text content.
- Dynamic: by calling `div.innerHTML = md2HTMLParseElementText(div.textContent)`, the parser will parse the text inside the div text contents you passed as a argument.
- See `demo.html` for a example how the parser works.

## Supports the following markdown elements:
- Headings
- Bold
- Italic
- Code emphasis
- Blockquote
- Ordered list
- Unordered list
- Horizontal rule
- Link
- Image
- Code blocks
- Tables

## Markdown elements and their conversions in HTML:
| Markdown element | HTML conversion |
| :----: | :----: |
| # Heading | `

Heading

` |
| ## Heading | `

Heading ` |
| ### Heading | `

Heading ` |
| #### Heading | `

Heading ` |
| ##### Heading | `

Heading ` |
| ###### Heading | `
Heading ` |
| `**Bold**` | `Bold` |
| `*Italic*` | `Italic` |
| `Code emphasis` (has ` ) | `Code emphasis` |
| `> Quote` | `
Quote
` |
| `***` | `
` |
| `---` | `
` |
| `___` | `
` |
| `[Title](https://link.to.somewhere)` | `Title` |
| `![Alt text](img.png)` | `Alt text` |

## Contributions, issues,...
- Found any issues or want to add other complex/extended markdown syntax? Simply open a issue/PR!