Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Catch up with the latest API of scrapbox #59

Merged
merged 1 commit into from
Dec 21, 2024
Merged
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
732 changes: 719 additions & 13 deletions blocks.test.ts

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export type Line =
/** 画像を並べているときのみ生える */
numberOfImages?: number;

/** 引用文のときのみ生える */
quoteLine?: true;

/** 中に含まれるnodes */
nodes: Node | NodeWithoutIndent[];
get nodes(): Node | NodeWithoutIndent[];
});

/** the type which represents a line in a block */
Expand All @@ -62,6 +65,8 @@ export interface CodeBlock extends Block {

/** the file name of the code block */
filename: string;

hasCursor: boolean;
}

/** the type which represents a line in a table block */
Expand Down
4 changes: 2 additions & 2 deletions node/anchor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** Anchor埋め込み */
Expand All @@ -12,7 +12,7 @@ export interface Anchor {
children: PlainText;
}

export interface AnchorUnit extends Unit {
export interface AnchorUnit extends BracketUnit {
/** Anchor video ID */
videoId: string;

Expand Down
4 changes: 2 additions & 2 deletions node/audio.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** 音声埋め込み */
export interface Audio {
type: "audio";

/** 構文解析結果 */
unit: Unit;
unit: BracketUnit;

/** scrapboxにuploadされたfileのID
*
Expand Down
4 changes: 2 additions & 2 deletions node/audioLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** タイトル付き音声 */
Expand All @@ -18,7 +18,7 @@ export interface AudioLink {
children: PlainText;
}

export interface AudioLinkUnit extends Unit {
export interface AudioLinkUnit extends BracketUnit {
/** 音声のURL */
link: string;

Expand Down
4 changes: 2 additions & 2 deletions node/blank.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** 空白記法 */
export interface Blank {
type: "blank";

/** 構文解析結果 */
unit: Unit;
unit: BracketUnit;

/** the same as `unit.content` */
children: PlainText;
Expand Down
7 changes: 6 additions & 1 deletion node/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export interface Code {
type: "code";

/** 構文解析結果 */
unit: Unit;
unit: CodeUnit;

/** the same as `unit.content` */
children: PlainText;
}

export interface CodeUnit extends Unit {
content: string;
whole: `\`${string}\``;
}
6 changes: 4 additions & 2 deletions node/decoration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";
import type { Formula } from "./formula.ts";
import type { Link } from "./link.ts";
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface Decoration {
children: NodeInDecoration | NodeInDecoration[];
}

export interface DecorationUnit extends Unit {
export interface DecorationUnit extends BracketUnit {
/** 文字装飾記号 */
deco: string;

Expand All @@ -72,4 +72,6 @@ export interface DecorationUnit extends Unit {

/** 下線記号`_`を含むとき`true` */
underline: boolean;

whole: `[${string} ${string}]`;
}
11 changes: 7 additions & 4 deletions node/formula.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Unit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";
import type { BracketUnit } from "./unit.ts";

/** 数式記法 */
export interface Formula {
Expand All @@ -9,13 +8,17 @@ export interface Formula {
unit: FormulaUnit;

/** the same as `unit.content` */
children: PlainText;
children: `$ ${string}`;
}

export interface FormulaUnit extends Unit {
export interface FormulaUnit extends BracketUnit {
/** KaTeX text
*
* `content` から`$ `を外したもの
*/
formula: string;

content: `$ ${string}`;

whole: `[$ ${string}]`;
}
15 changes: 13 additions & 2 deletions node/googleMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** Location記法 */
Expand All @@ -12,7 +12,9 @@ export interface GoogleMap {
children: PlainText;
}

export interface GoogleMapUnit extends Unit {
declare const unit: GoogleMapUnit;

export interface GoogleMapUnit extends BracketUnit {
/** 緯度 */
latitude: number;

Expand All @@ -24,4 +26,13 @@ export interface GoogleMapUnit extends Unit {

/** 地点の名前 */
title?: string;
content:
| `${"N" | "S"}${number},${"E" | "W"}${number}${`,Z${number}` | ""}`
| `${"N" | "S"}${number},${"E" | "W"}${number}${
| `,Z${number}`
| ""} ${string}`
| `${string} ${"N" | "S"}${number},${"E" | "W"}${number}${
| `,Z${number}`
| ""}`;
whole: `[${this["content"]}]`;
}
30 changes: 24 additions & 6 deletions node/gyazo.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit, DoubleBracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** Gyazoから引っ張ってきた画像の画像記法 */
export interface Gyazo extends GyazoBase {
export interface Gyazo {
type: "gyazo";

/** 構文解析結果 */
unit: GyazoUnit;

/** the same as `unit.content` */
children: PlainText;
}

/** Gyazoから引っ張ってきた画像の強調画像記法 */
export interface StrongGyazo extends GyazoBase {
export interface StrongGyazo {
type: "strongGyazo";
}

export interface GyazoBase {
/** 構文解析結果 */
unit: Unit;
unit: StrongGyazoUnit;

/** the same as `unit.content` */
children: PlainText;
}

export interface GyazoUnit extends BracketUnit {
content: `http${"s" | ""}://${`${string}.` | ""}gyazo.com/${string}${
| `.${string}`
| "/raw"
| ""}`;
}

export interface StrongGyazoUnit extends DoubleBracketUnit {
content: `http${"s" | ""}://${`${string}.` | ""}gyazo.com/${string}${
| `.${string}`
| "/raw"
| ""}`;
}
22 changes: 18 additions & 4 deletions node/gyazoLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Unit } from "./unit.ts";
import type { BracketUnit, DoubleBracketUnit } from "./unit.ts";
import type { PlainText } from "./plainText.ts";

/** Gyazoから引っ張ってきた画像のリンク付き画像記法 */
Expand All @@ -16,15 +16,29 @@ export interface StrongGyazoLink {
type: "strongGyazoLink";

/** 構文解析結果 */
unit: GyazoLinkUnit;
unit: StrongGyazoLinkUnit;

/** the same as `unit.content` */
children: PlainText;
}

export interface GyazoLinkUnit extends Unit {
export interface GyazoLinkUnit extends BracketUnit {
/** 画像のURL */
gyazo: `http${"s" | ""}://${`${string}.` | ""}gyazo.com/${string}${
| `.${string}`
| "/raw"
| ""}`;

/** 埋め込まれたリンクのURL */
link: string;
}

export interface StrongGyazoLinkUnit extends DoubleBracketUnit {
/** 画像のURL */
gyazo: string;
gyazo: `http${"s" | ""}://${`${string}.` | ""}gyazo.com/${string}${
| `.${string}`
| "/raw"
| ""}`;

/** 埋め込まれたリンクのURL */
link: string;
Expand Down
11 changes: 8 additions & 3 deletions node/hashTag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { NodeWithoutIndent } from "./node.ts";
import type { Unit } from "./unit.ts";

/** hashtag */
Expand All @@ -8,13 +7,19 @@ export interface HashTag {
/** 構文解析結果 */
unit: HashTagUnit;

/** 中に含まれるNodes */
children: NodeWithoutIndent | NodeWithoutIndent[];
/** same as {@linkcode HashTagUnit.content} */
children: `#${string}`;
}

export interface HashTagUnit extends Unit {
/** page title */
page: string;

tag: "#";

/** page title */
get content(): string;

/** raw text */
get whole(): `#${string}`;
}
81 changes: 75 additions & 6 deletions node/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export interface Icon {
type: "icon";

/** 構文解析結果 */
unit: IconUnit;
unit:
| IconUnit<false>
| ProjectIconUnit<false>
| RepeatIconUnit<false>
| RepeatProjectIconUnit<false>;

/** the same as `unit.content` */
children: PlainText;
Expand All @@ -17,25 +21,90 @@ export interface StrongIcon {
type: "strong-icon";

/** 構文解析結果 */
unit: IconUnit;
unit:
| IconUnit<true>
| ProjectIconUnit<true>
| RepeatIconUnit<true>
| RepeatProjectIconUnit<true>;

/** the same as `unit.content` */
children: PlainText;
}

export interface IconUnit extends Unit {
/** アイコンがあるproject name
export interface IconUnit<Strong extends boolean = false> extends Unit {
/** アイコンがあるページのタイトル */
page: string;

/** 繰り返し回数
*
* 同じprojectのアイコンのときは省略される
* 最大1000
*/
project?: string;
size: 1;

/** icon syntax */
get content(): `${string}.icon`;

/** raw text */
get whole(): Strong extends true ? `[[${string}.icon]]` : `[${string}.icon]`;
}

export interface ProjectIconUnit<Strong extends boolean> extends Unit {
/** アイコンがあるproject name */
project: string;

/** アイコンがあるページのタイトル */
page: string;

/** 繰り返し回数
*
* 最大1000
*/
size: 1;

/** icon syntax */
get content(): `/${string}/${string}.icon`;

/** raw text */
get whole(): Strong extends true ? `[[/${string}/${string}.icon]]`
: `[/${string}/${string}.icon]`;
}

export interface RepeatIconUnit<Strong extends boolean> extends Unit {
/** アイコンがあるページのタイトル */
page: string;

/** 繰り返し回数
*
* 最大1000
*/
size: number;

/** icon syntax */
get content(): `${string}.icon${"*" | "x"}${number}`;

/** raw text */
get whole(): Strong extends true ? `[[${string}.icon${"*" | "x"}${number}]]`
: `[${string}.icon${"*" | "x"}${number}]`;
}

export interface RepeatProjectIconUnit<Strong extends boolean> extends Unit {
/** アイコンがあるproject name */
project: string;

/** アイコンがあるページのタイトル */
page: string;

/** 繰り返し回数
*
* 最大1000
*/
size: number;

/** icon syntax */
get content(): `/${string}/${string}.icon${"*" | "x"}${number}`;

/** raw text */
get whole(): Strong extends true
? `[[/${string}/${string}.icon${"*" | "x"}${number}]]`
: `[/${string}/${string}.icon${"*" | "x"}${number}]`;
}
Loading
Loading