@ritedown/core 0.0.0-stage → 2.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 duichuai (https://duichuai.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ import { type Pluggable } from 'unified';
2
+ import remarkGfm from 'remark-gfm';
3
+ import type { Root } from 'mdast';
4
+ export type { Root } from 'mdast';
5
+ export type { Pluggable } from 'unified';
6
+ /**
7
+ * Syntax extensions available to the pipeline.
8
+ * Ritedown core ships with zero extensions enabled by default —
9
+ * callers opt in explicitly (see `builtin`).
10
+ */
11
+ export interface RitedownOptions {
12
+ /** remark/rehype plugins to extend the pipeline */
13
+ extensions?: Pluggable[];
14
+ }
15
+ /** Built-in extension registry (GFM: tables, task lists, strikethrough, autolinks, footnotes, alerts) */
16
+ export declare const builtin: {
17
+ readonly gfm: typeof remarkGfm;
18
+ };
19
+ /**
20
+ * Descriptor for a Ritedown plugin: a named bundle of remark/rehype
21
+ * extensions plus optional editor-side hooks.
22
+ */
23
+ export interface RitedownPlugin {
24
+ /** stable identifier used for enable/disable persistence */
25
+ id: string;
26
+ /** display name (i18n keys or literal text) */
27
+ name: string;
28
+ /** short description shown in the settings panel */
29
+ description?: string;
30
+ /** remark (or array-form) plugin injected into the pipeline */
31
+ remark?: Pluggable;
32
+ /** rehype plugin injected after remarkRehype */
33
+ rehype?: Pluggable;
34
+ /** enabled when the user has never toggled it (default true) */
35
+ defaultEnabled?: boolean;
36
+ /**
37
+ * CodeMirror extension factory for editor-side syntax support.
38
+ * Typed `unknown` so core keeps zero editor dependencies; callers
39
+ * narrow the result to their own Extension type.
40
+ */
41
+ editorExtension?: () => unknown;
42
+ }
43
+ /**
44
+ * Plugins bundled with core, in canonical declaration order.
45
+ * Order matters: callers must preserve it when assembling pipelines.
46
+ */
47
+ export declare const builtinPlugins: RitedownPlugin[];
48
+ /** Parse markdown into an mdast tree (CommonMark 0.31.2 + enabled extensions;
49
+ * transformer-phase plugins like gemoji run too). */
50
+ export declare function parse(markdown: string, options?: RitedownOptions): Root;
51
+ /** Render markdown to HTML (CommonMark 0.31.2 + enabled extensions). */
52
+ export declare function render(markdown: string, options?: RitedownOptions): string;
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { unified } from 'unified';
2
+ import remarkParse from 'remark-parse';
3
+ import remarkGfm from 'remark-gfm';
4
+ import remarkRehype from 'remark-rehype';
5
+ import rehypeStringify from 'rehype-stringify';
6
+ import remarkGfmAlerts from '@ritedown/gfm-alerts';
7
+ /** Built-in extension registry (GFM: tables, task lists, strikethrough, autolinks, footnotes, alerts) */
8
+ export const builtin = {
9
+ gfm: remarkGfm,
10
+ };
11
+ /**
12
+ * Plugins bundled with core, in canonical declaration order.
13
+ * Order matters: callers must preserve it when assembling pipelines.
14
+ */
15
+ export const builtinPlugins = [
16
+ {
17
+ id: 'gfm',
18
+ name: 'GFM',
19
+ description: 'Tables, task lists, strikethrough, autolinks, footnotes',
20
+ remark: builtin.gfm,
21
+ defaultEnabled: true,
22
+ },
23
+ {
24
+ id: 'gfmAlerts',
25
+ name: 'GFM Alerts',
26
+ description: '> [!NOTE] / [!TIP] / [!IMPORTANT] / [!WARNING] / [!CAUTION] blocks',
27
+ remark: remarkGfmAlerts,
28
+ defaultEnabled: true,
29
+ },
30
+ ];
31
+ function createProcessor(options = {}) {
32
+ return unified()
33
+ .use(remarkParse)
34
+ .use(options.extensions ?? [])
35
+ .use(remarkRehype)
36
+ .use(rehypeStringify);
37
+ }
38
+ /** remark-only pipeline (no rehype): used by parse() to stay in mdast */
39
+ function createParser(options = {}) {
40
+ return unified().use(remarkParse).use(options.extensions ?? []);
41
+ }
42
+ /** Parse markdown into an mdast tree (CommonMark 0.31.2 + enabled extensions;
43
+ * transformer-phase plugins like gemoji run too). */
44
+ export function parse(markdown, options) {
45
+ const processor = createParser(options);
46
+ return processor.runSync(processor.parse(markdown));
47
+ }
48
+ /** Render markdown to HTML (CommonMark 0.31.2 + enabled extensions). */
49
+ export function render(markdown, options) {
50
+ return String(createProcessor(options).processSync(markdown));
51
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@ritedown/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.1.0-beta.0",
4
+ "description": "Ritedown kernel: Markdown parse & render pipeline (CommonMark 0.31.2 based, pluggable extensions)",
5
+ "license": "MIT",
6
+ "author": "duichuai",
7
+ "homepage": "https://duichuai.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/duichuai/ritedown.git",
11
+ "directory": "packages/core"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/duichuai/ritedown/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "publishConfig": {
29
+ "registry": "https://registry.npmjs.org/",
30
+ "access": "public"
31
+ },
32
+ "dependencies": {
33
+ "remark-gfm": "^4.0.0",
34
+ "remark-parse": "^11.0.0",
35
+ "remark-rehype": "^11.1.0",
36
+ "rehype-stringify": "^10.0.1",
37
+ "unified": "^11.0.5",
38
+ "@ritedown/gfm-alerts": "2.1.0-beta.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^20.0.0",
42
+ "tsx": "^4.19.0",
43
+ "typescript": "^5.6.0",
44
+ "vitest": "^3.0.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.json",
48
+ "test": "vitest run",
49
+ "demo": "tsx src/demo.ts"
50
+ }
6
51
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.