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
14 changes: 14 additions & 0 deletions docs/guide/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,17 @@ md.linkify = new LinkifyIt()
> [!WARNING]
> - Plugins that access `md.linkify` (e.g. `md.linkify.set(...)`) throw in the core entry unless you assign a linkify-it instance before calling `md.use()`.
> - If any module in your app imports `markdown-exit` instead of `markdown-exit/core`, linkify-it is bundled anyway, and instances created from `markdown-exit/core` get a linkify-it instance too.

## Parser Entry

`markdown-exit/parser` exports `Parser` and `Token` without the renderer and presets, for apps that only need tokens. `Parser` parses with the same rules as the default preset and leaves out linkify-it like the core entry, but has no `use()`, `set()`, `configure()` or `render()`. Change its options and rules directly:

```ts
import { Parser } from 'markdown-exit/parser'

const parser = new Parser()
parser.options.html = true
parser.block.ruler.disable('table')

const tokens = parser.parse('# Hello')
```
1 change: 1 addition & 0 deletions packages/markdown-exit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"exports": {
".": "./dist/index.js",
"./core": "./dist/core.js",
"./parser": "./dist/parser.js",
"./package.json": "./package.json"
},
"main": "./dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/markdown-exit/src/index.parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './parser'
export * from './token'
25 changes: 23 additions & 2 deletions packages/markdown-exit/tests/core-entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { LinkifyIt } from 'linkify-it'
import { build } from 'vite'
import { assert, describe, it } from 'vitest'
import MarkdownExit from '../src/index.core'
import { Parser } from '../src/index.parser'

async function bundleImports(entry: string): Promise<string[]> {
async function bundle(entry: string): Promise<Rollup.OutputChunk[]> {
const result = await build({
configFile: false,
logLevel: 'silent',
Expand All @@ -15,7 +16,11 @@ async function bundleImports(entry: string): Promise<string[]> {
rollupOptions: { external: id => !id.startsWith('.') && !id.startsWith('/') },
},
}) as Rollup.RollupOutput[]
return result[0].output.flatMap(chunk => chunk.type === 'chunk' ? chunk.imports : [])
return result[0].output.filter(chunk => chunk.type === 'chunk')
}

async function bundleImports(entry: string): Promise<string[]> {
return (await bundle(entry)).flatMap(chunk => chunk.imports)
}

describe('markdown-exit/core', () => {
Expand All @@ -39,3 +44,19 @@ describe('markdown-exit/core', () => {
assert.strictEqual(md.render('https://example.com'), '<p><a href="https://example.com">https://example.com</a></p>\n')
})
})

describe('markdown-exit/parser', () => {
it('bundles neither the renderer nor the presets', async () => {
const modules = (await bundle('../src/index.parser.ts')).flatMap(chunk => chunk.moduleIds)

assert.include(modules.join('\n'), '/src/parser/parser.ts')
assert.notInclude(modules.join('\n'), '/src/renderer.ts')
assert.notInclude(modules.join('\n'), '/src/presets/')
})

it('parses the same tokens as `MarkdownExit`', () => {
const src = '# a\n\n- *b* [c](/d)\n\n| e |\n| - |\n| f |\n\n~~g~~ `h` &copy;\n'

assert.deepEqual(new Parser().parse(src), MarkdownExit().parse(src))
})
})
2 changes: 1 addition & 1 deletion packages/markdown-exit/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'tsdown'

export default defineConfig([
{
entry: { index: './src/index.ts', core: './src/index.core.ts' },
entry: { index: './src/index.ts', core: './src/index.core.ts', parser: './src/index.parser.ts' },
platform: 'neutral',
dts: true,
},
Expand Down
Loading