Skip to content

Commit bb015e4

Browse files
farnabazatinux
andauthored
feat: add rangi plugin + rename highlight to shiki (#332)
Co-authored-by: Sébastien Chopin <atinux@gmail.com>
1 parent 08cec83 commit bb015e4

87 files changed

Lines changed: 2571 additions & 672 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,21 @@ packages/comark/
6060
│ │ ├── components.ts # Block/inline components + spans (`::name`, `:name`, `[text]`)
6161
│ │ ├── attributes.ts # Inline attributes (`{props}` after tokens)
6262
│ │ ├── emoji.ts # Emoji shortcodes
63-
│ │ ├── highlight.ts # Syntax highlighting via Shiki (peer: shiki)
63+
│ │ ├── shiki.ts # Syntax highlighting via Shiki (peer: shiki)
64+
│ │ ├── highlight.ts # Deprecated alias → shiki (remove next major)
65+
│ │ ├── rangi.ts # Lightweight highlighting via rangi (peer: rangi)
6466
│ │ ├── math.ts # LaTeX math via KaTeX (peer: katex)
6567
│ │ ├── mermaid.ts # Mermaid diagrams (peer: beautiful-mermaid)
6668
│ │ ├── security.ts # XSS/security sanitization
6769
│ │ ├── summary.ts # Summary extraction
6870
│ │ ├── task-list.ts # GFM task lists
6971
│ │ └── toc.ts # Table of contents
72+
│ ├── utils/ # Shared utilities (comark/utils entry point)
73+
│ │ ├── index.ts # textContent(), visit(), visitAsync(), string/object utils
74+
│ │ ├── helpers.ts # defineComarkPlugin(), dedupePlugins()
75+
│ │ ├── caret.ts # Caret utilities for streaming
76+
│ │ ├── comark.tmLanguage.ts # Comark TextMate grammar (Shiki plugin)
77+
│ │ └── comark.rangiLanguage.ts # Comark rangi grammar (rangi plugin)
7078
│ └── internal/ # Internal implementation (not exported)
7179
│ ├── front-matter.ts
7280
│ ├── parse/ # Parsing pipeline
@@ -80,7 +88,8 @@ packages/comark/
8088

8189
| Peer | Required by |
8290
|------|-------------|
83-
| `shiki` | `comark/plugins/highlight` |
91+
| `shiki` | `comark/plugins/shiki` |
92+
| `rangi` | `comark/plugins/rangi` |
8493
| `katex` | `comark/plugins/math` |
8594
| `beautiful-mermaid` | `comark/plugins/mermaid` |
8695

@@ -104,12 +113,12 @@ Located at `packages/comark-html/`. Framework-free HTML string rendering.
104113

105114
```typescript
106115
import { createHtmlRenderer, renderHtml, renderHtmlFromDocument } from '@comark/html'
107-
import highlight from '@comark/html/plugins/highlight'
116+
import shiki from '@comark/html/plugins/shiki'
108117
import math, { Math } from '@comark/html/plugins/math'
109118

110119
// Flat options — ParserOptions & RendererOptions merged at top level
111120
const renderHtml = createHtmlRenderer({
112-
plugins: [highlight({ themes: { light: 'github-light', dark: 'github-dark' } })],
121+
plugins: [shiki({ themes: { light: 'github-light', dark: 'github-dark' } })],
113122
components: {
114123
Math,
115124
alert: async ([, attrs, ...children], { render }) =>
@@ -140,12 +149,12 @@ Located at `packages/comark-ansi/`. ANSI terminal renderer.
140149

141150
```typescript
142151
import { createAnsiRenderer, createAnsiWriter, renderAnsi, renderAnsiFromDocument, writeAnsi } from '@comark/ansi'
143-
import highlight from '@comark/ansi/plugins/highlight'
152+
import shiki from '@comark/ansi/plugins/shiki'
144153
import math, { Math } from '@comark/ansi/plugins/math'
145154

146155
// Flat options — ParserOptions & AnsiRendererOptions merged at top level
147156
const writeAnsi = createAnsiWriter({
148-
plugins: [highlight(), math()],
157+
plugins: [shiki(), math()],
149158
components: { Math },
150159
width: 120, // terminal width
151160
colors: true, // emit ANSI escape codes
@@ -379,7 +388,9 @@ import type { MarkdownDocument, Node, ElementNode, TextNode } from 'comark'
379388
import { textContent, visit } from 'comark/utils'
380389

381390
// Core plugins — use when calling parseMarkdown() directly (framework-agnostic)
382-
import highlight from 'comark/plugins/highlight'
391+
import shiki from 'comark/plugins/shiki'
392+
import rangi, { comarkLanguage, comarkLanguages } from 'comark/plugins/rangi'
393+
// import highlight from 'comark/plugins/highlight' // deprecated alias → shiki
383394
import math from 'comark/plugins/math'
384395
import mermaid from 'comark/plugins/mermaid'
385396
import emoji from 'comark/plugins/emoji'
@@ -396,18 +407,18 @@ import { markdownItAttributes } from 'comark/plugins/attributes'
396407

397408
// NOTE: All framework packages re-export every core plugin via their own subpath.
398409
// Prefer the framework-specific path when using a framework renderer:
399-
// @comark/vue/plugins/highlight, @comark/react/plugins/highlight, etc.
410+
// @comark/vue/plugins/shiki, @comark/react/plugins/shiki, etc.
400411
// Use comark/plugins/* only when calling parseMarkdown() without a framework renderer.
401412

402413
// HTML rendering — parse + render to HTML string
403414
import { createHtmlRenderer, renderHtml, renderHtmlFromDocument } from '@comark/html'
404-
import highlight from '@comark/html/plugins/highlight'
415+
import shiki from '@comark/html/plugins/shiki'
405416
import math, { Math } from '@comark/html/plugins/math'
406417
import mermaid, { Mermaid } from '@comark/html/plugins/mermaid'
407418

408419
// ANSI terminal rendering — parse + render to styled terminal string
409420
import { createAnsiRenderer, createAnsiWriter, renderAnsi, renderAnsiFromDocument, writeAnsi } from '@comark/ansi'
410-
import highlight from '@comark/ansi/plugins/highlight'
421+
import shiki from '@comark/ansi/plugins/shiki'
411422
import math from '@comark/ansi/plugins/math'
412423

413424
// Vue — renderer + plugin wrappers (plugin fn + Vue component)

benchmarks/plugin-highlight.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MarkdownExit from 'markdown-exit'
44
import { markdownItComponents } from 'comark/plugins/components'
55
import { markdownItAttributes } from 'comark/plugins/attributes'
66
import { createMarkdownParser } from 'comark'
7-
import highlight, { getHighlighter } from '../packages/comark/src/plugins/highlight'
7+
import shiki, { getHighlighter } from '../packages/comark/src/plugins/shiki'
88
import { codeToHast } from 'shiki/core'
99

1010
const short = `
@@ -40,7 +40,7 @@ interface ParserOptions {
4040
4141
const tree = await parseMarkdown(markdown, {
4242
autoClose: true,
43-
plugins: [highlight()],
43+
plugins: [shiki()],
4444
})
4545
\`\`\`
4646
@@ -49,12 +49,12 @@ const tree = await parseMarkdown(markdown, {
4949
\`\`\`vue
5050
<script setup>
5151
import { Markdown } from '@comark/vue'
52-
import highlight from '@comark/vue/plugins/highlight'
52+
import shiki from '@comark/vue/plugins/shiki'
5353
</script>
5454
5555
<template>
5656
<Suspense>
57-
<Markdown :plugins="[highlight()]">{{ content }}</Markdown>
57+
<Markdown :plugins="[shiki()]">{{ content }}</Markdown>
5858
</Suspense>
5959
</template>
6060
\`\`\`
@@ -103,12 +103,12 @@ const markdownExit = new MarkdownExit({ html: true, linkify: true })
103103

104104
// comark: baseline vs highlight plugin
105105
const comark = createMarkdownParser()
106-
const comarkHl = createMarkdownParser({ plugins: [highlight()] })
106+
const comarkHl = createMarkdownParser({ plugins: [shiki()] })
107107

108108
// Pre-warm shiki so we benchmark steady-state, not cold-start
109109
const shiki = await getHighlighter()
110110

111-
// Warm up comark highlight to ensure shiki languages are loaded
111+
// Warm up comark shiki to ensure shiki languages are loaded
112112
await comarkHl(medium)
113113

114114
// Helper: extract fence tokens from markdown-it/exit and highlight them with shiki

docs/app/app.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export default defineAppConfig({
104104
title: 'Plugins',
105105
links: [
106106
{
107-
label: 'Syntax Highlighting',
108-
to: '/plugins/built-in/syntax-highlight',
107+
label: 'Shiki',
108+
to: '/plugins/built-in/shiki',
109109
},
110110
{
111111
label: 'Math',

docs/app/components/ComarkDocs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import math, { Math } from '@comark/nuxt/plugins/math'
33
import mermaid, { Mermaid } from '@comark/nuxt/plugins/mermaid'
44
import emoji from '@comark/nuxt/plugins/emoji'
55
import ProsePre from './landing/ProsePre.vue'
6-
import highlight from 'comark/plugins/highlight'
6+
import shiki from 'comark/plugins/shiki'
77
import Python from '@shikijs/langs/python'
88
import githubLight from '@shikijs/themes/github-light'
99
import githubDark from '@shikijs/themes/github-dark'
@@ -27,7 +27,7 @@ export default defineMarkdownComponent({
2727
extends: BaseComarkDocs,
2828
name: 'ComarkDocs',
2929
plugins: [
30-
highlight({
30+
shiki({
3131
languages: [Python],
3232
themes: {
3333
light: githubLight,

docs/app/components/Playground.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { parseMarkdown } from 'comark'
3-
import highlight from '@comark/nuxt/plugins/highlight'
3+
import shiki from '@comark/nuxt/plugins/shiki'
44
import math from '@comark/nuxt/plugins/math'
55
import binding from '@comark/nuxt/plugins/binding'
66
import emoji from '@comark/nuxt/plugins/emoji'

docs/app/composables/useMDCStream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { MarkdownDocument, ParserOptions } from 'comark'
22
import { readonly, ref, shallowRef } from 'vue'
33
import { parseMarkdown } from 'comark'
4-
import highlight from 'comark/plugins/highlight'
4+
import shiki from 'comark/plugins/shiki'
55

66
export interface MDCStreamState {
77
tree: MarkdownDocument
@@ -16,7 +16,7 @@ export interface MDCStreamOptions extends ParserOptions {
1616
onError?: (error: Error) => void
1717
}
1818

19-
const plugins = [highlight()]
19+
const plugins = [shiki()]
2020

2121
/**
2222
* Vue composable for streaming Comark content parsing

docs/app/pages/play/[...slug].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useCompletion } from '@ai-sdk/vue'
55
import { createMarkdownParser } from 'comark'
66
import jsonRenderer from '@comark/nuxt/plugins/json-render'
77
import binding from '@comark/nuxt/plugins/binding'
8-
import highlight from '@comark/nuxt/plugins/highlight'
8+
import shiki from '@comark/nuxt/plugins/shiki'
99
import math from '@comark/nuxt/plugins/math'
1010
import emoji from '@comark/nuxt/plugins/emoji'
1111
import mermaid from '@comark/nuxt/plugins/mermaid'

docs/app/pages/test.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import highlight from 'comark/plugins/highlight'
2+
import shiki from 'comark/plugins/shiki'
33
import resolveComponent from '../utils/components-manifest'
44
55
useHead({
@@ -191,7 +191,7 @@ Thanks for trying the **Comark test page**! 🚀
191191
<UContainer>
192192
<Markdown
193193
:components-manifest="resolveComponent"
194-
:plugins="[highlight()]"
194+
:plugins="[shiki()]"
195195
>
196196
{{ markdown }}
197197
</Markdown>

docs/content/1.getting-started/0.introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ For detailed, honest comparisons, see [Comark vs MDX](/compare/comark-vs-mdx), [
207207
First-class support for Vue, React, Svelte, and Angular with dedicated renderers.
208208
::
209209

210-
::card{icon="i-lucide-palette" title="Syntax Highlighting" to="/plugins/built-in/syntax-highlight"}
210+
::card{icon="i-lucide-palette" title="Syntax Highlighting" to="/plugins/built-in/shiki"}
211211
Built-in Shiki integration for beautiful code blocks with theme support.
212212
::
213213

docs/content/1.getting-started/1.installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const document = await parseMarkdown(source)
224224
const output = await renderMarkdown(document)
225225

226226
// Reusable parser: initializes plugins once, faster for batch processing
227-
const parseDoc = createMarkdownParser({ plugins: [highlight(), toc()] })
227+
const parseDoc = createMarkdownParser({ plugins: [shiki(), toc()] })
228228
```
229229

230230
See the [Parse API](/api/parse) and [Render API](/api/render) for full options.

0 commit comments

Comments
 (0)