Markdown source highlighting
with the CSS Custom Highlight API.
npm install md-inknpm ↗- 0 core runtime dependencies
- ESM + TypeScript
- React · Vue · Svelte
edit me
DOM TEXT CONTAINERsame source · different CSS
Core API + CSS
Full documentation<textarea id="source"># Hello **world**</textarea>
import { createMdInk } from 'md-ink'
const md = createMdInk(document.querySelector('#source'))
// After script value changes: md.update()
// On teardown: md.destroy()HTML + JavaScript
import { useState } from 'react'
import { useMdInk } from 'md-ink/react'
export default function Editor() {
const [source, setSource] = useState('# Hello **world**')
const ref = useMdInk<HTMLTextAreaElement>()
return <textarea ref={ref} value={source}
onChange={e => setSource(e.target.value)} />
}React ≥18 · TSX · updates and cleanup handled by the hook.
<script setup>
import { ref } from 'vue'
import { vMdInk } from 'md-ink/vue'
const source = ref('# Hello **world**')
</script>
<template>
<textarea v-md-ink v-model="source" />
</template>Vue ≥3 · updates and cleanup handled by the directive.
<script>
import { mdInk } from 'md-ink/svelte'
let source = $state('# Hello **world**');
</script>
<textarea use:mdInk={source}
bind:value={source}></textarea>Svelte ≥5 · source is a refresh token; cleanup is automatic.
SHARED CSS · ALL FRAMEWORKS
::highlight(md-ink-heading) { color: #8250df; }
::highlight(md-ink-code) {
color: #116329; background-color: #dcfce7;
}
::highlight(md-ink-marker) { color: #8c959f; }Core: input and DOM changes refresh automatically. Script value changes and form reset need update(); call destroy() on teardown. Recreate after target, Document or input-type changes.
Syntax & browser support
Syntax fixtures- Syntax
- ATX headings, quotes, lists, bold / italic, strike, inline / fenced code and simple links. No tables, images, HTML or full CommonMark support.
- Browsers
- DOM: Chrome / Edge 105+, Firefox 149+, Safari / iOS 17.2+, Opera 91+, Samsung 20+. Firefox 140–148: partial. Can I Use ↗
Textarea / input: Chrome 152+ / Edge 152+ (OpaqueRange). Others stay plain.