Skip to content

Commit bed9cdc

Browse files
committed
refactor(test): Move getPageMetadataFromLine and getHelpfeels tests into JSDoc comments.
1 parent 658cb35 commit bed9cdc

File tree

2 files changed

+91
-97
lines changed

2 files changed

+91
-97
lines changed

websocket/getPageMetadataFromLines.test.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.

websocket/getPageMetadataFromLines.ts

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,85 @@ import { parseYoutube } from "../parser/youtube.ts";
55

66
/** Extract metadata from Scrapbox page text
77
*
8-
* This function parses a Scrapbox page and extracts various types of metadata:
8+
* ```ts
9+
* import { assertEquals } from "@std/assert/equals";
10+
*
11+
* const text = `test page
12+
* [normal]link
13+
* but \`this [link]\` is not a link
14+
*
15+
* code:code
16+
* Links [link] and images [https://scrapbox.io/files/65f29c0c9045b5002522c8bb.svg] in code blocks should be ignored
17+
*
18+
* ? Need help with setup!!
19+
*
20+
* table:infobox
21+
* Name [scrapbox.icon]
22+
* Address Add [link2] here
23+
* Phone Adding # won't create a link
24+
* Strengths List about 3 items
25+
*
26+
* \#hashtag is recommended
27+
* [/forum-en] links should be excluded
28+
* [/help-en/] too
29+
* [/icons/example.icon][takker.icon]
30+
* [/help-en/external-link]
31+
*
32+
* Prepare thumbnail
33+
* [https://scrapbox.io/files/65f29c24974fd8002333b160.svg]
34+
*
35+
* [https://scrapbox.io/files/65e7f4413bc95600258481fb.svg https://scrapbox.io/files/65e7f82e03949c0024a367d0.svg]`;
36+
*
37+
* assertEquals(getPageMetadataFromLines(text), [
38+
* "test page",
39+
* [
40+
* "normal",
41+
* "link2",
42+
* "hashtag",
43+
* ],
44+
* [
45+
* "/help-en/external-link",
46+
* ],
47+
* [
48+
* "scrapbox",
49+
* "takker",
50+
* ],
51+
* "https://scrapbox.io/files/65f29c24974fd8002333b160.svg",
52+
* [
53+
* "[normal]link",
54+
* "but `this [link]` is not a link",
55+
* "`Links [link] and images [https://scrapbox.io/files/65f29c0c9045b5002522c8bb.svg] in code blocks should be ignored`",
56+
* "`? Need help with setup!!`",
57+
* "#hashtag is recommended",
58+
* ],
59+
* [
60+
* "65f29c24974fd8002333b160",
61+
* "65e7f82e03949c0024a367d0",
62+
* "65e7f4413bc95600258481fb",
63+
* ],
64+
* [
65+
* "Need help with setup!!",
66+
* ],
67+
* [
68+
* "Name\t[scrapbox.icon]",
69+
* "Address\tAdd [link2] here",
70+
* "Phone\tAdding # won't create a link",
71+
* "Strengths\tList about 3 items",
72+
* ],
73+
* 25,
74+
* 659,
75+
* ]);
76+
* ```
77+
*
78+
* @param text - Raw text content of a Scrapbox page
79+
* @returns A tuple containing `[links, projectLinks, icons, image, files, helpfeels, infoboxDefinition]`
980
* - links: Regular page links and hashtags
1081
* - projectLinks: Links to pages in other projects
1182
* - icons: User icons and decorative icons
12-
* - image: First image or YouTube thumbnail for page preview
83+
* - image: First image or YouTube thumbnail for page preview, which can be null if no suitable preview image is found
1384
* - files: Attached file IDs
1485
* - helpfeels: Questions or help requests (lines starting with "?")
1586
* - infoboxDefinition: Structured data from infobox tables
16-
*
17-
* @param text - Raw text content of a Scrapbox page
18-
* @returns A tuple containing [links, projectLinks, icons, image, files, helpfeels, infoboxDefinition]
19-
* where image can be null if no suitable preview image is found
2087
*/
2188
export const getPageMetadataFromLines = (
2289
text: string,
@@ -218,6 +285,24 @@ const cutId = (link: string): string => link.replace(/#[a-f\d]{24,32}$/, "");
218285
* Helpfeel is a Scrapbox notation for questions and help requests.
219286
* Lines starting with "?" are considered Helpfeel entries and are
220287
* used to collect questions and support requests within a project.
288+
*
289+
* ```ts
290+
* import { assertEquals } from "@std/assert/equals";
291+
*
292+
* const text = `test page
293+
* [normal]link
294+
* but \`this [link]\` is not a link
295+
*
296+
* code:code
297+
* Links [link] and images [https://scrapbox.io/files/65f29c0c9045b5002522c8bb.svg] in code blocks should be ignored
298+
*
299+
* ? Need help with setup!!
300+
* `;
301+
*
302+
* assertEquals(getHelpfeels(text.split("\n").map((text) => ({ text }))), [
303+
* "Need help with setup!!",
304+
* ]);
305+
* ```
221306
*/
222307
export const getHelpfeels = (lines: Pick<BaseLine, "text">[]): string[] =>
223308
lines.flatMap(({ text }) =>

0 commit comments

Comments
 (0)