Skip to content

Commit cbec1f3

Browse files
committed
pass result of RegExp.prototype.exec to NodeCreator
1 parent 38b8adf commit cbec1f3

19 files changed

+43
-43
lines changed

src/block/node/BlankNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import type { BlankNode, PlainNode } from "./type.ts";
66

77
const blankRegExp = /\[\s+\]/;
88

9-
const createBlankNode: NodeCreator<BlankNode | PlainNode> = (raw, opts) =>
9+
const createBlankNode: NodeCreator<BlankNode | PlainNode> = ([raw], opts) =>
1010
opts.context === "table"
11-
? createPlainNode(raw, opts)
11+
? createPlainNode(raw)
1212
: [
1313
{
1414
type: "blank",

src/block/node/CodeNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import type { CodeNode, PlainNode } from "./type.ts";
66

77
const codeRegExp = /`.*?`/;
88

9-
const createCodeNode: NodeCreator<CodeNode | PlainNode> = (raw, opts) =>
9+
const createCodeNode: NodeCreator<CodeNode | PlainNode> = ([raw], opts) =>
1010
opts.context === "table"
11-
? createPlainNode(raw, opts)
11+
? createPlainNode(raw)
1212
: [
1313
{
1414
type: "code",

src/block/node/CommandLineNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import type { CommandLineNode, PlainNode } from "./type.ts";
77
const commandLineRegExp = /^[$%] .+$/;
88

99
const createCommandLineNode: NodeCreator<CommandLineNode | PlainNode> = (
10-
raw: string,
10+
[raw],
1111
opts,
1212
) => {
1313
if (opts.context === "table") {
14-
return createPlainNode(raw, opts);
14+
return createPlainNode(raw);
1515
}
1616

1717
const symbol = raw[0] ?? "";

src/block/node/DecorationNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ type AsteriskDecorationChar =
4848
export type Decoration = Exclude<DecorationChar, "*"> | AsteriskDecorationChar;
4949

5050
const createDecorationNode: NodeCreator<DecorationNode | PlainNode> = (
51-
raw,
51+
[raw],
5252
opts,
5353
) => {
5454
if (opts.context === "table") {
55-
return createPlainNode(raw, opts);
55+
return createPlainNode(raw);
5656
}
5757

5858
const separatorIndex = raw.indexOf(" ");

src/block/node/ExternalLinkNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const bracketedUrlRegExp = /\[https?:\/\/[^\s\]]+\]/;
1010
const httpRegExp = /https?:\/\/[^\s]+/;
1111

1212
const createExternalLinkNode: NodeCreator<LinkNode | PlainNode> = (
13-
raw,
13+
[raw],
1414
opts,
1515
) => {
1616
if (opts.context === "table") {
17-
return createPlainNode(raw, opts);
17+
return createPlainNode(raw);
1818
}
1919

2020
const inner =

src/block/node/FormulaNode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import type { FormulaNode, PlainNode } from "./type.ts";
77
const formulaWithTailHalfSpaceRegExp = /\[\$ .+? \]/;
88
const formulaRegExp = /\[\$ [^\]]+\]/;
99

10-
const createFormulaNode: NodeCreator<FormulaNode | PlainNode> = (raw, opts) =>
10+
const createFormulaNode: NodeCreator<FormulaNode | PlainNode> = (
11+
[raw],
12+
opts,
13+
) =>
1114
opts.context === "table"
12-
? createPlainNode(raw, opts)
15+
? createPlainNode(raw)
1316
: [
1417
{
1518
type: "formula",

src/block/node/GoogleMapNode.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ const parseCoordinate: (format: string) => Coordinate = (format) => {
2424
};
2525

2626
const createGoogleMapNode: NodeCreator<GoogleMapNode | PlainNode> = (
27-
raw,
27+
match,
2828
opts,
2929
) => {
30+
const raw = match[0];
3031
if (opts.context === "table") {
31-
return createPlainNode(raw, opts);
32+
return createPlainNode(raw);
3233
}
33-
34-
const match =
35-
raw.match(placeFirstGoogleMapRegExp) ??
36-
raw.match(coordFirstGoogleMapRegExp);
37-
if (match === null) return [];
38-
3934
const isCoordFirst = raw.startsWith("[N") || raw.startsWith("[S");
4035
const [, coord = "", place = ""] = isCoordFirst
4136
? match

src/block/node/HashTagNode.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import type { HashTagNode, PlainNode } from "./type.ts";
66

77
const hashTagRegExp = /(?:^|\s)#\S+/;
88

9-
const createHashTagNode: NodeCreator<HashTagNode | PlainNode> = (raw, opts) => {
9+
const createHashTagNode: NodeCreator<HashTagNode | PlainNode> = (
10+
[raw],
11+
opts,
12+
) => {
1013
if (opts.context === "table") {
11-
return createPlainNode(raw, opts);
14+
return createPlainNode(raw);
1215
}
1316

1417
if (raw.startsWith("#")) {
@@ -25,7 +28,7 @@ const createHashTagNode: NodeCreator<HashTagNode | PlainNode> = (raw, opts) => {
2528
const tag = raw.substring(1);
2629

2730
return [
28-
...createPlainNode(space, opts),
31+
...createPlainNode(space),
2932
{
3033
type: "hashTag",
3134
raw: tag,

src/block/node/HelpfeelNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import type { HelpfeelNode, PlainNode } from "./type.ts";
77
const helpfeelRegExp = /^\? .+$/;
88

99
const createHelpfeelNode: NodeCreator<HelpfeelNode | PlainNode> = (
10-
raw,
10+
[raw],
1111
opts,
1212
) =>
1313
opts.context === "table"
14-
? createPlainNode(raw, opts)
14+
? createPlainNode(raw)
1515
: [
1616
{
1717
type: "helpfeel",

src/block/node/IconNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { IconNode } from "./type.ts";
55

66
const iconRegExp = /\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;
77

8-
const createIconNode: NodeCreator<IconNode> = (raw) => {
8+
const createIconNode: NodeCreator<IconNode> = ([raw]) => {
99
const target = raw.substring(1, raw.length - 1);
1010
const index = target.lastIndexOf(".icon");
1111
const path = target.substring(0, index);

0 commit comments

Comments
 (0)