From 7bc02f61612b0d3c80bef79dc00a466287dce2b6 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 23 Mar 2023 12:13:28 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:recycle:=20Selection.lines=E3=81=AE?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E7=BE=A9=E3=82=92=E4=BD=9C=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser/dom/selection.d.ts | 6 +++--- deps/scrapbox.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/browser/dom/selection.d.ts b/browser/dom/selection.d.ts index 946d289..3b9dcf2 100644 --- a/browser/dom/selection.d.ts +++ b/browser/dom/selection.d.ts @@ -2,7 +2,7 @@ /// /// -import { BaseStore } from "../../deps/scrapbox.ts"; +import { BaseLine, BaseStore } from "../../deps/scrapbox.ts"; import { Position } from "./position.ts"; export interface Range { @@ -13,8 +13,8 @@ export interface Range { export declare class Selection extends BaseStore { constructor(); - /** `scrapbox.Page.lines`とほぼ同じ */ - get lines(): unknown[]; + /** 現在のページ本文を取得する */ + get lines(): BaseLine[]; /** 現在の選択範囲を取得する */ getRange(init?: { normalizeOrder: boolean }): Range; diff --git a/deps/scrapbox.ts b/deps/scrapbox.ts index 9185839..e976927 100644 --- a/deps/scrapbox.ts +++ b/deps/scrapbox.ts @@ -1,4 +1,5 @@ export type { + BaseLine, Line, Scrapbox, } from "https://raw.githubusercontent.com/scrapbox-jp/types/0.3.8/userscript.ts"; From 6c8bf79097e58d5a882a9607b06fc9ced0e0b87e Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 23 Mar 2023 12:20:21 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:recycle:=20event=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E3=82=92=E5=8E=B3=E5=AF=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser/dom/cursor.d.ts | 16 ++++++++++++---- browser/dom/selection.d.ts | 2 +- deps/scrapbox.ts | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/browser/dom/cursor.d.ts b/browser/dom/cursor.d.ts index fd35e3d..2f7f7b4 100644 --- a/browser/dom/cursor.d.ts +++ b/browser/dom/cursor.d.ts @@ -16,11 +16,13 @@ export interface SetPositionOptions { * * コード内だと、"mouse"が指定されていた場合があった。詳細は不明 */ - source?: string; + source?: "mouse"; } /** カーソル操作クラス */ -export declare class Cursor extends BaseStore { +export declare class Cursor extends BaseStore< + { source: "mouse" | undefined } | "focusTextInput" | "scroll" | undefined +> { constructor(); /** カーソルの位置を初期化し、editorからカーソルを外す */ @@ -44,7 +46,10 @@ export declare class Cursor extends BaseStore { /** popup menuを消す */ hidePopupMenu(): void; - /** #text-inputにカーソルをfocusし、同時にカーソルを表示する */ + /** #text-inputにカーソルをfocusし、同時にカーソルを表示する + * + * このとき、`event: "focusTextInput"`が発行される + */ focus(): void; /** #text-inputからfocusを外す。カーソルの表示状態は変えない */ @@ -143,8 +148,11 @@ export declare class Cursor extends BaseStore { private sync(): void; private syncNow(): void; private updateTemporalHorizontalPoint(): number; + /** scrollされたときに発火される + * + * このとき`event: "source"`が発行される + */ private emitScroll(): void; - emitChange(event: string): void; private data: Position; private temporalHorizontalPoint: number; diff --git a/browser/dom/selection.d.ts b/browser/dom/selection.d.ts index 3b9dcf2..7486e08 100644 --- a/browser/dom/selection.d.ts +++ b/browser/dom/selection.d.ts @@ -10,7 +10,7 @@ export interface Range { end: Position; } -export declare class Selection extends BaseStore { +export declare class Selection extends BaseStore { constructor(); /** 現在のページ本文を取得する */ diff --git a/deps/scrapbox.ts b/deps/scrapbox.ts index e976927..b764a78 100644 --- a/deps/scrapbox.ts +++ b/deps/scrapbox.ts @@ -2,8 +2,8 @@ export type { BaseLine, Line, Scrapbox, -} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.3.8/userscript.ts"; +} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.4.2/userscript.ts"; export type { BaseStore, -} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.3.8/baseStore.ts"; +} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.4.2/baseStore.ts"; export * from "https://esm.sh/@progfay/scrapbox-parser@8.1.0"; From 4a4585488745c0c373233705348bb9f613e02471 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 23 Mar 2023 12:20:45 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:recycle:=20normalizeOrder=E3=81=AE?= =?UTF-8?q?=E8=AA=AC=E6=98=8E=E3=82=92=E6=9B=B8=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser/dom/selection.d.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/browser/dom/selection.d.ts b/browser/dom/selection.d.ts index 7486e08..df6f530 100644 --- a/browser/dom/selection.d.ts +++ b/browser/dom/selection.d.ts @@ -16,7 +16,11 @@ export declare class Selection extends BaseStore { /** 現在のページ本文を取得する */ get lines(): BaseLine[]; - /** 現在の選択範囲を取得する */ + /** 現在の選択範囲を取得する + * + * @param init 選択範囲の先頭位置がRange.startになるよう並び替えたいときは`init.normalizeOrder`を`true`にする + * @return 現在の選択範囲 + */ getRange(init?: { normalizeOrder: boolean }): Range; /** 選択範囲を変更する */ @@ -25,9 +29,10 @@ export declare class Selection extends BaseStore { /** 選択を解除する */ clear(): void; - /** algorithmがよくわからない + /** 選択範囲の先頭位置がrange.startになるよう並び替える * - * 何らかの条件に基づいて、startとendを入れ替えているのはわかる + * @param range 並び替えたい選択範囲 + * @return 並び替えた選択範囲 */ normalizeOrder(range: Range): Range; From 6e6ea0a9a0b622c46329fe5e1555e2b7f65e0e0b Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 23 Mar 2023 12:53:47 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:recycle:=20Cursor=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9=E3=82=92=E5=8E=B3=E5=AF=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser/dom/cursor.d.ts | 19 +++++++++--- browser/dom/page.d.ts | 69 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 browser/dom/page.d.ts diff --git a/browser/dom/cursor.d.ts b/browser/dom/cursor.d.ts index 2f7f7b4..4518fd6 100644 --- a/browser/dom/cursor.d.ts +++ b/browser/dom/cursor.d.ts @@ -2,8 +2,9 @@ /// /// -import { BaseStore } from "../../deps/scrapbox.ts"; +import { BaseLine, BaseStore } from "../../deps/scrapbox.ts"; import { Position } from "./position.ts"; +import { Page } from "./page.d.ts"; export interface SetPositionOptions { /** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか @@ -25,6 +26,8 @@ export declare class Cursor extends BaseStore< > { constructor(); + public startedWithTouch: boolean; + /** カーソルの位置を初期化し、editorからカーソルを外す */ clear(): void; @@ -52,6 +55,12 @@ export declare class Cursor extends BaseStore< */ focus(): void; + /** #text-inputにfocusがあたっているか返す + * + * `this.focusTextarea`と同値 + */ + get hasFocus(): boolean; + /** #text-inputからfocusを外す。カーソルの表示状態は変えない */ blur(): void; @@ -113,11 +122,11 @@ export declare class Cursor extends BaseStore< | "go-pageup", ): void; - /* `scrapbox.Page.lines`とほぼ同じ */ - get lines(): unknown[]; + /** 現在のページ本文を取得する */ + get lines(): BaseLine[]; - /* `scrapbox.Project.pages`とほぼ同じ */ - get pages(): unknown; + /** 現在のページデータを取得する */ + get page(): Page; private goUp(): void; private goPageUp(): void; diff --git a/browser/dom/page.d.ts b/browser/dom/page.d.ts new file mode 100644 index 0000000..0f9e1b3 --- /dev/null +++ b/browser/dom/page.d.ts @@ -0,0 +1,69 @@ +/// +/// +/// + +import { BaseStore } from "../../deps/scrapbox.ts"; +import { Page as PageData } from "../../deps/scrapbox-rest.ts"; + +export interface SetPositionOptions { + /** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか + * + * @default true + */ + scrollInView?: boolean; + + /** カーソル移動イベントの発生箇所? + * + * コード内だと、"mouse"が指定されていた場合があった。詳細は不明 + */ + source?: "mouse"; +} + +export interface ApiUrlForFetch { + projectName: string; + title: string; + titleHint: string; + followRename: boolean; + search: string; +} + +export interface ApplySnapshotInit { + page: Pick; + prevPage?: Pick; + nextPage?: Pick; +} + +export type PageWithCache = PageData & { cachedAt: number | undefined }; + +/** Scrapboxのページデータを管理する内部クラス + * + * 一部型定義は書きかけ + */ +export declare class Page extends BaseStore< + { source: "mouse" | undefined } | "focusTextInput" | "scroll" | undefined +> { + public initialize(): void; + + private data: PageWithCache; + + public get(): PageWithCache; + + public apiUrlForFetch(init: ApiUrlForFetch): string; + public apiUrlForUpdatePageAccessed(pageId: string): string; + public fetch(): Promise; + + public set(page: PageWithCache): void; + public reset(): void; + public applySnapshot(init: ApplySnapshotInit): void; + setTitle(title: string, init?: { from: string }): void; + get fromCacheStorage(): boolean; + public setPin(pin: number): void; + public delete(): void; + public patch(t: unknown): void; + public patchChanges( + t: unknown, + init?: { from: string }, + ): Promise; + get hasSelfBackLink(): boolean; + public requestFetchApiCacheToServiceWorker(): unknown; +} From 06285ab4d880144e01c0239dde02dff51172006c Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 23 Mar 2023 13:05:22 +0900 Subject: [PATCH 5/5] :rotating_light: --- browser/dom/extractCodeFiles.test.ts | 575 +-------------------------- browser/dom/sample-lines1.json | 454 +++++++++++++++++++++ 2 files changed, 456 insertions(+), 573 deletions(-) create mode 100644 browser/dom/sample-lines1.json diff --git a/browser/dom/extractCodeFiles.test.ts b/browser/dom/extractCodeFiles.test.ts index 436a99b..724e42b 100644 --- a/browser/dom/extractCodeFiles.test.ts +++ b/browser/dom/extractCodeFiles.test.ts @@ -1,582 +1,11 @@ import { extractCodeFiles } from "./extractCodeFiles.ts"; import { Line } from "../../deps/scrapbox.ts"; import { assertSnapshot } from "../../deps/testing.ts"; - -const sample: Line[] = [ - { - "id": "63b7aeeb5defe7001ddae116", - "text": "コードブロック記法", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982645, - "updated": 1672982645, - "title": true, - "section": { - "number": 0, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b0761280f00000c9bc21", - "text": "ここでは[コードブロック]を表現する[scrapbox記法]を示す", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982645, - "updated": 1672982671, - "section": { - "number": 0, - "start": false, - "end": false, - }, - "nodes": [ - "ここでは", - { - "type": "link", - "unit": { - "page": "コードブロック", - }, - "children": "コードブロック", - }, - "を表現する", - { - "type": "link", - "unit": { - "page": "scrapbox記法", - }, - "children": "scrapbox記法", - }, - "を示す", - ], - }, - { - "id": "63b7b0791280f00000c9bc22", - "text": "", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982648, - "updated": 1672982648, - "section": { - "number": 0, - "start": false, - "end": true, - }, - "nodes": "", - }, - { - "id": "63b7b12b1280f00000c9bc3d", - "text": "サンプル", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982826, - "updated": 1672982828, - "section": { - "number": 1, - "start": true, - "end": false, - }, - "nodes": "サンプル", - }, - { - "id": "63b7b12c1280f00000c9bc3e", - "text": " from [/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982828, - "updated": 1672982835, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": { - "type": "indent", - "unit": { - "whole": " from [/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]", - "tag": " ", - "content": "from [/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]", - }, - "children": [ - "from ", - { - "type": "link", - "unit": { - "project": "villagepump", - "page": "記法サンプル", - "line": "61dd289e7838e30000dc9cb5", - }, - "children": "/villagepump/記法サンプル#61dd289e7838e30000dc9cb5", - }, - ], - }, - }, - { - "id": "63b7b1261280f00000c9bc26", - "text": "code:コードブロック.py", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982821, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "py", - "filename": "コードブロック.py", - "indent": 1, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc27", - "text": ' print("Hello World!")', - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "py", - "filename": "コードブロック.py", - "indent": 1, - "start": false, - "end": true, - }, - }, - { - "id": "63b7b1261280f00000c9bc28", - "text": "リンクなしコードブロック", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": "リンクなしコードブロック", - }, - { - "id": "63b7b1261280f00000c9bc29", - "text": "code:py", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "py", - "filename": "py", - "indent": 1, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc2a", - "text": ' print("Hello World!")', - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "py", - "filename": "py", - "indent": 1, - "start": false, - "end": true, - }, - }, - { - "id": "63b7b1261280f00000c9bc2b", - "text": "インデントつき", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": "インデントつき", - }, - { - "id": "63b7b1261280f00000c9bc2c", - "text": " code:インデント.md", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "md", - "filename": "インデント.md", - "indent": 2, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc2d", - "text": " - インデント", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "md", - "filename": "インデント.md", - "indent": 2, - "start": false, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc2e", - "text": " - インデント", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "md", - "filename": "インデント.md", - "indent": 2, - "start": false, - "end": true, - }, - }, - { - "id": "63b7b1261280f00000c9bc2f", - "text": "言語を強制", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": "言語を強制", - }, - { - "id": "63b7b1261280f00000c9bc30", - "text": " code:python(js)", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "js", - "filename": "python", - "indent": 2, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc31", - "text": ' console.log("I\'m JavaScript");', - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "js", - "filename": "python", - "indent": 2, - "start": false, - "end": true, - }, - }, - { - "id": "63b7b1261280f00000c9bc32", - "text": "文芸的プログラミング", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982825, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": "文芸的プログラミング", - }, - { - "id": "63b7b1261280f00000c9bc33", - "text": " 標準ヘッダファイルをインクルード", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": { - "type": "indent", - "unit": { - "whole": " 標準ヘッダファイルをインクルード", - "tag": " ", - "content": "標準ヘッダファイルをインクルード", - }, - "children": "標準ヘッダファイルをインクルード", - }, - }, - { - "id": "63b7b1261280f00000c9bc34", - "text": " code:main.cpp", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc35", - "text": " #include ", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": false, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc36", - "text": " ", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": false, - "end": true, - }, - }, - { - "id": "63b7b1261280f00000c9bc37", - "text": " main函数の定義", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "nodes": { - "type": "indent", - "unit": { - "whole": " main函数の定義", - "tag": " ", - "content": "main函数の定義", - }, - "children": "main函数の定義", - }, - }, - { - "id": "63b7b1261280f00000c9bc38", - "text": " code:main.cpp", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": true, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc39", - "text": " int main() {", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": false, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc3a", - "text": - ' std::cout << "Hello, C++" << "from scrapbox.io" << std::endl;', - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": false, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc3b", - "text": " }", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": false, - "end": false, - }, - }, - { - "id": "63b7b1261280f00000c9bc3c", - "text": " ", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982822, - "updated": 1672982822, - "section": { - "number": 1, - "start": false, - "end": false, - }, - "codeBlock": { - "lang": "cpp", - "filename": "main.cpp", - "indent": 3, - "start": false, - "end": true, - }, - }, - { - "id": "63b7b0911280f00000c9bc23", - "text": "", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982673, - "updated": 1672982673, - "section": { - "number": 1, - "start": false, - "end": true, - }, - "nodes": "", - }, - { - "id": "63b7b0911280f00000c9bc24", - "text": "#2023-01-06 14:24:35 ", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982673, - "updated": 1672982674, - "section": { - "number": 2, - "start": true, - "end": false, - }, - "nodes": [ - { - "type": "hashTag", - "unit": { - "page": "2023-01-06", - "tag": "#", - }, - "children": "#2023-01-06", - }, - " 14:24:35 ", - ], - }, - { - "id": "63b7b0931280f00000c9bc25", - "text": "", - "userId": "5ef2bdebb60650001e1280f0", - "created": 1672982674, - "updated": 1672982674, - "section": { - "number": 2, - "start": false, - "end": true, - }, - "nodes": "", - }, -]; +import sample from "./sample-lines1.json" assert { type: "json" }; Deno.test("extractCodeFiles", async (t) => { await assertSnapshot( t, - extractCodeFiles(sample), + extractCodeFiles(sample as Line[]), ); }); diff --git a/browser/dom/sample-lines1.json b/browser/dom/sample-lines1.json new file mode 100644 index 0000000..4135dfe --- /dev/null +++ b/browser/dom/sample-lines1.json @@ -0,0 +1,454 @@ +[ + { + "id": "63b7aeeb5defe7001ddae116", + "text": "コードブロック記法", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982645, + "updated": 1672982645, + "title": true, + "section": { "number": 0, "start": true, "end": false } + }, + { + "id": "63b7b0761280f00000c9bc21", + "text": "ここでは[コードブロック]を表現する[scrapbox記法]を示す", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982645, + "updated": 1672982671, + "section": { "number": 0, "start": false, "end": false }, + "nodes": [ + "ここでは", + { + "type": "link", + "unit": { + "page": "コードブロック", + "content": "コードブロック", + "whole": "[コードブロック]" + }, + "children": "コードブロック" + }, + "を表現する", + { + "type": "link", + "unit": { + "page": "scrapbox記法", + "content": "scrapbox記法", + "whole": "[scrapbox記法]" + }, + "children": "scrapbox記法" + }, + "を示す" + ] + }, + { + "id": "63b7b0791280f00000c9bc22", + "text": "", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982648, + "updated": 1672982648, + "section": { "number": 0, "start": false, "end": true }, + "nodes": "" + }, + { + "id": "63b7b12b1280f00000c9bc3d", + "text": "サンプル", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982826, + "updated": 1672982828, + "section": { "number": 1, "start": true, "end": false }, + "nodes": "サンプル" + }, + { + "id": "63b7b12c1280f00000c9bc3e", + "text": " from [/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982828, + "updated": 1672982835, + "section": { "number": 1, "start": false, "end": false }, + "nodes": { + "type": "indent", + "unit": { + "whole": " from [/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]", + "tag": " ", + "content": "from [/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]" + }, + "children": [ + "from ", + { + "type": "link", + "unit": { + "project": "villagepump", + "page": "記法サンプル", + "line": "61dd289e7838e30000dc9cb5", + "content": "/villagepump/記法サンプル#61dd289e7838e30000dc9cb5", + "whole": "[/villagepump/記法サンプル#61dd289e7838e30000dc9cb5]" + }, + "children": "/villagepump/記法サンプル#61dd289e7838e30000dc9cb5" + } + ] + } + }, + { + "id": "63b7b1261280f00000c9bc26", + "text": "code:コードブロック.py", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982821, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "py", + "filename": "コードブロック.py", + "indent": 1, + "start": true, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc27", + "text": " print(\"Hello World!\")", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "py", + "filename": "コードブロック.py", + "indent": 1, + "start": false, + "end": true + } + }, + { + "id": "63b7b1261280f00000c9bc28", + "text": "無名コードブロック", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672983021, + "section": { "number": 1, "start": false, "end": false }, + "nodes": "無名コードブロック" + }, + { + "id": "63b7b1261280f00000c9bc29", + "text": "code:py", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "py", + "filename": "py", + "indent": 1, + "start": true, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc2a", + "text": " print(\"Hello World!\")", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "py", + "filename": "py", + "indent": 1, + "start": false, + "end": true + } + }, + { + "id": "63b7b1261280f00000c9bc2b", + "text": "インデントつき", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "nodes": "インデントつき" + }, + { + "id": "63b7b1261280f00000c9bc2c", + "text": " code:インデント.md", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "md", + "filename": "インデント.md", + "indent": 2, + "start": true, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc2d", + "text": " - インデント", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "md", + "filename": "インデント.md", + "indent": 2, + "start": false, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc2e", + "text": " - インデント", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "md", + "filename": "インデント.md", + "indent": 2, + "start": false, + "end": true + } + }, + { + "id": "63b7b1261280f00000c9bc2f", + "text": "言語を強制", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "nodes": "言語を強制" + }, + { + "id": "63b7b1261280f00000c9bc30", + "text": " code:python(js)", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "js", + "filename": "python", + "indent": 2, + "start": true, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc31", + "text": " console.log(\"I'm JavaScript\");", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "js", + "filename": "python", + "indent": 2, + "start": false, + "end": true + } + }, + { + "id": "63b7b1261280f00000c9bc32", + "text": "文芸的プログラミング", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982825, + "section": { "number": 1, "start": false, "end": false }, + "nodes": "文芸的プログラミング" + }, + { + "id": "63b7b1261280f00000c9bc33", + "text": " 標準ヘッダファイルをインクルード", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "nodes": { + "type": "indent", + "unit": { + "whole": " 標準ヘッダファイルをインクルード", + "tag": " ", + "content": "標準ヘッダファイルをインクルード" + }, + "children": "標準ヘッダファイルをインクルード" + } + }, + { + "id": "63b7b1261280f00000c9bc34", + "text": " code:main.cpp", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": true, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc35", + "text": " #include ", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": false, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc36", + "text": " ", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": false, + "end": true + } + }, + { + "id": "63b7b1261280f00000c9bc37", + "text": " main函数の定義", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "nodes": { + "type": "indent", + "unit": { + "whole": " main函数の定義", + "tag": " ", + "content": "main函数の定義" + }, + "children": "main函数の定義" + } + }, + { + "id": "63b7b1261280f00000c9bc38", + "text": " code:main.cpp", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": true, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc39", + "text": " int main() {", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": false, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc3a", + "text": " std::cout << \"Hello, C++\" << \"from scrapbox.io\" << std::endl;", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": false, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc3b", + "text": " }", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": false, + "end": false + } + }, + { + "id": "63b7b1261280f00000c9bc3c", + "text": " ", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982822, + "updated": 1672982822, + "section": { "number": 1, "start": false, "end": false }, + "codeBlock": { + "lang": "cpp", + "filename": "main.cpp", + "indent": 3, + "start": false, + "end": true + } + }, + { + "id": "63b7b0911280f00000c9bc23", + "text": "", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982673, + "updated": 1672982673, + "section": { "number": 1, "start": false, "end": true }, + "nodes": "" + }, + { + "id": "63b7b0911280f00000c9bc24", + "text": "#2023-01-06 14:24:35 ", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982673, + "updated": 1672982674, + "section": { "number": 2, "start": true, "end": false }, + "nodes": [ + { + "type": "hashTag", + "unit": { + "page": "2023-01-06", + "tag": "#", + "content": "2023-01-06", + "whole": "#2023-01-06" + }, + "children": "#2023-01-06" + }, + " 14:24:35 " + ] + }, + { + "id": "63b7b0931280f00000c9bc25", + "text": "", + "userId": "5ef2bdebb60650001e1280f0", + "created": 1672982674, + "updated": 1672982674, + "section": { "number": 2, "start": false, "end": true }, + "nodes": "" + } +]