Skip to content

Commit 4bcb785

Browse files
authored
Merge pull request #1628 from progfay/jsr-docs
add documents for JSR
2 parents 6e0bcf5 + 7601768 commit 4bcb785

File tree

10 files changed

+97
-0
lines changed

10 files changed

+97
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ parse Scrapbox notation to JavaScript Object
1414
$ npm i @progfay/scrapbox-parser
1515
```
1616

17+
Also, you can install `@progfay/scrapbox-parser` via [JSR](https://jsr.io/@progfay/scrapbox-parser).
18+
1719
## Usage
1820

1921
```js

src/block/CodeBlock.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export interface CodeBlockPack {
55
rows: Row[];
66
}
77

8+
/**
9+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67df | code block} type
10+
*/
811
export interface CodeBlock {
912
indent: number;
1013
type: "codeBlock";

src/block/Line.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export interface LinePack {
88
rows: [Row];
99
}
1010

11+
/**
12+
* Scrapbox line type
13+
*/
1114
export interface Line {
1215
indent: number;
1316
type: "line";

src/block/Row.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Scrapbox row type
3+
*/
14
export interface Row {
25
indent: number;
36
text: string;

src/block/Table.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export interface TablePack {
88
rows: Row[];
99
}
1010

11+
/**
12+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58795996651ee5000012d4c7 | table} type
13+
*/
1114
export interface Table {
1215
indent: number;
1316
type: "table";

src/block/Title.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export interface TitlePack {
55
rows: [Row];
66
}
77

8+
/**
9+
* Scrapbox title type
10+
*/
811
export interface Title {
912
type: "title";
1013
text: string;

src/block/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import type { CodeBlock } from "./CodeBlock";
99
import type { Table } from "./Table";
1010
import type { Line } from "./Line";
1111

12+
/**
13+
* Scrapbox block type
14+
*/
1215
export type Block = Title | CodeBlock | Table | Line;
1316

1417
export const convertToBlock = (pack: Pack): Block => {

src/block/node/DecorationNode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type AsteriskDecorationChar =
4343
| "*-9"
4444
| "*-10";
4545

46+
/**
47+
* character type of decoration
48+
*/
4649
export type Decoration = Exclude<DecorationChar, "*"> | AsteriskDecorationChar;
4750

4851
const createDecorationNode: NodeCreator<DecorationNode | PlainNode> = (

src/block/node/type.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,112 @@ interface BaseNode {
44
raw: string;
55
}
66

7+
/**
8+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67d8 | quote node} type
9+
*/
710
export interface QuoteNode extends BaseNode {
811
type: "quote";
912
nodes: Node[];
1013
}
1114

15+
/**
16+
* Scrapbox {@link https://scrapbox.io/help-jp/Helpfeel%E8%A8%98%E6%B3%95 | Helpfeel node} type
17+
*/
1218
export interface HelpfeelNode extends BaseNode {
1319
type: "helpfeel";
1420
text: string;
1521
}
1622

23+
/**
24+
* Scrapbox {@link https://scrapbox.io/help-jp/%E3%81%9D%E3%81%AE%E4%BB%96%E3%81%AE%E6%9B%B8%E3%81%8D%E6%96%B9#5cfa1ea397c291000095c81e | strong image node} type
25+
*/
1726
export interface StrongImageNode extends BaseNode {
1827
type: "strongImage";
1928
src: string;
2029
}
2130

31+
/**
32+
* Scrapbox {@link https://scrapbox.io/help/Icon#5ec273358ee92a000078cafe | strong icon node} type
33+
*/
2234
export interface StrongIconNode extends BaseNode {
2335
type: "strongIcon";
2436
pathType: "root" | "relative";
2537
path: string;
2638
}
2739

40+
/**
41+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67cb | strong node} type
42+
*/
2843
export interface StrongNode extends BaseNode {
2944
type: "strong";
3045
nodes: Node[];
3146
}
3247

48+
/**
49+
* Scrapbox {@link https://scrapbox.io/help/Syntax#5e7c7a17651ee50000d77b2e | formula node} type
50+
*/
3351
export interface FormulaNode extends BaseNode {
3452
type: "formula";
3553
formula: string;
3654
}
3755

56+
/**
57+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67cc | decoration node} type
58+
*/
3859
export interface DecorationNode extends BaseNode {
3960
type: "decoration";
4061
rawDecos: string;
4162
decos: Decoration[];
4263
nodes: Node[];
4364
}
4465

66+
/**
67+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67db | code node} type
68+
*/
4569
export interface CodeNode extends BaseNode {
4670
type: "code";
4771
text: string;
4872
}
4973

74+
/**
75+
* Scrapbox {@link https://scrapbox.io/help/Code_notation#587d557d651ee50000dc693d | command line node} type
76+
*/
5077
export interface CommandLineNode extends BaseNode {
5178
type: "commandLine";
5279
symbol: string;
5380
text: string;
5481
}
5582

83+
/**
84+
* Scrapbox blank node type
85+
*/
5686
export interface BlankNode extends BaseNode {
5787
type: "blank";
5888
text: string;
5989
}
6090

91+
/**
92+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67b8 | image node} type
93+
*/
6194
export interface ImageNode extends BaseNode {
6295
type: "image";
6396
src: string;
6497
link: string;
6598
}
6699

100+
/**
101+
* Scrapbox {@link https://scrapbox.io/help/Link | link node} type
102+
*/
67103
export interface LinkNode extends BaseNode {
68104
type: "link";
69105
pathType: "absolute" | "root" | "relative";
70106
href: string;
71107
content: string;
72108
}
73109

110+
/**
111+
* Scrapbox {@link https://scrapbox.io/help-jp/Location%E8%A8%98%E6%B3%95 | Google Map node} type
112+
*/
74113
export interface GoogleMapNode extends BaseNode {
75114
type: "googleMap";
76115
latitude: number;
@@ -80,29 +119,44 @@ export interface GoogleMapNode extends BaseNode {
80119
url: string;
81120
}
82121

122+
/**
123+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67c7 | icon node} type
124+
*/
83125
export interface IconNode extends BaseNode {
84126
type: "icon";
85127
pathType: "root" | "relative";
86128
path: string;
87129
}
88130

131+
/**
132+
* Scrapbox {@link https://scrapbox.io/help/Syntax#58348ae2651ee500008d67d5 | hash tag node} type
133+
*/
89134
export interface HashTagNode extends BaseNode {
90135
type: "hashTag";
91136
href: string;
92137
}
93138

139+
/**
140+
* Scrapbox number list node type
141+
*/
94142
export interface NumberListNode extends BaseNode {
95143
type: "numberList";
96144
rawNumber: string;
97145
number: number;
98146
nodes: Node[];
99147
}
100148

149+
/**
150+
* Scrapbox plain node type
151+
*/
101152
export interface PlainNode extends BaseNode {
102153
type: "plain";
103154
text: string;
104155
}
105156

157+
/**
158+
* Scrapbox node type
159+
*/
106160
export type Node =
107161
| QuoteNode
108162
| HelpfeelNode

src/parse.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,38 @@ import { packRows } from "./block/Pack";
44

55
import type { Block } from "./block";
66

7+
/**
8+
* parser option type
9+
*/
710
export interface ParserOption {
11+
/**
12+
* is Scrapbox notation text including title
13+
*/
814
hasTitle?: boolean;
915
}
1016

17+
/**
18+
* Scrapbox page type
19+
*/
1120
export type Page = Block[];
1221

22+
/**
23+
* parse Scrapbox notation text into JavaScript Object
24+
* @param input raw Scrapbox notation text
25+
* @param opts parser options
26+
* @returns syntax tree of parsed input
27+
*/
1328
export const parse = (input: string, opts?: ParserOption): Page => {
1429
const rows = parseToRows(input);
1530
const packs = packRows(rows, { hasTitle: opts?.hasTitle ?? true });
1631
return packs.map(convertToBlock);
1732
};
1833

34+
/**
35+
* get title of Scrapbox page
36+
* @param input raw Scrapbox notation text
37+
* @returns title of input Scrapbox page
38+
*/
1939
export const getTitle = (input: string): string => {
2040
const match = /^\s*\S.*$/m.exec(input);
2141
return match?.[0]?.trim() ?? "Untitled";

0 commit comments

Comments
 (0)