Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- uses: pnpm/action-setup@v6

- uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- uses: pnpm/action-setup@v6

- uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- uses: pnpm/action-setup@v6

- uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- uses: pnpm/action-setup@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
Expand Down
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

45 changes: 36 additions & 9 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,42 @@ export default defineConfig({
title: 'markdown-exit',
description: 'The Modern Toolkit for Markdown',
head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo-mini.svg' }],
['meta', { name: 'theme-color', content: '#00AF6B' }],
['meta', { property: 'og:title', content: title }],
['meta', { property: 'og:description', content: description }],
['meta', { property: 'og:image', content: ogImage }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:url', content: docsUrl }],
['meta', { property: 'twitter:card', content: 'summary_large_image' }],
['meta', { property: 'twitter:image', content: ogImage }],
[
'link',
{ rel: 'icon', type: 'image/svg+xml', href: '/logo-mini.svg' },
],
[
'meta',
{ name: 'theme-color', content: '#00AF6B' },
],
[
'meta',
{ property: 'og:title', content: title },
],
[
'meta',
{ property: 'og:description', content: description },
],
[
'meta',
{ property: 'og:image', content: ogImage },
],
[
'meta',
{ property: 'og:type', content: 'website' },
],
[
'meta',
{ property: 'og:url', content: docsUrl },
],
[
'meta',
{ property: 'twitter:card', content: 'summary_large_image' },
],
[
'meta',
{ property: 'twitter:image', content: ogImage },
],
],
markdown: {
theme: { light: 'github-light', dark: 'vitesse-dark' },
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

It is a TypeScript rewrite of [markdown-it](https://github.com/markdown-it/markdown-it), designed as a drop-in replacement with thoughtful enhancements.

### Differences from markdown-it
## Differences from markdown-it

- TypeScript-first design
- Supports [async rendering](/guide/rendering.html#async-rendering)
Expand All @@ -13,7 +13,7 @@ It is a TypeScript rewrite of [markdown-it](https://github.com/markdown-it/markd
- Better performance (see [benchmarks](https://codspeed.io/serkodev/markdown-exit/benchmarks))
- Bug fixes and [additional features](https://github.com/serkodev/markdown-exit/issues?q=is:issue%20label:features)

#### Why a separate codebase from markdown-it?
### Why a separate codebase from markdown-it?

TypeScript offers better type safety and a superior development experience. It also makes the code easier to read and maintain.

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/migrate-from-markdown-it.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ After [installing](/guide/quick-start.html#installation) **markdown-exit**, simp
+ import MarkdownExit from 'markdown-exit'
```

#### Named Import
### Named Import

markdown-it uses [default imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#default_import) by default. While **markdown-exit** is compatible with this approach, it’s recommended to use [named import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#named_import) instead, as they are more tree-shaking friendly.

Expand Down
6 changes: 3 additions & 3 deletions docs/guide/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**markdown-exit** compatible with **markdown-it** render API and supports [async rendering](#async-rendering) out of the box.

### Basic Usage
## Basic Usage

```ts
import { createMarkdownExit } from 'markdown-exit'
Expand All @@ -11,15 +11,15 @@ const md = createMarkdownExit()
const html = md.render('# Hello World')
```

### Inline Rendering
## Inline Rendering

Render inline markdown content without paragraph wrapping.

```ts
const html = md.renderInline('**markdown-exit** is awesome!')
```

### Syntax Highlighting
## Syntax Highlighting

You can provide a custom syntax highlighter function via the [`highlight`](/reference/api/Interface.MarkdownExitOptions.html#highlight) option.

Expand Down
6 changes: 5 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export default antfu(
'no-console': 'warn',
'no-alert': 'warn',
'curly': 'off',
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'style/brace-style': [
'error',
'1tbs',
{ allowSingleLine: true },
],
'unused-imports/no-unused-vars': 'warn',
'style/operator-linebreak': 'off',
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "1.3.0",
"private": true,
"packageManager": "pnpm@10.26.2",
"packageManager": "pnpm@12.16.1",
"license": "MIT",
"scripts": {
"dev": "pnpm -F markdown-exit run dev",
Expand All @@ -22,6 +22,7 @@
"@antfu/eslint-config": "catalog:",
"@codspeed/vitest-plugin": "catalog:tests",
"@types/node": "catalog:types",
"@typescript/native": "catalog:",
"bumpp": "catalog:",
"eslint": "catalog:",
"shiki": "catalog:tests",
Expand Down
21 changes: 12 additions & 9 deletions packages/bench/compare.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, describe } from 'vitest'
import { it } from 'vitest'
import { createRunners } from './runners'

const fixtures = import.meta.glob<string>('./samples/*', { query: '?raw', import: 'default', eager: true })
Expand All @@ -7,13 +7,16 @@ const contents = Object.values(fixtures)
const runners = createRunners()

for (const [category, runnerGroup] of Object.entries(runners)) {
describe(`category: ${category}`, () => {
for (const [name, runner] of Object.entries(runnerGroup)) {
bench(name, () => {
for (const content of contents) {
runner(content)
}
}, { time: 1000, warmupTime: 200 })
}
it(`category: ${category}`, async ({ bench: b }) => {
await b.compare(
...Object.entries(runnerGroup).map(([name, runner]) =>
b(name, () => {
for (const content of contents) {
runner(content)
}
}),
),
{ time: 1000, warmupTime: 200 },
)
})
}
1 change: 0 additions & 1 deletion packages/markdown-exit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"prepublishOnly": "pnpm build"
},
"dependencies": {
"@types/linkify-it": "catalog:types",
"@types/mdurl": "catalog:types",
"entities": "catalog:integrations",
"linkify-it": "catalog:integrations",
Expand Down
61 changes: 53 additions & 8 deletions packages/markdown-exit/src/parser/block/parser_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,58 @@ export type RuleBlock = (state: StateBlock, startLine: number, endLine: number,
const _rules = [
// First 2 params - rule name & source. Secondary array - list of rules,
// which can be terminated by this one.
['table', r_table, ['paragraph', 'reference']],
[
'table',
r_table,
['paragraph', 'reference'],
],
['code', r_code],
['fence', r_fence, ['paragraph', 'reference', 'blockquote', 'list']],
['blockquote', r_blockquote, ['paragraph', 'reference', 'blockquote', 'list']],
['hr', r_hr, ['paragraph', 'reference', 'blockquote', 'list']],
['list', r_list, ['paragraph', 'reference', 'blockquote']],
[
'fence',
r_fence,
[
'paragraph',
'reference',
'blockquote',
'list',
],
],
[
'blockquote',
r_blockquote,
[
'paragraph',
'reference',
'blockquote',
'list',
],
],
[
'hr',
r_hr,
[
'paragraph',
'reference',
'blockquote',
'list',
],
],
[
'list',
r_list,
['paragraph', 'reference', 'blockquote'],
],
['reference', r_reference],
['html_block', r_html_block, ['paragraph', 'reference', 'blockquote']],
['heading', r_heading, ['paragraph', 'reference', 'blockquote']],
[
'html_block',
r_html_block,
['paragraph', 'reference', 'blockquote'],
],
[
'heading',
r_heading,
['paragraph', 'reference', 'blockquote'],
],
['lheading', r_lheading],
['paragraph', r_paragraph],
] as const satisfies [string, RuleBlock, string[]?][]
Expand All @@ -53,7 +96,9 @@ export default class ParserBlock<T extends Parser = Parser> {
this.ruler = new Ruler()

for (let i = 0; i < _rules.length; i++) {
this.ruler.push(_rules[i][0], _rules[i][1], { alt: (_rules[i][2] || []).slice() })
this.ruler.push(_rules[i][0], _rules[i][1], {
alt: (_rules[i][2] || []).slice(),
})
}
}

Expand Down
12 changes: 10 additions & 2 deletions packages/markdown-exit/src/parser/block/rules/html_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ const HTML_SEQUENCES: [RegExp, RegExp, boolean][] = [
[/^<\?/, /\?>/, true],
[/^<![A-Z]/, />/, true],
[/^<!\[CDATA\[/, /\]\]>/, true],
[new RegExp(`^</?(${block_names.join('|')})(?=(\\s|/?>|$))`, 'i'), /^$/, true],
[new RegExp(`${HTML_OPEN_CLOSE_TAG_RE.source}\\s*$`), /^$/, false],
[
new RegExp(`^</?(${block_names.join('|')})(?=(\\s|/?>|$))`, 'i'),
/^$/,
true,
],
[
new RegExp(`${HTML_OPEN_CLOSE_TAG_RE.source}\\s*$`),
/^$/,
false,
],
]

export default function html_block(state: StateBlock, startLine: number, endLine: number, silent: boolean) {
Expand Down
4 changes: 3 additions & 1 deletion packages/markdown-exit/src/parser/block/rules/lheading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export default function lheading(state: StateBlock, startLine: number, endLine:
pos = state.skipSpaces(pos)

if (pos >= max) {
level = (marker === 0x3D/* = */ ? 1 : 2)
level = (marker === 0x3D/* = */
? 1
: 2)
break
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/markdown-exit/src/parser/block/rules/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ export default function list(state: StateBlock, startLine: number, endLine: numb
token = state.push('ordered_list_open', 'ol', 1)
if (markerValue !== 1) {
// markdown-exit notes: convert markerValue to string
token.attrs = [['start', markerValue!.toString()]]
token.attrs = [
[
'start',
markerValue!.toString(),
],
]
}
} else {
token = state.push('bullet_list_open', 'ul', 1)
Expand Down
16 changes: 12 additions & 4 deletions packages/markdown-exit/src/parser/block/rules/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export default function table(state: StateBlock, startLine: number, endLine: num
if (!/^:?-+:?$/.test(t))
return false
if (t.charCodeAt(t.length - 1) === 0x3A/* : */) {
aligns.push(t.charCodeAt(0) === 0x3A/* : */ ? 'center' : 'right')
aligns.push(t.charCodeAt(0) === 0x3A/* : */
? 'center'
: 'right')
} else if (t.charCodeAt(0) === 0x3A/* : */) {
aligns.push('left')
} else {
Expand Down Expand Up @@ -168,7 +170,9 @@ export default function table(state: StateBlock, startLine: number, endLine: num
for (let i = 0; i < columns.length; i++) {
const token_ho = state.push('th_open', 'th', 1)
if (aligns[i]) {
token_ho.attrs = [['style', `text-align:${aligns[i]}`]]
token_ho.attrs = [
['style', `text-align:${aligns[i]}`],
]
}

const token_il = state.push('inline', '', 0)
Expand Down Expand Up @@ -226,11 +230,15 @@ export default function table(state: StateBlock, startLine: number, endLine: num
for (let i = 0; i < columnCount; i++) {
const token_tdo = state.push('td_open', 'td', 1)
if (aligns[i]) {
token_tdo.attrs = [['style', `text-align:${aligns[i]}`]]
token_tdo.attrs = [
['style', `text-align:${aligns[i]}`],
]
}

const token_il = state.push('inline', '', 0)
token_il.content = columns[i] ? columns[i].trim() : ''
token_il.content = columns[i]
? columns[i].trim()
: ''
token_il.children = []

state.push('td_close', 'td', -1)
Expand Down
8 changes: 6 additions & 2 deletions packages/markdown-exit/src/parser/block/state_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export default class StateBlock<T extends Parser = Parser> {

for (let start = 0; start < len;) {
const lineEnd = s.indexOf('\n', start)
const end = lineEnd === -1 ? len : lineEnd
const end = lineEnd === -1
? len
: lineEnd
let indent = 0
let offset = 0
let pos = start
Expand All @@ -120,7 +122,9 @@ export default class StateBlock<T extends Parser = Parser> {
const ch = s.charCodeAt(pos)
if (isSpace(ch)) {
indent++
offset += (ch === 0x09) ? (4 - offset % 4) : 1
offset += (ch === 0x09)
? (4 - offset % 4)
: 1
pos++
continue
}
Expand Down
Loading