@jianwen-lang/parser 0.1.1
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 +21 -0
- package/README.md +95 -0
- package/dist/cli/render.d.ts +1 -0
- package/dist/cli/render.js +300 -0
- package/dist/core/ast.d.ts +286 -0
- package/dist/core/ast.js +2 -0
- package/dist/core/block/rules/heading.d.ts +9 -0
- package/dist/core/block/rules/heading.js +75 -0
- package/dist/core/block/rules/horizontal-rule.d.ts +9 -0
- package/dist/core/block/rules/horizontal-rule.js +87 -0
- package/dist/core/block/rules/include.d.ts +9 -0
- package/dist/core/block/rules/include.js +64 -0
- package/dist/core/block/rules/index.d.ts +2 -0
- package/dist/core/block/rules/index.js +16 -0
- package/dist/core/block/rules/types.d.ts +21 -0
- package/dist/core/block/rules/types.js +2 -0
- package/dist/core/block/types.d.ts +10 -0
- package/dist/core/block/types.js +2 -0
- package/dist/core/block-parser.d.ts +3 -0
- package/dist/core/block-parser.js +1385 -0
- package/dist/core/clone.d.ts +9 -0
- package/dist/core/clone.js +32 -0
- package/dist/core/diagnostics.d.ts +12 -0
- package/dist/core/diagnostics.js +24 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +2 -0
- package/dist/core/inline/rules/backtick.d.ts +4 -0
- package/dist/core/inline/rules/backtick.js +90 -0
- package/dist/core/inline/rules/bracket.d.ts +4 -0
- package/dist/core/inline/rules/bracket.js +721 -0
- package/dist/core/inline/rules/disabled.d.ts +2 -0
- package/dist/core/inline/rules/disabled.js +34 -0
- package/dist/core/inline/rules/escape.d.ts +2 -0
- package/dist/core/inline/rules/escape.js +11 -0
- package/dist/core/inline/rules/index.d.ts +2 -0
- package/dist/core/inline/rules/index.js +25 -0
- package/dist/core/inline/rules/marker-highlight.d.ts +4 -0
- package/dist/core/inline/rules/marker-highlight.js +56 -0
- package/dist/core/inline/rules/style.d.ts +4 -0
- package/dist/core/inline/rules/style.js +120 -0
- package/dist/core/inline/rules/types.d.ts +22 -0
- package/dist/core/inline/rules/types.js +2 -0
- package/dist/core/inline/types.d.ts +1 -0
- package/dist/core/inline/types.js +2 -0
- package/dist/core/inline-parser.d.ts +3 -0
- package/dist/core/inline-parser.js +52 -0
- package/dist/core/location.d.ts +9 -0
- package/dist/core/location.js +30 -0
- package/dist/core/parser.d.ts +9 -0
- package/dist/core/parser.js +423 -0
- package/dist/core/traverse.d.ts +7 -0
- package/dist/core/traverse.js +71 -0
- package/dist/html/convert.d.ts +29 -0
- package/dist/html/convert.js +61 -0
- package/dist/html/format.d.ts +1 -0
- package/dist/html/format.js +17 -0
- package/dist/html/render/blocks.d.ts +4 -0
- package/dist/html/render/blocks.js +433 -0
- package/dist/html/render/html.d.ts +8 -0
- package/dist/html/render/html.js +89 -0
- package/dist/html/render/inlines.d.ts +4 -0
- package/dist/html/render/inlines.js +110 -0
- package/dist/html/render/meta.d.ts +3 -0
- package/dist/html/render/meta.js +51 -0
- package/dist/html/render/utils.d.ts +31 -0
- package/dist/html/render/utils.js +213 -0
- package/dist/html/theme/base/css.d.ts +2 -0
- package/dist/html/theme/base/css.js +383 -0
- package/dist/html/theme/dark/css.d.ts +2 -0
- package/dist/html/theme/dark/css.js +108 -0
- package/dist/html/theme/default/colors.d.ts +13 -0
- package/dist/html/theme/default/colors.js +2 -0
- package/dist/html/theme/default/css.d.ts +2 -0
- package/dist/html/theme/default/css.js +6 -0
- package/dist/html/theme/default/runtime.d.ts +0 -0
- package/dist/html/theme/default/runtime.js +31 -0
- package/dist/html/theme/light/css.d.ts +2 -0
- package/dist/html/theme/light/css.js +55 -0
- package/dist/html/theme/preset/colors.d.ts +10 -0
- package/dist/html/theme/preset/colors.js +14 -0
- package/dist/html/theme/runtime.d.ts +0 -0
- package/dist/html/theme/runtime.js +31 -0
- package/dist/html/theme/theme.d.ts +9 -0
- package/dist/html/theme/theme.js +21 -0
- package/dist/lexer/lexer.d.ts +17 -0
- package/dist/lexer/lexer.js +47 -0
- package/dist/parser.d.ts +6 -0
- package/dist/parser.js +22 -0
- package/package.json +50 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PRESET_COLORS = exports.DEFAULT_CSS = exports.DEFAULT_THEME = void 0;
|
|
7
|
+
const css_1 = __importDefault(require("./base/css"));
|
|
8
|
+
const css_2 = __importDefault(require("./dark/css"));
|
|
9
|
+
const css_3 = __importDefault(require("./light/css"));
|
|
10
|
+
const colors_1 = __importDefault(require("./preset/colors"));
|
|
11
|
+
exports.DEFAULT_THEME = {
|
|
12
|
+
baseCss: String(css_1.default),
|
|
13
|
+
lightCss: String(css_3.default),
|
|
14
|
+
darkCss: String(css_2.default),
|
|
15
|
+
};
|
|
16
|
+
exports.DEFAULT_CSS = [
|
|
17
|
+
exports.DEFAULT_THEME.baseCss,
|
|
18
|
+
exports.DEFAULT_THEME.lightCss,
|
|
19
|
+
exports.DEFAULT_THEME.darkCss,
|
|
20
|
+
].join('\n');
|
|
21
|
+
exports.PRESET_COLORS = colors_1.default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface CharScanner {
|
|
2
|
+
text: string;
|
|
3
|
+
index: number;
|
|
4
|
+
length: number;
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
peek(): string | undefined;
|
|
8
|
+
next(): string | undefined;
|
|
9
|
+
eof(): boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function createCharScanner(text: string, baseLine?: number, baseColumn?: number): CharScanner;
|
|
12
|
+
export interface LineInfo {
|
|
13
|
+
raw: string;
|
|
14
|
+
content: string;
|
|
15
|
+
tabCount: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function getLineInfo(raw: string, maxTabsForPosition?: number): LineInfo;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCharScanner = createCharScanner;
|
|
4
|
+
exports.getLineInfo = getLineInfo;
|
|
5
|
+
function createCharScanner(text, baseLine = 1, baseColumn = 1) {
|
|
6
|
+
return {
|
|
7
|
+
text,
|
|
8
|
+
index: 0,
|
|
9
|
+
length: text.length,
|
|
10
|
+
line: baseLine,
|
|
11
|
+
column: baseColumn,
|
|
12
|
+
peek() {
|
|
13
|
+
if (this.index >= this.length) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return this.text[this.index];
|
|
17
|
+
},
|
|
18
|
+
next() {
|
|
19
|
+
if (this.index >= this.length) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const ch = this.text[this.index];
|
|
23
|
+
this.index += 1;
|
|
24
|
+
if (ch === '\n') {
|
|
25
|
+
this.line += 1;
|
|
26
|
+
this.column = 1;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.column += 1;
|
|
30
|
+
}
|
|
31
|
+
return ch;
|
|
32
|
+
},
|
|
33
|
+
eof() {
|
|
34
|
+
return this.index >= this.length;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getLineInfo(raw, maxTabsForPosition = 2) {
|
|
39
|
+
let index = 0;
|
|
40
|
+
let tabCount = 0;
|
|
41
|
+
while (index < raw.length && raw[index] === '\t' && tabCount < maxTabsForPosition) {
|
|
42
|
+
tabCount += 1;
|
|
43
|
+
index += 1;
|
|
44
|
+
}
|
|
45
|
+
const content = raw.slice(index);
|
|
46
|
+
return { raw, content, tabCount };
|
|
47
|
+
}
|
package/dist/parser.d.ts
ADDED
package/dist/parser.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./core/ast"), exports);
|
|
18
|
+
__exportStar(require("./core/errors"), exports);
|
|
19
|
+
__exportStar(require("./core/parser"), exports);
|
|
20
|
+
__exportStar(require("./html/render/html"), exports);
|
|
21
|
+
__exportStar(require("./html/theme/theme"), exports);
|
|
22
|
+
__exportStar(require("./html/convert"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jianwen-lang/parser",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "JianWen language parser implemented in TypeScript",
|
|
5
|
+
"main": "dist/parser.js",
|
|
6
|
+
"types": "dist/parser.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true })\"",
|
|
17
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
18
|
+
"prepack": "npm run build",
|
|
19
|
+
"test": "jest",
|
|
20
|
+
"test:watch": "jest --watch",
|
|
21
|
+
"render": "ts-node \"src/cli/render.ts\"",
|
|
22
|
+
"test:render": "ts-node \"scripts/test-render.ts\"",
|
|
23
|
+
"format": "prettier \"./src/**/*.{ts,tsx,js,jsx,json,md}\" \"./tests/**/*.{ts,tsx,js,jsx,json,md}\" --write",
|
|
24
|
+
"format:check": "prettier \"./src/**/*.{ts,tsx,js,jsx,json,md}\" \"./tests/**/*.{ts,tsx,js,jsx,json,md}\" --check",
|
|
25
|
+
"lint": "eslint \"./src/**/*.{ts,tsx}\" \"./tests/**/*.{ts,tsx}\"",
|
|
26
|
+
"lint:fix": "eslint \"./src/**/*.{ts,tsx}\" \"./tests/**/*.{ts,tsx}\" --fix"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"js-beautify": "^1.15.4"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@eslint/js": "^9.39.1",
|
|
34
|
+
"@types/jest": "^30.0.0",
|
|
35
|
+
"@types/js-beautify": "^1.14.3",
|
|
36
|
+
"@types/node": "^24.10.1",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
38
|
+
"@typescript-eslint/parser": "^8.48.0",
|
|
39
|
+
"eslint": "^9.39.1",
|
|
40
|
+
"eslint-config-prettier": "^10.1.8",
|
|
41
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
42
|
+
"globals": "^17.0.0",
|
|
43
|
+
"jest": "^30.2.0",
|
|
44
|
+
"prettier": "^3.6.2",
|
|
45
|
+
"ts-jest": "^29.4.5",
|
|
46
|
+
"ts-node": "^10.9.2",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"typescript-eslint": "^8.48.0"
|
|
49
|
+
}
|
|
50
|
+
}
|