@manufosela/rich-markdown-to-html
Markdown to HTML converter with support for tables, code blocks, and task lists
Demo code (CodePen-ready HTML, CSS, JS)
HTML (html)
<div class="topbar">
<demo-theme-toggle></demo-theme-toggle>
<div class="topbar-links">
<a href="https://manufosela.dev/utils/">Utils catalog</a>
<a href="https://manufosela.dev/">Main catalog</a>
<a href="https://github.com/manufosela/utils/tree/main/packages/rich-markdown-to-html">Source</a>
<span style="margin-left: auto; font-size: 0.85rem; color: #9ca3af;">Live markdown playground</span>
</div>
<div class="code-block">import { parse } from '@manufosela/rich-markdown-to-html';
const html = parse(markdown, { linkify: true, taskLists: true });
</div>
</div>
<div class="container">
<div class="panel">
<div class="panel-header">Markdown Input</div>
<div class="options">
<label><input type="checkbox" id="breaks"> Line Breaks</label>
<label><input type="checkbox" id="linkify" checked> Auto-link URLs</label>
<label><input type="checkbox" id="taskLists" checked> Task Lists</label>
<label><input type="checkbox" id="tables" checked> Tables</label>
<label><input type="checkbox" id="typographer"> Typographer</label>
<label><input type="checkbox" id="showToc"> Show TOC</label>
</div>
<div class="panel-content">
<textarea id="editor"># Welcome to Rich Markdown
This is a **live preview** markdown editor powered by `@manufosela/rich-markdown-to-html`.
## Features
### Text Formatting
You can use **bold**, *italic*, and ~~strikethrough~~ text.
### Code
Inline code: `const x = 1;`
Code blocks with syntax highlighting:
```javascript
function greet(name) {
console.log(`Hello, ${name}!`);
}
```
### Lists
Unordered list:
- Item one
- Item two
- Item three
Ordered list:
1. First item
2. Second item
3. Third item
### Task Lists
- [x] Completed task
- [ ] Incomplete task
- [x] Another done task
### Blockquotes
> This is a blockquote.
> It can span multiple lines.
### Tables
| Feature | Status | Notes |
|:--------|:------:|------:|
| Tables | Done | Aligned! |
| Lists | Done | Task lists too |
| Code | Done | With highlighting |
### Links and Images
Visit [Google](https://google.com "Search Engine") for more info.
Auto-linked URL: https://example.com
---
## Try It!
Edit this text and see the live preview update instantly.
</textarea>
</div>
</div>
<div class="panel">
<div class="panel-header">HTML Preview</div>
<div class="panel-content" id="preview"></div>
</div>
</div> CSS (css)
:root {
--bg: #0c0f14;
--bg-elevated: #141923;
--bg-panel: #171d28;
--border: #262f3f;
--text: #f4f6fb;
--text-muted: #a7b0c2;
--text-dim: #7d879b;
--accent: #ff8a3d;
--accent-strong: #ff6a00;
--accent-soft: rgba(255, 138, 61, 0.16);
--shadow: 0 20px 50px rgba(5, 8, 14, 0.45);
--radius-lg: 22px;
--radius-md: 14px;
--radius-sm: 10px;
--max-width: 1160px;
}
* {
box-sizing: border-box;
}
.topbar {
display: grid;
gap: 0.75rem;
padding: 0.75rem 1rem;
background: var(--bg-panel);
color: var(--text);
align-items: center;
}
.topbar-links {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
align-items: center;
}
.topbar a {
font-size: 0.8rem;
color: var(--text-muted);
text-decoration: none;
border: 1px solid var(--border);
padding: 0.35rem 0.75rem;
border-radius: 999px;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr;
height: calc(100vh - 110px);
}
.code-block {
background: #0b0f1a;
border: 1px solid #2b3247;
border-radius: 8px;
padding: 10px 12px;
color: #d6d9e6;
font-family: "JetBrains Mono", "Courier New", monospace;
font-size: 0.8rem;
white-space: pre-wrap;
word-break: break-word;
}
.panel {
display: flex;
flex-direction: column;
height: 100%;
}
.panel-header {
padding: 1rem;
background: var(--accent);
color: #111;
font-weight: 600;
}
.panel-content {
flex: 1;
overflow: auto;
}
#editor {
width: 100%;
height: 100%;
padding: 1rem;
border: none;
resize: none;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 14px;
line-height: 1.5;
}
#preview {
padding: 1rem 2rem;
background: var(--bg-elevated);
}
/* Preview Styles */
#preview h1, #preview h2, #preview h3,
#preview h4, #preview h5, #preview h6 {
margin-top: 1.5em;
margin-bottom: 0.5em;
color: var(--text);
}
#preview h1 { font-size: 2rem; border-bottom: 2px solid var(--border); padding-bottom: 0.3em; }
#preview h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
#preview h3 { font-size: 1.25rem; }
#preview p {
line-height: 1.6;
color: var(--text-muted);
}
#preview a {
color: var(--accent);
text-decoration: none;
}
#preview a:hover {
text-decoration: underline;
}
#preview code {
background: var(--code-bg);
color: var(--code-text);
padding: 0.2em 0.4em;
border-radius: 3px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 0.9em;
}
#preview pre {
background: var(--code-bg);
color: var(--code-text);
padding: 1rem;
border-radius: 6px;
overflow-x: auto;
}
#preview pre code {
background: transparent;
padding: 0;
color: inherit;
}
#preview blockquote {
border-left: 4px solid var(--accent);
margin: 1em 0;
padding: 0.5em 1em;
background: var(--bg-panel);
color: var(--text-muted);
}
#preview ul, #preview ol {
padding-left: 2em;
line-height: 1.8;
}
#preview .task-list {
list-style: none;
padding-left: 0;
}
#preview .task-list-item {
display: flex;
align-items: center;
gap: 0.5em;
}
#preview .task-list-item input {
margin: 0;
}
#preview table {
border-collapse: collapse;
width: 100%;
margin: 1em 0;
}
#preview th, #preview td {
border: 1px solid var(--border);
padding: 0.75em;
}
#preview th {
background: var(--bg-panel);
font-weight: 600;
}
#preview tr:nth-child(even) {
background: var(--bg-2);
}
#preview hr {
border: none;
border-top: 2px solid var(--border);
margin: 2em 0;
}
#preview img {
max-width: 100%;
height: auto;
}
.options {
padding: 0.5rem 1rem;
background: var(--bg-panel);
display: flex;
gap: 1rem;
flex-wrap: wrap;
font-size: 0.875rem;
}
.options label {
display: flex;
align-items: center;
gap: 0.25rem;
cursor: pointer;
color: var(--text);
}
.options input {
accent-color: var(--accent);
}
.toc {
background: var(--bg-panel);
padding: 1rem;
border-radius: 4px;
margin-bottom: 1rem;
}
.toc ul {
list-style: none;
padding-left: 1em;
margin: 0;
}
.toc > ul {
padding-left: 0;
}
.toc a {
color: var(--text-muted);
}
.toc-title {
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--text);
}
:root {
--bg: #0f1117;
--bg-2: #151a26;
--bg-spot-1: #1a2136;
--bg-spot-2: #1d1b34;
--card: #1c2233;
--text: #f3f6ff;
--muted: #b8c0d9;
--line: #2b3247;
--accent: #ffb000;
--accent-2: #00d0ff;
--surface: #0b0f1a;
--code-bg: #0b0f1a;
--code-text: #d6d9e6;
}
:root.light {
--bg: #f5f5f7;
--bg-2: #ffffff;
--bg-spot-1: #f8e9d0;
--bg-spot-2: #e8eef8;
--card: #ffffff;
--text: #1d1d1f;
--muted: #6b7280;
--line: #e5e7eb;
--accent: #ffb000;
--accent-2: #00a7d6;
--surface: #f3f4f6;
--code-bg: #111827;
--code-text: #f9fafb;
}
:root.dark {
--bg: #0f1117;
--bg-2: #151a26;
--bg-spot-1: #1a2136;
--bg-spot-2: #1d1b34;
--card: #1c2233;
--text: #f3f6ff;
--muted: #b8c0d9;
--line: #2b3247;
--accent: #ffb000;
--accent-2: #00d0ff;
--surface: #0b0f1a;
--code-bg: #0b0f1a;
--code-text: #d6d9e6;
}
h1 {
color: var(--accent) !important;
}
.top-links a,
.topbar a {
color: var(--muted) !important;
border-color: var(--line) !important;
}
.top-links a:hover,
.topbar a:hover {
color: var(--text) !important;
}
.card,
.section,
.demo-section,
.panel {
background: var(--card) !important;
border-color: var(--line) !important;
color: var(--text) !important;
}
.code-block,
pre,
code,
.output,
.current-url,
.event-log,
.result-card,
.log {
background: var(--code-bg) !important;
color: var(--code-text) !important;
border-color: var(--line) !important;
}
input,
select,
textarea {
background: var(--surface) !important;
color: var(--text) !important;
border-color: var(--line) !important;
}
button {
background: linear-gradient(120deg, var(--accent), #ff6a00) !important;
color: #111 !important;
}
footer {
color: var(--muted) !important;
}
footer a {
color: var(--text) !important;
} JS (js)
import { parse, generateTOC, renderTOC } from "https://esm.sh/@manufosela/rich-markdown-to-html";
const editor = document.getElementById('editor');
const preview = document.getElementById('preview');
const optionBreaks = document.getElementById('breaks');
const optionLinkify = document.getElementById('linkify');
const optionTaskLists = document.getElementById('taskLists');
const optionTables = document.getElementById('tables');
const optionTypographer = document.getElementById('typographer');
const optionShowToc = document.getElementById('showToc');
function updatePreview() {
const options = {
breaks: optionBreaks.checked,
linkify: optionLinkify.checked,
taskLists: optionTaskLists.checked,
tables: optionTables.checked,
typographer: optionTypographer.checked
};
const markdown = editor.value;
let html = '';
if (optionShowToc.checked) {
const toc = generateTOC(markdown, { maxLevel: 3 });
if (toc.length > 0) {
html += '<div class="toc"><div class="toc-title">Table of Contents</div>';
html += renderTOC(toc);
html += '</div>';
}
}
html += parse(markdown, options);
preview.innerHTML = html;
}
// Initial render
updatePreview();
// Update on input
editor.addEventListener('input', updatePreview);
// Update on option change
[optionBreaks, optionLinkify, optionTaskLists, optionTables, optionTypographer, optionShowToc]
.forEach(el => el.addEventListener('change', updatePreview));
class DemoThemeToggle extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.handleClick = this.handleClick.bind(this);
}
connectedCallback() {
const saved = localStorage.getItem('utils-demo-theme');
document.documentElement.classList.remove('dark');
document.documentElement.classList.toggle('light', saved === 'light');
this.render();
}
render() {
const isLight = document.documentElement.classList.contains('light');
this.shadowRoot.innerHTML = `
<style>
:host {
display: inline-flex;
}
.toggle {
display: inline-flex;
align-items: center;
border: 1px solid var(--line);
border-radius: 999px;
overflow: hidden;
background: var(--surface);
}
button {
border: none;
background: transparent;
color: var(--muted);
padding: 6px 12px;
font-size: 0.8rem;
cursor: pointer;
font-family: "Space Grotesk", "Trebuchet MS", Arial, sans-serif;
}
button.active {
background: linear-gradient(120deg, var(--accent), #ff6a00);
color: #111;
font-weight: 600;
}
</style>
<div class="toggle" role="group" aria-label="Theme toggle">
<button class="${isLight ? 'active' : ''}" data-theme="light">Light</button>
<button class="${isLight ? '' : 'active'}" data-theme="dark">Dark</button>
</div>
`;
this.shadowRoot.querySelectorAll('button').forEach((btn) => {
btn.addEventListener('click', this.handleClick);
});
}
handleClick(event) {
const theme = event.currentTarget.dataset.theme;
const isLight = theme === 'light';
document.documentElement.classList.toggle('light', isLight);
document.documentElement.classList.remove('dark');
localStorage.setItem('utils-demo-theme', isLight ? 'light' : 'dark');
this.render();
}
}
customElements.define('demo-theme-toggle', DemoThemeToggle);