@cosense-toolbox/parser 0.1.0-beta.1 → 0.1.0-beta.3
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/README.md +45 -31
- package/dist/{ast-uYWtkHwT.cjs → ast-C0BGz7X2.cjs} +2 -2
- package/dist/ast-C0BGz7X2.cjs.map +1 -0
- package/dist/{ast-CIKXwSl5.mjs → ast-CMQYawYl.mjs} +2 -2
- package/dist/ast-CMQYawYl.mjs.map +1 -0
- package/dist/compile.cjs +2 -213
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.d.cts +2 -129
- package/dist/compile.d.cts.map +1 -1
- package/dist/compile.d.mts +2 -129
- package/dist/compile.d.mts.map +1 -1
- package/dist/compile.mjs +3 -207
- package/dist/compile.mjs.map +1 -1
- package/dist/extensions.cjs +10 -7
- package/dist/extensions.cjs.map +1 -1
- package/dist/extensions.d.cts +12 -8
- package/dist/extensions.d.cts.map +1 -1
- package/dist/extensions.d.mts +12 -8
- package/dist/extensions.d.mts.map +1 -1
- package/dist/extensions.mjs +10 -7
- package/dist/extensions.mjs.map +1 -1
- package/dist/html.cjs +458 -0
- package/dist/html.cjs.map +1 -0
- package/dist/html.d.cts +274 -0
- package/dist/html.d.cts.map +1 -0
- package/dist/html.d.mts +274 -0
- package/dist/html.d.mts.map +1 -0
- package/dist/html.mjs +447 -0
- package/dist/html.mjs.map +1 -0
- package/dist/image-url-YcTed8tg.cjs.map +1 -1
- package/dist/image-url-eQ6X-oN0.mjs.map +1 -1
- package/dist/index-CrIlOW1k.d.mts +78 -0
- package/dist/index-CrIlOW1k.d.mts.map +1 -0
- package/dist/index-_o1STNhP.d.cts +78 -0
- package/dist/index-_o1STNhP.d.cts.map +1 -0
- package/dist/index.cjs +188 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -77
- package/dist/index.d.mts +4 -77
- package/dist/index.mjs +180 -27
- package/dist/index.mjs.map +1 -1
- package/dist/schema.cjs +1 -0
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.cts.map +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.d.mts.map +1 -1
- package/dist/schema.mjs +1 -0
- package/dist/schema.mjs.map +1 -1
- package/dist/{types-CiwPj2R8.d.cts → types-CdiHju1P.d.mts} +15 -12
- package/dist/types-CdiHju1P.d.mts.map +1 -0
- package/dist/{types-9vAAFHka.d.mts → types-_-ZAyNkz.d.cts} +15 -12
- package/dist/types-_-ZAyNkz.d.cts.map +1 -0
- package/dist/{types-DmfFumcw.d.cts → types-gWMrsXPX.d.cts} +28 -21
- package/dist/{types-DmfFumcw.d.cts.map → types-gWMrsXPX.d.cts.map} +1 -1
- package/dist/{types-DmfFumcw.d.mts → types-gWMrsXPX.d.mts} +28 -21
- package/dist/{types-DmfFumcw.d.mts.map → types-gWMrsXPX.d.mts.map} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +27 -5
- package/dist/ast-CIKXwSl5.mjs.map +0 -1
- package/dist/ast-uYWtkHwT.cjs.map +0 -1
- package/dist/decoration-DODaJKeA.cjs +0 -103
- package/dist/decoration-DODaJKeA.cjs.map +0 -1
- package/dist/decoration-Dq_5e20j.mjs +0 -68
- package/dist/decoration-Dq_5e20j.mjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/types-9vAAFHka.d.mts.map +0 -1
- package/dist/types-CiwPj2R8.d.cts.map +0 -1
package/dist/schema.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as TableCell, D as ProjectLink, E as Position, M as TextNode, N as TitleBlock, P as TopLevelBlock, T as Point, b as InternalLink, c as CodeLine, d as FormulaNode, f as Hashtag, g as InlineNode, h as InlineCode, j as TableRow, k as TableBlock, l as Decoration, m as ImageNode, p as IconNode, s as CodeBlock, u as ExternalLink, w as Page, x as LineBlock } from "./types-
|
|
1
|
+
import { A as TableCell, D as ProjectLink, E as Position, M as TextNode, N as TitleBlock, P as TopLevelBlock, T as Point, b as InternalLink, c as CodeLine, d as FormulaNode, f as Hashtag, g as InlineNode, h as InlineCode, j as TableRow, k as TableBlock, l as Decoration, m as ImageNode, p as IconNode, s as CodeBlock, u as ExternalLink, w as Page, x as LineBlock } from "./types-gWMrsXPX.mjs";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
3
|
//#region src/schema.d.ts
|
|
4
4
|
declare const PointSchema: Schema.Schema<Point>;
|
package/dist/schema.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.mts","names":[],"sources":["../src/schema.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"schema.d.mts","names":[],"sources":["../src/schema.ts"],"mappings":";;;cAuCa,aAAa,OAAO,OAAO;cAM3B,gBAAgB,OAAO,OAAO;cAS9B,gBAAgB,OAAO,OAAO;cAM9B,oBAAoB,OAAO,OAAO;cAOlC,oBAAoB,OAAO,OAAO;cAOlC,mBAAmB,OAAO,OAAO;cASjC,eAAe,OAAO,OAAO;cAM7B,kBAAkB,OAAO,OAAO;cAMhC,iBAAiB,OAAO,OAAO;cAQ/B,gBAAgB,OAAO,OAAO;cAO9B,mBAAmB,OAAO,OAAO;;cAOjC,kBAAkB,OAAO,OAAO;cAahC,kBAAkB,OAAO,OAAO;cAehC,kBAAkB,OAAO,OAAO;cAOhC,gBAAgB,OAAO,OAAO;cAM9B,iBAAiB,OAAO,OAAO;cAQ/B,iBAAiB,OAAO,OAAO;cAO/B,gBAAgB,OAAO,OAAO;cAM9B,kBAAkB,OAAO,OAAO;cAQhC,iBAAiB,OAAO,OAAO;cAS/B,qBAAqB,OAAO,OAAO;cAOnC,YAAY,OAAO,OAAO;;;;;cAU1B,aAAU,YAAA,6CAAA,yCAAA,OAAA,mCAAA"}
|
package/dist/schema.mjs
CHANGED
|
@@ -110,6 +110,7 @@ const CodeBlockSchema = Schema.Struct({
|
|
|
110
110
|
const TableCellSchema = Schema.Struct({
|
|
111
111
|
type: Schema.Literal("tableCell"),
|
|
112
112
|
value: Schema.String,
|
|
113
|
+
children: Schema.Array(InlineNodeSchema),
|
|
113
114
|
...withPosition
|
|
114
115
|
});
|
|
115
116
|
const TableRowSchema = Schema.Struct({
|
package/dist/schema.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/**\n * schema.ts — AST の effect Schema 定義 (`@cosense-toolbox/parser/schema` サブパス)。\n *\n * パーサー本体はこれを使わない。自分でパースした結果は型が保証されているので検証は要らず、\n * 必要になるのは外から来た値 — 保存しておいた JSON を読み戻したとき、別プロセスから\n * 受け取ったとき、書き出したときとバージョンが違うとき — に限られる。\n * 使わない利用者のバンドルに載らないよう、メインエントリからは re-export しない。\n *\n * 型の単一情報源は types.ts の方であり、ここではない。各 Schema に `Schema.Schema<T>` を\n * 明示注釈してあるので、types.ts と定義がズレたらコンパイルエラーになる。\n * 逆に Schema から型を推論する形にすると、NodeMap への declaration merging が効かなくなる。\n */\nimport { Schema } from
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/**\n * schema.ts — AST の effect Schema 定義 (`@cosense-toolbox/parser/schema` サブパス)。\n *\n * パーサー本体はこれを使わない。自分でパースした結果は型が保証されているので検証は要らず、\n * 必要になるのは外から来た値 — 保存しておいた JSON を読み戻したとき、別プロセスから\n * 受け取ったとき、書き出したときとバージョンが違うとき — に限られる。\n * 使わない利用者のバンドルに載らないよう、メインエントリからは re-export しない。\n *\n * 型の単一情報源は types.ts の方であり、ここではない。各 Schema に `Schema.Schema<T>` を\n * 明示注釈してあるので、types.ts と定義がズレたらコンパイルエラーになる。\n * 逆に Schema から型を推論する形にすると、NodeMap への declaration merging が効かなくなる。\n */\nimport { Schema } from \"effect\"\n\nimport type {\n CodeBlock,\n CodeLine,\n Decoration,\n ExternalLink,\n FormulaNode,\n Hashtag,\n IconNode,\n ImageNode,\n InlineCode,\n InlineNode,\n InternalLink,\n LineBlock,\n Page,\n Point,\n Position,\n ProjectLink,\n TableBlock,\n TableCell,\n TableRow,\n TextNode,\n TitleBlock,\n TopLevelBlock,\n} from \"./types\"\n\nexport const PointSchema: Schema.Schema<Point> = Schema.Struct({\n line: Schema.Number,\n column: Schema.Number,\n offset: Schema.Number,\n})\n\nexport const PositionSchema: Schema.Schema<Position> = Schema.Struct({\n start: PointSchema,\n end: PointSchema,\n})\n\nconst withPosition = { position: PositionSchema }\n\n// --- インライン ---------------------------------------------------------\n\nexport const TextNodeSchema: Schema.Schema<TextNode> = Schema.Struct({\n type: Schema.Literal(\"text\"),\n value: Schema.String,\n ...withPosition,\n})\n\nexport const InternalLinkSchema: Schema.Schema<InternalLink> = Schema.Struct({\n type: Schema.Literal(\"internalLink\"),\n label: Schema.String,\n target: Schema.String,\n ...withPosition,\n})\n\nexport const ExternalLinkSchema: Schema.Schema<ExternalLink> = Schema.Struct({\n type: Schema.Literal(\"externalLink\"),\n label: Schema.String,\n target: Schema.String,\n ...withPosition,\n})\n\nexport const ProjectLinkSchema: Schema.Schema<ProjectLink> = Schema.Struct({\n type: Schema.Literal(\"projectLink\"),\n label: Schema.String,\n target: Schema.String,\n project: Schema.String,\n title: Schema.String,\n ...withPosition,\n})\n\nexport const HashtagSchema: Schema.Schema<Hashtag> = Schema.Struct({\n type: Schema.Literal(\"hashtag\"),\n value: Schema.String,\n ...withPosition,\n})\n\nexport const InlineCodeSchema: Schema.Schema<InlineCode> = Schema.Struct({\n type: Schema.Literal(\"inlineCode\"),\n value: Schema.String,\n ...withPosition,\n})\n\nexport const ImageNodeSchema: Schema.Schema<ImageNode> = Schema.Struct({\n type: Schema.Literal(\"image\"),\n src: Schema.String,\n large: Schema.optionalWith(Schema.Boolean, { exact: true }),\n link: Schema.optionalWith(Schema.String, { exact: true }),\n ...withPosition,\n})\n\nexport const IconNodeSchema: Schema.Schema<IconNode> = Schema.Struct({\n type: Schema.Literal(\"icon\"),\n user: Schema.String,\n count: Schema.Number,\n ...withPosition,\n})\n\nexport const FormulaNodeSchema: Schema.Schema<FormulaNode> = Schema.Struct({\n type: Schema.Literal(\"formula\"),\n value: Schema.String,\n ...withPosition,\n})\n\n/** 装飾は中に装飾以外のインライン記法を持てるので、InlineNodeSchema を通じて再帰する。 */\nexport const DecorationSchema: Schema.Schema<Decoration> = Schema.Struct({\n type: Schema.Literal(\"decoration\"),\n value: Schema.String,\n markers: Schema.Array(Schema.String),\n bold: Schema.Boolean,\n italic: Schema.Boolean,\n strike: Schema.Boolean,\n underline: Schema.Boolean,\n sizeLevel: Schema.Number,\n children: Schema.Array(Schema.suspend((): Schema.Schema<InlineNode> => InlineNodeSchema)),\n ...withPosition,\n})\n\nexport const InlineNodeSchema: Schema.Schema<InlineNode> = Schema.Union(\n TextNodeSchema,\n InternalLinkSchema,\n ExternalLinkSchema,\n ProjectLinkSchema,\n HashtagSchema,\n InlineCodeSchema,\n ImageNodeSchema,\n IconNodeSchema,\n FormulaNodeSchema,\n DecorationSchema,\n)\n\n// --- ブロック -----------------------------------------------------------\n\nexport const TitleBlockSchema: Schema.Schema<TitleBlock> = Schema.Struct({\n type: Schema.Literal(\"title\"),\n value: Schema.String,\n children: Schema.Array(InlineNodeSchema),\n ...withPosition,\n})\n\nexport const CodeLineSchema: Schema.Schema<CodeLine> = Schema.Struct({\n type: Schema.Literal(\"codeLine\"),\n value: Schema.String,\n ...withPosition,\n})\n\nexport const CodeBlockSchema: Schema.Schema<CodeBlock> = Schema.Struct({\n type: Schema.Literal(\"codeBlock\"),\n filename: Schema.String,\n indent: Schema.Number,\n lines: Schema.Array(CodeLineSchema),\n ...withPosition,\n})\n\nexport const TableCellSchema: Schema.Schema<TableCell> = Schema.Struct({\n type: Schema.Literal(\"tableCell\"),\n value: Schema.String,\n children: Schema.Array(InlineNodeSchema),\n ...withPosition,\n})\n\nexport const TableRowSchema: Schema.Schema<TableRow> = Schema.Struct({\n type: Schema.Literal(\"tableRow\"),\n cells: Schema.Array(TableCellSchema),\n ...withPosition,\n})\n\nexport const TableBlockSchema: Schema.Schema<TableBlock> = Schema.Struct({\n type: Schema.Literal(\"table\"),\n name: Schema.String,\n indent: Schema.Number,\n rows: Schema.Array(TableRowSchema),\n ...withPosition,\n})\n\nexport const LineBlockSchema: Schema.Schema<LineBlock> = Schema.Struct({\n type: Schema.Literal(\"line\"),\n indent: Schema.Number,\n quote: Schema.Boolean,\n monospace: Schema.Boolean,\n children: Schema.Array(InlineNodeSchema),\n ...withPosition,\n})\n\nexport const TopLevelBlockSchema: Schema.Schema<TopLevelBlock> = Schema.Union(\n TitleBlockSchema,\n CodeBlockSchema,\n TableBlockSchema,\n LineBlockSchema,\n)\n\nexport const PageSchema: Schema.Schema<Page> = Schema.Struct({\n type: Schema.Literal(\"page\"),\n children: Schema.Array(TopLevelBlockSchema),\n ...withPosition,\n})\n\n/**\n * 未知の値を `Page` として検証する。成功なら `Right<Page>`、失敗なら `Left<ParseError>`。\n * パースそのものは失敗しないので、このパッケージで Either を返すのはここだけ。\n */\nexport const decodePage = Schema.decodeUnknownEither(PageSchema)\n"],"mappings":";;;;;;;;;;;;;;AAuCA,MAAa,cAAoC,OAAO,OAAO;CAC7D,MAAM,OAAO;CACb,QAAQ,OAAO;CACf,QAAQ,OAAO;AACjB,CAAC;AAED,MAAa,iBAA0C,OAAO,OAAO;CACnE,OAAO;CACP,KAAK;AACP,CAAC;AAED,MAAM,eAAe,EAAE,UAAU,eAAe;AAIhD,MAAa,iBAA0C,OAAO,OAAO;CACnE,MAAM,OAAO,QAAQ,MAAM;CAC3B,OAAO,OAAO;CACd,GAAG;AACL,CAAC;AAED,MAAa,qBAAk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AC3D,MAAM,OAAO,QAAQ,MAAM;CAC3B,UAAU,OAAO,MAAM,mBAAmB;CAC1C,GAAG;AACL,CAAC;;;;;AAMD,MAAa,aAAa,OAAO,oBAAoB,UAAU"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { _ as InlineNodeInit, g as InlineNode } from "./types-
|
|
2
|
-
import { Option } from "effect";
|
|
1
|
+
import { _ as InlineNodeInit, g as InlineNode } from "./types-gWMrsXPX.mjs";
|
|
3
2
|
//#region src/core/position.d.ts
|
|
4
3
|
/** 走査対象の文字列のインデックス 0 が、ソース上のどこにあるか。 */
|
|
5
4
|
interface Origin {
|
|
@@ -10,7 +9,7 @@ interface Origin {
|
|
|
10
9
|
//#endregion
|
|
11
10
|
//#region src/inline/types.d.ts
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* 走査中に共有される文脈。拡張のルールにもこの形で渡る。
|
|
14
13
|
*
|
|
15
14
|
* `tokenize` は装飾の中身のように部分文字列を再帰的に解析するためのフック。
|
|
16
15
|
* ルールが走査ループを直接 import すると循環参照になるので、文脈経由で渡している。
|
|
@@ -20,8 +19,6 @@ interface InlineContext {
|
|
|
20
19
|
readonly allowDecoration: boolean;
|
|
21
20
|
/** 走査対象 `source` のインデックス 0 がソース上のどこか */
|
|
22
21
|
readonly origin: Origin;
|
|
23
|
-
/** 拡張が追加した `[...]` のルール。既定のルールより先に試される */
|
|
24
|
-
readonly bracketRules: readonly BracketRule[];
|
|
25
22
|
readonly tokenize: (source: string, origin: Origin, allowDecoration: boolean) => readonly InlineNode[];
|
|
26
23
|
}
|
|
27
24
|
/** 記法が成立したときの結果。`length` は `index` から消費した文字数。 */
|
|
@@ -30,12 +27,12 @@ interface ConstructMatch {
|
|
|
30
27
|
readonly length: number;
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
|
-
* 行内の走査ルール。`source[index]`
|
|
30
|
+
* 行内の走査ルール。`source[index]` から記法が始まるなら、そのノードと消費した文字数を返す。
|
|
34
31
|
*
|
|
35
|
-
*
|
|
36
|
-
* 「記法として無効なので `[` は素の文字」といったケースも
|
|
32
|
+
* null を返すと呼び出し側は 1 文字を素のテキストとして消費して次に進むので、
|
|
33
|
+
* 「記法として無効なので `[` は素の文字」といったケースも null で表せる。
|
|
37
34
|
*/
|
|
38
|
-
type InlineConstruct = (source: string, index: number, ctx: InlineContext) =>
|
|
35
|
+
type InlineConstruct = (source: string, index: number, ctx: InlineContext) => ConstructMatch | null;
|
|
39
36
|
/** `[...]` の中身を解釈するルールに渡る文脈。 */
|
|
40
37
|
interface BracketRuleContext extends InlineContext {
|
|
41
38
|
/** `inner` のインデックス 0 がソース上のどこか (子ノードの位置計算に使う) */
|
|
@@ -43,9 +40,9 @@ interface BracketRuleContext extends InlineContext {
|
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
42
|
* `[...]` の中身を解釈するルール。角括弧そのものは呼び出し側が扱うので、
|
|
46
|
-
* ルールは中身の文字列だけを見る。
|
|
43
|
+
* ルールは中身の文字列だけを見る。null なら次のルールへ、全部 null なら記法として無効。
|
|
47
44
|
*/
|
|
48
|
-
type BracketRule = (inner: string, ctx: BracketRuleContext) =>
|
|
45
|
+
type BracketRule = (inner: string, ctx: BracketRuleContext) => InlineNodeInit | null;
|
|
49
46
|
/**
|
|
50
47
|
* 記法の拡張。`parse` / `tokenizeInline` の options に渡すと、
|
|
51
48
|
* **既定のルールより先に**試されるようになる。
|
|
@@ -57,7 +54,13 @@ interface Extension {
|
|
|
57
54
|
readonly constructs?: readonly InlineConstruct[];
|
|
58
55
|
/** `[...]` の中身の解釈ルール。角括弧記法のバリエーションを足すときはこちら */
|
|
59
56
|
readonly bracketRules?: readonly BracketRule[];
|
|
57
|
+
/**
|
|
58
|
+
* テーブルのセルの中でも記法として残すノード。true を返したノードは残し、
|
|
59
|
+
* どの拡張も残さないノードは書いたままの文字に戻す。リンクの記法は拡張に依らず常に残す
|
|
60
|
+
* (Cosense Web と同じ)。セルの中を行と同じく読むだけなら `tableCellNotation` を使う
|
|
61
|
+
*/
|
|
62
|
+
readonly keepInTableCell?: (node: InlineNode) => boolean;
|
|
60
63
|
}
|
|
61
64
|
//#endregion
|
|
62
65
|
export { InlineConstruct as a, Extension as i, BracketRuleContext as n, InlineContext as o, ConstructMatch as r, Origin as s, BracketRule as t };
|
|
63
|
-
//# sourceMappingURL=types-
|
|
66
|
+
//# sourceMappingURL=types-CdiHju1P.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CdiHju1P.d.mts","names":[],"sources":["../src/core/position.ts","../src/inline/types.ts"],"mappings":";;;UAUiB;WACN;WACA;WACA;;;;;;;;;;UCMM;;WAEN;;WAEA,QAAQ;WACR,WACP,gBACA,QAAQ,QACR,sCACY;;;UAIC;WACN,MAAM;WACN;;;;;;;;KASC,mBACV,gBACA,eACA,KAAK,kBACF;;UAGY,2BAA2B;;WAEjC,aAAa;;;;;;KAOZ,eAAe,eAAe,KAAK,uBAAuB;;;;;;;UAQrD;;WAEN,sBAAsB;;WAEtB,wBAAwB;;;;;;WAMxB,mBAAmB,MAAM"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { _ as InlineNodeInit, g as InlineNode } from "./types-
|
|
2
|
-
import { Option } from "effect";
|
|
1
|
+
import { _ as InlineNodeInit, g as InlineNode } from "./types-gWMrsXPX.cjs";
|
|
3
2
|
//#region src/core/position.d.ts
|
|
4
3
|
/** 走査対象の文字列のインデックス 0 が、ソース上のどこにあるか。 */
|
|
5
4
|
interface Origin {
|
|
@@ -10,7 +9,7 @@ interface Origin {
|
|
|
10
9
|
//#endregion
|
|
11
10
|
//#region src/inline/types.d.ts
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* 走査中に共有される文脈。拡張のルールにもこの形で渡る。
|
|
14
13
|
*
|
|
15
14
|
* `tokenize` は装飾の中身のように部分文字列を再帰的に解析するためのフック。
|
|
16
15
|
* ルールが走査ループを直接 import すると循環参照になるので、文脈経由で渡している。
|
|
@@ -20,8 +19,6 @@ interface InlineContext {
|
|
|
20
19
|
readonly allowDecoration: boolean;
|
|
21
20
|
/** 走査対象 `source` のインデックス 0 がソース上のどこか */
|
|
22
21
|
readonly origin: Origin;
|
|
23
|
-
/** 拡張が追加した `[...]` のルール。既定のルールより先に試される */
|
|
24
|
-
readonly bracketRules: readonly BracketRule[];
|
|
25
22
|
readonly tokenize: (source: string, origin: Origin, allowDecoration: boolean) => readonly InlineNode[];
|
|
26
23
|
}
|
|
27
24
|
/** 記法が成立したときの結果。`length` は `index` から消費した文字数。 */
|
|
@@ -30,12 +27,12 @@ interface ConstructMatch {
|
|
|
30
27
|
readonly length: number;
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
|
-
* 行内の走査ルール。`source[index]`
|
|
30
|
+
* 行内の走査ルール。`source[index]` から記法が始まるなら、そのノードと消費した文字数を返す。
|
|
34
31
|
*
|
|
35
|
-
*
|
|
36
|
-
* 「記法として無効なので `[` は素の文字」といったケースも
|
|
32
|
+
* null を返すと呼び出し側は 1 文字を素のテキストとして消費して次に進むので、
|
|
33
|
+
* 「記法として無効なので `[` は素の文字」といったケースも null で表せる。
|
|
37
34
|
*/
|
|
38
|
-
type InlineConstruct = (source: string, index: number, ctx: InlineContext) =>
|
|
35
|
+
type InlineConstruct = (source: string, index: number, ctx: InlineContext) => ConstructMatch | null;
|
|
39
36
|
/** `[...]` の中身を解釈するルールに渡る文脈。 */
|
|
40
37
|
interface BracketRuleContext extends InlineContext {
|
|
41
38
|
/** `inner` のインデックス 0 がソース上のどこか (子ノードの位置計算に使う) */
|
|
@@ -43,9 +40,9 @@ interface BracketRuleContext extends InlineContext {
|
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
42
|
* `[...]` の中身を解釈するルール。角括弧そのものは呼び出し側が扱うので、
|
|
46
|
-
* ルールは中身の文字列だけを見る。
|
|
43
|
+
* ルールは中身の文字列だけを見る。null なら次のルールへ、全部 null なら記法として無効。
|
|
47
44
|
*/
|
|
48
|
-
type BracketRule = (inner: string, ctx: BracketRuleContext) =>
|
|
45
|
+
type BracketRule = (inner: string, ctx: BracketRuleContext) => InlineNodeInit | null;
|
|
49
46
|
/**
|
|
50
47
|
* 記法の拡張。`parse` / `tokenizeInline` の options に渡すと、
|
|
51
48
|
* **既定のルールより先に**試されるようになる。
|
|
@@ -57,7 +54,13 @@ interface Extension {
|
|
|
57
54
|
readonly constructs?: readonly InlineConstruct[];
|
|
58
55
|
/** `[...]` の中身の解釈ルール。角括弧記法のバリエーションを足すときはこちら */
|
|
59
56
|
readonly bracketRules?: readonly BracketRule[];
|
|
57
|
+
/**
|
|
58
|
+
* テーブルのセルの中でも記法として残すノード。true を返したノードは残し、
|
|
59
|
+
* どの拡張も残さないノードは書いたままの文字に戻す。リンクの記法は拡張に依らず常に残す
|
|
60
|
+
* (Cosense Web と同じ)。セルの中を行と同じく読むだけなら `tableCellNotation` を使う
|
|
61
|
+
*/
|
|
62
|
+
readonly keepInTableCell?: (node: InlineNode) => boolean;
|
|
60
63
|
}
|
|
61
64
|
//#endregion
|
|
62
65
|
export { InlineConstruct as a, Extension as i, BracketRuleContext as n, InlineContext as o, ConstructMatch as r, Origin as s, BracketRule as t };
|
|
63
|
-
//# sourceMappingURL=types-
|
|
66
|
+
//# sourceMappingURL=types-_-ZAyNkz.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-_-ZAyNkz.d.cts","names":[],"sources":["../src/core/position.ts","../src/inline/types.ts"],"mappings":";;;UAUiB;WACN;WACA;WACA;;;;;;;;;;UCMM;;WAEN;;WAEA,QAAQ;WACR,WACP,gBACA,QAAQ,QACR,sCACY;;;UAIC;WACN,MAAM;WACN;;;;;;;;KASC,mBACV,gBACA,eACA,KAAK,kBACF;;UAGY,2BAA2B;;WAEjC,aAAa;;;;;;KAOZ,eAAe,eAAe,KAAK,uBAAuB;;;;;;;UAQrD;;WAEN,sBAAsB;;WAEtB,wBAAwB;;;;;;WAMxB,mBAAmB,MAAM"}
|
|
@@ -36,12 +36,12 @@ interface NodeBase {
|
|
|
36
36
|
}
|
|
37
37
|
/** 記法として解釈されなかった素のテキスト。 */
|
|
38
38
|
interface TextNode extends NodeBase {
|
|
39
|
-
readonly type:
|
|
39
|
+
readonly type: "text";
|
|
40
40
|
readonly value: string;
|
|
41
41
|
}
|
|
42
42
|
/** `[title]` — 同じプロジェクト内のページへのリンク。 */
|
|
43
43
|
interface InternalLink extends NodeBase {
|
|
44
|
-
readonly type:
|
|
44
|
+
readonly type: "internalLink";
|
|
45
45
|
/** 表示テキスト。内部リンクでは target と同じ */
|
|
46
46
|
readonly label: string;
|
|
47
47
|
/** リンク先のページタイトル */
|
|
@@ -49,13 +49,13 @@ interface InternalLink extends NodeBase {
|
|
|
49
49
|
}
|
|
50
50
|
/** 裸の URL、`[url]`、`[url label]`、`[label url]`。 */
|
|
51
51
|
interface ExternalLink extends NodeBase {
|
|
52
|
-
readonly type:
|
|
52
|
+
readonly type: "externalLink";
|
|
53
53
|
readonly label: string;
|
|
54
54
|
readonly target: string;
|
|
55
55
|
}
|
|
56
56
|
/** `[/project/title]` — 別プロジェクトのページへのリンク。 */
|
|
57
57
|
interface ProjectLink extends NodeBase {
|
|
58
|
-
readonly type:
|
|
58
|
+
readonly type: "projectLink";
|
|
59
59
|
readonly label: string;
|
|
60
60
|
/** `/project/title` 形式のまま */
|
|
61
61
|
readonly target: string;
|
|
@@ -65,17 +65,17 @@ interface ProjectLink extends NodeBase {
|
|
|
65
65
|
}
|
|
66
66
|
/** `#tag` — 内部リンクと同じくページを指すが、記法が異なるので別ノードにする。 */
|
|
67
67
|
interface Hashtag extends NodeBase {
|
|
68
|
-
readonly type:
|
|
68
|
+
readonly type: "hashtag";
|
|
69
69
|
readonly value: string;
|
|
70
70
|
}
|
|
71
71
|
/** バッククォートで囲んだインラインコード。 */
|
|
72
72
|
interface InlineCode extends NodeBase {
|
|
73
|
-
readonly type:
|
|
73
|
+
readonly type: "inlineCode";
|
|
74
74
|
readonly value: string;
|
|
75
75
|
}
|
|
76
76
|
/** `[url.png]` / `[[url.png]]` (large) / `[linkUrl imageUrl]` (link 付き)。 */
|
|
77
77
|
interface ImageNode extends NodeBase {
|
|
78
|
-
readonly type:
|
|
78
|
+
readonly type: "image";
|
|
79
79
|
readonly src: string;
|
|
80
80
|
/** `[[...]]` で囲まれた大きい表示 */
|
|
81
81
|
readonly large?: boolean;
|
|
@@ -84,14 +84,14 @@ interface ImageNode extends NodeBase {
|
|
|
84
84
|
}
|
|
85
85
|
/** `[user.icon]` / `[user.icon*N]`。 */
|
|
86
86
|
interface IconNode extends NodeBase {
|
|
87
|
-
readonly type:
|
|
87
|
+
readonly type: "icon";
|
|
88
88
|
readonly user: string;
|
|
89
89
|
/** 連打の個数 (1..20)。記法上省略されていても 1 が入る */
|
|
90
90
|
readonly count: number;
|
|
91
91
|
}
|
|
92
92
|
/** `[$ 数式]`。中身は解釈せず生のまま返す (KaTeX 等に渡す想定)。 */
|
|
93
93
|
interface FormulaNode extends NodeBase {
|
|
94
|
-
readonly type:
|
|
94
|
+
readonly type: "formula";
|
|
95
95
|
readonly value: string;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
@@ -101,7 +101,7 @@ interface FormulaNode extends NodeBase {
|
|
|
101
101
|
* Markdown のように入れ子の強調へ分解せずフラグの集合として表す。
|
|
102
102
|
*/
|
|
103
103
|
interface Decoration extends NodeBase {
|
|
104
|
-
readonly type:
|
|
104
|
+
readonly type: "decoration";
|
|
105
105
|
/** 装飾記号を除いた中身の生テキスト */
|
|
106
106
|
readonly value: string;
|
|
107
107
|
/** 書かれた文字装飾記法の記号を、出現順・重複なしで並べたもの。`[*** x]` なら `['*']` */
|
|
@@ -135,14 +135,14 @@ type InlineNodeType = keyof InlineNodeMap;
|
|
|
135
135
|
type InlineNode = InlineNodeMap[InlineNodeType];
|
|
136
136
|
/** ページの 1 行目。`code:` / `table:` として解釈しない (Cosense ではタイトル専用の行)。 */
|
|
137
137
|
interface TitleBlock extends NodeBase {
|
|
138
|
-
readonly type:
|
|
138
|
+
readonly type: "title";
|
|
139
139
|
/** タイトル行の生テキスト。Cosense ではこれがページの識別子でもある */
|
|
140
140
|
readonly value: string;
|
|
141
141
|
readonly children: readonly InlineNode[];
|
|
142
142
|
}
|
|
143
143
|
/** `code:filename` ブロックの本体 1 行。記法は解釈しない。 */
|
|
144
144
|
interface CodeLine extends NodeBase {
|
|
145
|
-
readonly type:
|
|
145
|
+
readonly type: "codeLine";
|
|
146
146
|
/**
|
|
147
147
|
* ブロックの左端に揃えた中身。ヘッダより 1 段深いところを左端とみなすので、
|
|
148
148
|
* それより深いインデントはコード自身の字下げとして残る。
|
|
@@ -151,33 +151,40 @@ interface CodeLine extends NodeBase {
|
|
|
151
151
|
}
|
|
152
152
|
/** `code:filename` + それより深いインデントの行。 */
|
|
153
153
|
interface CodeBlock extends NodeBase {
|
|
154
|
-
readonly type:
|
|
154
|
+
readonly type: "codeBlock";
|
|
155
155
|
readonly filename: string;
|
|
156
156
|
/** ヘッダ行のインデント。本体行はこれより深い */
|
|
157
157
|
readonly indent: number;
|
|
158
158
|
/** ヘッダ行自身は含まない */
|
|
159
159
|
readonly lines: readonly CodeLine[];
|
|
160
160
|
}
|
|
161
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* テーブルの 1 セル。
|
|
163
|
+
*
|
|
164
|
+
* `children` はセルの中の記法。Cosense Web と同じく、既定ではリンクの記法だけを読み、
|
|
165
|
+
* それ以外は書いたままの文字になる (拡張 `tableCellNotation` で変えられる)。
|
|
166
|
+
*/
|
|
162
167
|
interface TableCell extends NodeBase {
|
|
163
|
-
readonly type:
|
|
168
|
+
readonly type: "tableCell";
|
|
169
|
+
/** セルに書かれた文字列そのまま */
|
|
164
170
|
readonly value: string;
|
|
171
|
+
readonly children: readonly InlineNode[];
|
|
165
172
|
}
|
|
166
173
|
/** テーブルの 1 行。タブ区切りでセルに分割済み。 */
|
|
167
174
|
interface TableRow extends NodeBase {
|
|
168
|
-
readonly type:
|
|
175
|
+
readonly type: "tableRow";
|
|
169
176
|
readonly cells: readonly TableCell[];
|
|
170
177
|
}
|
|
171
178
|
/** `table:name` + それより深いインデントの行。 */
|
|
172
179
|
interface TableBlock extends NodeBase {
|
|
173
|
-
readonly type:
|
|
180
|
+
readonly type: "table";
|
|
174
181
|
readonly name: string;
|
|
175
182
|
readonly indent: number;
|
|
176
183
|
readonly rows: readonly TableRow[];
|
|
177
184
|
}
|
|
178
185
|
/** 通常の行。 */
|
|
179
186
|
interface LineBlock extends NodeBase {
|
|
180
|
-
readonly type:
|
|
187
|
+
readonly type: "line";
|
|
181
188
|
/** 行頭の空白 (半角スペース / タブ / 全角スペース) の文字数 */
|
|
182
189
|
readonly indent: number;
|
|
183
190
|
/** `>` で始まる引用行 */
|
|
@@ -206,7 +213,7 @@ type BlockNode = BlockNodeMap[BlockNodeType];
|
|
|
206
213
|
type TopLevelBlock = TitleBlock | CodeBlock | TableBlock | LineBlock;
|
|
207
214
|
/** パース結果のルート。 */
|
|
208
215
|
interface Page extends NodeBase {
|
|
209
|
-
readonly type:
|
|
216
|
+
readonly type: "page";
|
|
210
217
|
readonly children: readonly TopLevelBlock[];
|
|
211
218
|
}
|
|
212
219
|
interface RootNodeMap {
|
|
@@ -224,9 +231,9 @@ type NodeOfType<K extends AnyNodeType> = AnyNodeMap[K];
|
|
|
224
231
|
* 記法を判定する側は「何のノードか」だけを決め、位置の付与は走査側がまとめて行う。
|
|
225
232
|
* こうしておくと、記法を 1 つ足すたびにオフセット計算を書き足さずに済む。
|
|
226
233
|
*/
|
|
227
|
-
type WithoutPosition<T> = T extends unknown ? Omit<T,
|
|
234
|
+
type WithoutPosition<T> = T extends unknown ? Omit<T, "position"> : never;
|
|
228
235
|
/** 位置を持たないインラインノード。記法ルールの戻り値。 */
|
|
229
236
|
type InlineNodeInit = WithoutPosition<InlineNode>;
|
|
230
237
|
//#endregion
|
|
231
238
|
export { TableCell as A, NodeOfType as C, ProjectLink as D, Position as E, WithoutPosition as F, TextNode as M, TitleBlock as N, RootNodeMap as O, TopLevelBlock as P, NodeBase as S, Point as T, InlineNodeInit as _, BlockNodeMap as a, InternalLink as b, CodeLine as c, FormulaNode as d, Hashtag as f, InlineNode as g, InlineCode as h, BlockNode as i, TableRow as j, TableBlock as k, Decoration as l, ImageNode as m, AnyNodeMap as n, BlockNodeType as o, IconNode as p, AnyNodeType as r, CodeBlock as s, AnyNode as t, ExternalLink as u, InlineNodeMap as v, Page as w, LineBlock as x, InlineNodeType as y };
|
|
232
|
-
//# sourceMappingURL=types-
|
|
239
|
+
//# sourceMappingURL=types-gWMrsXPX.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-gWMrsXPX.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;;;UAkBiB;;WAEN;;WAEA;;WAEA;;;;;;;UAQM;WACN,OAAO;WACP,KAAK;;;UAIC;WACN;WACA,UAAU;;;UAQJ,iBAAiB;WACvB;WACA;;;UAIM,qBAAqB;WAC3B;;WAEA;;WAEA;;;UAIM,qBAAqB;WAC3B;WACA;WACA;;;UAIM,oBAAoB;WAC1B;WACA;;WAEA;WACA;;WAEA;;;UAIM,gBAAgB;WACtB;WACA;;;UAIM,mBAAmB;WACzB;WACA;;;UAIM,kBAAkB;WACxB;WACA;;WAEA;;WAEA;;;UAIM,iBAAiB;WACvB;WACA;;WAEA;;;UAIM,oBAAoB;WAC1B;WACA;;;;;;;;UASM,mBAAmB;WACzB;;WAEA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;;WAEA,mBAAmB;;;;;;UAOb;EACf,MAAM;EACN,cAAc;EACd,cAAc;EACd,aAAa;EACb,SAAS;EACT,YAAY;EACZ,OAAO;EACP,MAAM;EACN,SAAS;EACT,YAAY;;KAGF,uBAAuB;KACvB,aAAa,cAAc;;UAOtB,mBAAmB;WACzB;;WAEA;WACA,mBAAmB;;;UAIb,iBAAiB;WACvB;;;;;WAKA;;;UAIM,kBAAkB;WACxB;WACA;;WAEA;;WAEA,gBAAgB;;;;;;;;UASV,kBAAkB;WACxB;;WAEA;WACA,mBAAmB;;;UAIb,iBAAiB;WACvB;WACA,gBAAgB;;;UAIV,mBAAmB;WACzB;WACA;WACA;WACA,eAAe;;;UAIT,kBAAkB;WACxB;;WAEA;;WAEA;;WAEA;;WAEA,mBAAmB;;;;;;UAOb;EACf,OAAO;EACP,WAAW;EACX,UAAU;EACV,OAAO;EACP,UAAU;EACV,WAAW;EACX,MAAM;;KAGI,sBAAsB;KACtB,YAAY,aAAa;;KAGzB,gBAAgB,aAAa,YAAY,aAAa;;UAOjD,aAAa;WACnB;WACA,mBAAmB;;UAOb;EACf,MAAM;;;KAII,aAAa,cAAc,eAAe;KAE1C,oBAAoB;KACpB,UAAU,WAAW;;KAGrB,WAAW,UAAU,eAAe,WAAW;;;;;;;KAQ/C,gBAAgB,KAAK,oBAAoB,KAAK;;KAG9C,iBAAiB,gBAAgB"}
|
|
@@ -36,12 +36,12 @@ interface NodeBase {
|
|
|
36
36
|
}
|
|
37
37
|
/** 記法として解釈されなかった素のテキスト。 */
|
|
38
38
|
interface TextNode extends NodeBase {
|
|
39
|
-
readonly type:
|
|
39
|
+
readonly type: "text";
|
|
40
40
|
readonly value: string;
|
|
41
41
|
}
|
|
42
42
|
/** `[title]` — 同じプロジェクト内のページへのリンク。 */
|
|
43
43
|
interface InternalLink extends NodeBase {
|
|
44
|
-
readonly type:
|
|
44
|
+
readonly type: "internalLink";
|
|
45
45
|
/** 表示テキスト。内部リンクでは target と同じ */
|
|
46
46
|
readonly label: string;
|
|
47
47
|
/** リンク先のページタイトル */
|
|
@@ -49,13 +49,13 @@ interface InternalLink extends NodeBase {
|
|
|
49
49
|
}
|
|
50
50
|
/** 裸の URL、`[url]`、`[url label]`、`[label url]`。 */
|
|
51
51
|
interface ExternalLink extends NodeBase {
|
|
52
|
-
readonly type:
|
|
52
|
+
readonly type: "externalLink";
|
|
53
53
|
readonly label: string;
|
|
54
54
|
readonly target: string;
|
|
55
55
|
}
|
|
56
56
|
/** `[/project/title]` — 別プロジェクトのページへのリンク。 */
|
|
57
57
|
interface ProjectLink extends NodeBase {
|
|
58
|
-
readonly type:
|
|
58
|
+
readonly type: "projectLink";
|
|
59
59
|
readonly label: string;
|
|
60
60
|
/** `/project/title` 形式のまま */
|
|
61
61
|
readonly target: string;
|
|
@@ -65,17 +65,17 @@ interface ProjectLink extends NodeBase {
|
|
|
65
65
|
}
|
|
66
66
|
/** `#tag` — 内部リンクと同じくページを指すが、記法が異なるので別ノードにする。 */
|
|
67
67
|
interface Hashtag extends NodeBase {
|
|
68
|
-
readonly type:
|
|
68
|
+
readonly type: "hashtag";
|
|
69
69
|
readonly value: string;
|
|
70
70
|
}
|
|
71
71
|
/** バッククォートで囲んだインラインコード。 */
|
|
72
72
|
interface InlineCode extends NodeBase {
|
|
73
|
-
readonly type:
|
|
73
|
+
readonly type: "inlineCode";
|
|
74
74
|
readonly value: string;
|
|
75
75
|
}
|
|
76
76
|
/** `[url.png]` / `[[url.png]]` (large) / `[linkUrl imageUrl]` (link 付き)。 */
|
|
77
77
|
interface ImageNode extends NodeBase {
|
|
78
|
-
readonly type:
|
|
78
|
+
readonly type: "image";
|
|
79
79
|
readonly src: string;
|
|
80
80
|
/** `[[...]]` で囲まれた大きい表示 */
|
|
81
81
|
readonly large?: boolean;
|
|
@@ -84,14 +84,14 @@ interface ImageNode extends NodeBase {
|
|
|
84
84
|
}
|
|
85
85
|
/** `[user.icon]` / `[user.icon*N]`。 */
|
|
86
86
|
interface IconNode extends NodeBase {
|
|
87
|
-
readonly type:
|
|
87
|
+
readonly type: "icon";
|
|
88
88
|
readonly user: string;
|
|
89
89
|
/** 連打の個数 (1..20)。記法上省略されていても 1 が入る */
|
|
90
90
|
readonly count: number;
|
|
91
91
|
}
|
|
92
92
|
/** `[$ 数式]`。中身は解釈せず生のまま返す (KaTeX 等に渡す想定)。 */
|
|
93
93
|
interface FormulaNode extends NodeBase {
|
|
94
|
-
readonly type:
|
|
94
|
+
readonly type: "formula";
|
|
95
95
|
readonly value: string;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
@@ -101,7 +101,7 @@ interface FormulaNode extends NodeBase {
|
|
|
101
101
|
* Markdown のように入れ子の強調へ分解せずフラグの集合として表す。
|
|
102
102
|
*/
|
|
103
103
|
interface Decoration extends NodeBase {
|
|
104
|
-
readonly type:
|
|
104
|
+
readonly type: "decoration";
|
|
105
105
|
/** 装飾記号を除いた中身の生テキスト */
|
|
106
106
|
readonly value: string;
|
|
107
107
|
/** 書かれた文字装飾記法の記号を、出現順・重複なしで並べたもの。`[*** x]` なら `['*']` */
|
|
@@ -135,14 +135,14 @@ type InlineNodeType = keyof InlineNodeMap;
|
|
|
135
135
|
type InlineNode = InlineNodeMap[InlineNodeType];
|
|
136
136
|
/** ページの 1 行目。`code:` / `table:` として解釈しない (Cosense ではタイトル専用の行)。 */
|
|
137
137
|
interface TitleBlock extends NodeBase {
|
|
138
|
-
readonly type:
|
|
138
|
+
readonly type: "title";
|
|
139
139
|
/** タイトル行の生テキスト。Cosense ではこれがページの識別子でもある */
|
|
140
140
|
readonly value: string;
|
|
141
141
|
readonly children: readonly InlineNode[];
|
|
142
142
|
}
|
|
143
143
|
/** `code:filename` ブロックの本体 1 行。記法は解釈しない。 */
|
|
144
144
|
interface CodeLine extends NodeBase {
|
|
145
|
-
readonly type:
|
|
145
|
+
readonly type: "codeLine";
|
|
146
146
|
/**
|
|
147
147
|
* ブロックの左端に揃えた中身。ヘッダより 1 段深いところを左端とみなすので、
|
|
148
148
|
* それより深いインデントはコード自身の字下げとして残る。
|
|
@@ -151,33 +151,40 @@ interface CodeLine extends NodeBase {
|
|
|
151
151
|
}
|
|
152
152
|
/** `code:filename` + それより深いインデントの行。 */
|
|
153
153
|
interface CodeBlock extends NodeBase {
|
|
154
|
-
readonly type:
|
|
154
|
+
readonly type: "codeBlock";
|
|
155
155
|
readonly filename: string;
|
|
156
156
|
/** ヘッダ行のインデント。本体行はこれより深い */
|
|
157
157
|
readonly indent: number;
|
|
158
158
|
/** ヘッダ行自身は含まない */
|
|
159
159
|
readonly lines: readonly CodeLine[];
|
|
160
160
|
}
|
|
161
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* テーブルの 1 セル。
|
|
163
|
+
*
|
|
164
|
+
* `children` はセルの中の記法。Cosense Web と同じく、既定ではリンクの記法だけを読み、
|
|
165
|
+
* それ以外は書いたままの文字になる (拡張 `tableCellNotation` で変えられる)。
|
|
166
|
+
*/
|
|
162
167
|
interface TableCell extends NodeBase {
|
|
163
|
-
readonly type:
|
|
168
|
+
readonly type: "tableCell";
|
|
169
|
+
/** セルに書かれた文字列そのまま */
|
|
164
170
|
readonly value: string;
|
|
171
|
+
readonly children: readonly InlineNode[];
|
|
165
172
|
}
|
|
166
173
|
/** テーブルの 1 行。タブ区切りでセルに分割済み。 */
|
|
167
174
|
interface TableRow extends NodeBase {
|
|
168
|
-
readonly type:
|
|
175
|
+
readonly type: "tableRow";
|
|
169
176
|
readonly cells: readonly TableCell[];
|
|
170
177
|
}
|
|
171
178
|
/** `table:name` + それより深いインデントの行。 */
|
|
172
179
|
interface TableBlock extends NodeBase {
|
|
173
|
-
readonly type:
|
|
180
|
+
readonly type: "table";
|
|
174
181
|
readonly name: string;
|
|
175
182
|
readonly indent: number;
|
|
176
183
|
readonly rows: readonly TableRow[];
|
|
177
184
|
}
|
|
178
185
|
/** 通常の行。 */
|
|
179
186
|
interface LineBlock extends NodeBase {
|
|
180
|
-
readonly type:
|
|
187
|
+
readonly type: "line";
|
|
181
188
|
/** 行頭の空白 (半角スペース / タブ / 全角スペース) の文字数 */
|
|
182
189
|
readonly indent: number;
|
|
183
190
|
/** `>` で始まる引用行 */
|
|
@@ -206,7 +213,7 @@ type BlockNode = BlockNodeMap[BlockNodeType];
|
|
|
206
213
|
type TopLevelBlock = TitleBlock | CodeBlock | TableBlock | LineBlock;
|
|
207
214
|
/** パース結果のルート。 */
|
|
208
215
|
interface Page extends NodeBase {
|
|
209
|
-
readonly type:
|
|
216
|
+
readonly type: "page";
|
|
210
217
|
readonly children: readonly TopLevelBlock[];
|
|
211
218
|
}
|
|
212
219
|
interface RootNodeMap {
|
|
@@ -224,9 +231,9 @@ type NodeOfType<K extends AnyNodeType> = AnyNodeMap[K];
|
|
|
224
231
|
* 記法を判定する側は「何のノードか」だけを決め、位置の付与は走査側がまとめて行う。
|
|
225
232
|
* こうしておくと、記法を 1 つ足すたびにオフセット計算を書き足さずに済む。
|
|
226
233
|
*/
|
|
227
|
-
type WithoutPosition<T> = T extends unknown ? Omit<T,
|
|
234
|
+
type WithoutPosition<T> = T extends unknown ? Omit<T, "position"> : never;
|
|
228
235
|
/** 位置を持たないインラインノード。記法ルールの戻り値。 */
|
|
229
236
|
type InlineNodeInit = WithoutPosition<InlineNode>;
|
|
230
237
|
//#endregion
|
|
231
238
|
export { TableCell as A, NodeOfType as C, ProjectLink as D, Position as E, WithoutPosition as F, TextNode as M, TitleBlock as N, RootNodeMap as O, TopLevelBlock as P, NodeBase as S, Point as T, InlineNodeInit as _, BlockNodeMap as a, InternalLink as b, CodeLine as c, FormulaNode as d, Hashtag as f, InlineNode as g, InlineCode as h, BlockNode as i, TableRow as j, TableBlock as k, Decoration as l, ImageNode as m, AnyNodeMap as n, BlockNodeType as o, IconNode as p, AnyNodeType as r, CodeBlock as s, AnyNode as t, ExternalLink as u, InlineNodeMap as v, Page as w, LineBlock as x, InlineNodeType as y };
|
|
232
|
-
//# sourceMappingURL=types-
|
|
239
|
+
//# sourceMappingURL=types-gWMrsXPX.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-gWMrsXPX.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;;;UAkBiB;;WAEN;;WAEA;;WAEA;;;;;;;UAQM;WACN,OAAO;WACP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B,KAAK;;KAG9C,iBAAiB,gBAAgB"}
|
package/dist/utils.cjs
CHANGED
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["childrenOf"],"sources":["../src/utils/visit.ts","../src/utils/links.ts"],"sourcesContent":["/**\n * visit.ts — AST を深さ優先で走査する。外部依存を増やさないための自前実装。\n */\nimport { childrenOf } from
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["childrenOf"],"sources":["../src/utils/visit.ts","../src/utils/links.ts"],"sourcesContent":["/**\n * visit.ts — AST を深さ優先で走査する。外部依存を増やさないための自前実装。\n */\nimport { childrenOf } from \"../ast\"\nimport type { AnyNode, AnyNodeType, NodeOfType } from \"../types\"\n\n/**\n * visitor の戻り値。\n * - 何も返さない — そのまま子へ進む\n * - `'skip'` — このノードの子を辿らない\n * - `'exit'` — 走査全体を打ち切る\n */\n// void にしているのは、undefined にすると値を返さない visitor を渡せなくなるため\nexport type VisitResult = void | \"skip\" | \"exit\"\n\nexport type Visitor<T extends AnyNode> = (node: T, ancestors: readonly AnyNode[]) => VisitResult\n\n/** 木を深さ優先で辿る。`types` を渡すとその型のノードだけが visitor に届く。 */\nexport function visit(tree: AnyNode, visitor: Visitor<AnyNode>): void\nexport function visit<K extends AnyNodeType>(\n tree: AnyNode,\n types: K | readonly K[],\n visitor: Visitor<NodeOfType<K>>,\n): void\nexport function visit(\n tree: AnyNode,\n typesOrVisitor: AnyNodeType | readonly AnyNodeType[] | Visitor<AnyNode>,\n maybeVisitor?: Visitor<AnyNode>,\n): void {\n const visitor = maybeVisitor ?? (typesOrVisitor as Visitor<AnyNode>)\n const types =\n maybeVisitor === undefined\n ? undefined\n : new Set(\n typeof typesOrVisitor === \"string\"\n ? [typesOrVisitor]\n : (typesOrVisitor as readonly AnyNodeType[]),\n )\n\n const walk = (node: AnyNode, ancestors: readonly AnyNode[]): VisitResult => {\n if (types === undefined || types.has(node.type)) {\n const result = visitor(node, ancestors)\n if (result === \"exit\") return \"exit\"\n if (result === \"skip\") return undefined\n }\n const nextAncestors = [...ancestors, node]\n for (const child of childrenOf(node)) {\n if (walk(child, nextAncestors) === \"exit\") return \"exit\"\n }\n return undefined\n }\n\n walk(tree, [])\n}\n\n/** その型の最初のノードを返す。無ければ null。 */\nexport function find<K extends AnyNodeType>(tree: AnyNode, type: K): NodeOfType<K> | null {\n let found: NodeOfType<K> | null = null\n visit(tree, type, (node) => {\n found = node\n return \"exit\"\n })\n return found\n}\n\n/** その型のノードを出現順にすべて集める。 */\nexport function collect<K extends AnyNodeType>(tree: AnyNode, type: K): NodeOfType<K>[] {\n const out: NodeOfType<K>[] = []\n visit(tree, type, (node) => {\n out.push(node)\n })\n return out\n}\n","/**\n * links.ts — AST からリンクと画像を抜き出す。\n */\nimport type { AnyNode, ImageNode, ProjectLink } from \"../types\"\nimport { collect, visit } from \"./visit\"\n\nexport interface CollectLinksOptions {\n /** `[/project/title]` も含めるか (既定: false)。同一プロジェクト内の被リンクだけが要るなら false */\n readonly includeProjectLinks?: boolean\n}\n\n/**\n * 同じプロジェクト内のページを指すリンクを、出現順・重複なしで集める。\n * `[title]` と `#tag` は同じページを指すので同じ 1 件として扱う。\n */\nexport const collectLinks = (tree: AnyNode, options?: CollectLinksOptions): string[] => {\n const out: string[] = []\n const seen = new Set<string>()\n const add = (value: string) => {\n if (value === \"\" || seen.has(value)) return\n seen.add(value)\n out.push(value)\n }\n\n visit(tree, (node) => {\n if (node.type === \"internalLink\") add(node.target)\n else if (node.type === \"hashtag\") add(node.value)\n else if (node.type === \"projectLink\" && options?.includeProjectLinks) add(node.target)\n })\n\n return out\n}\n\n/** ページが参照している外部プロジェクトのリンクを、出現順に集める。 */\nexport const collectProjectLinks = (tree: AnyNode): ProjectLink[] => collect(tree, \"projectLink\")\n\n/** 最初に現れる画像ノード。無ければ null。 */\nexport const firstImage = (tree: AnyNode): ImageNode | null => {\n let found: ImageNode | null = null\n visit(tree, \"image\", (node) => {\n found = node\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AAK,SAAS,iBAAiB,SAAS,qBAAqB,IAAI,KAAK,MAAM;CACvF,CAAC;CAED,OAAO;AACT;;AAGA,MAAa,uBAAuB,SAAiC,QAAQ,MAAM,aAAa;;AAGhG,MAAa,cAAc,SAAoC;CAC7D,IAAI,QAA0B;CAC9B,MAAM,MAAM,UAAU,SAAS;EAC7B,QAAQ;EACR,OAAO;CACT,CAAC;CACD,OAAO;AACT"}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as NodeOfType, D as ProjectLink, m as ImageNode, r as AnyNodeType, t as AnyNode } from "./types-
|
|
1
|
+
import { C as NodeOfType, D as ProjectLink, m as ImageNode, r as AnyNodeType, t as AnyNode } from "./types-gWMrsXPX.cjs";
|
|
2
2
|
//#region src/ast.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* ノードの子を返す。子を持たないノードでは空配列。
|
|
@@ -32,7 +32,7 @@ declare const firstImage: (tree: AnyNode) => ImageNode | null;
|
|
|
32
32
|
* - `'skip'` — このノードの子を辿らない
|
|
33
33
|
* - `'exit'` — 走査全体を打ち切る
|
|
34
34
|
*/
|
|
35
|
-
type VisitResult = void |
|
|
35
|
+
type VisitResult = void | "skip" | "exit";
|
|
36
36
|
type Visitor<T extends AnyNode> = (node: T, ancestors: readonly AnyNode[]) => VisitResult;
|
|
37
37
|
/** 木を深さ優先で辿る。`types` を渡すとその型のノードだけが visitor に届く。 */
|
|
38
38
|
declare function visit(tree: AnyNode, visitor: Visitor<AnyNode>): void;
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../src/ast.ts","../src/utils/links.ts","../src/utils/visit.ts"],"mappings":";;;;;;;;cAiBa,aAAc,MAAM,qBAAmB;;
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../src/ast.ts","../src/utils/links.ts","../src/utils/visit.ts"],"mappings":";;;;;;;;cAiBa,aAAc,MAAM,qBAAmB;;cAwCvC,YAAa,gBAAgB,MAAM;;;UCnD/B;;WAEN;;;;;;cAOE,eAAgB,MAAM,SAAS,UAAU;;cAmBzC,sBAAuB,MAAM,YAAU;;cAGvC,aAAc,MAAM,YAAU;;;;;;;;;KCxB/B;KAEA,QAAQ,UAAU,YAAY,MAAM,GAAG,oBAAoB,cAAc;;iBAGrE,MAAM,MAAM,SAAS,SAAS,QAAQ;iBACtC,MAAM,UAAU,aAC9B,MAAM,SACN,OAAO,aAAa,KACpB,SAAS,QAAQ,WAAW;;iBAkCd,KAAK,UAAU,aAAa,MAAM,SAAS,MAAM,IAAI,WAAW;;iBAUhE,QAAQ,UAAU,aAAa,MAAM,SAAS,MAAM,IAAI,WAAW"}
|