Skip to content
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
4 changes: 2 additions & 2 deletions src/block/node/BlankNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { BlankNode, PlainNode } from "./type.ts";

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

const createBlankNode: NodeCreator<BlankNode | PlainNode> = (raw, opts) =>
const createBlankNode: NodeCreator<BlankNode | PlainNode> = ([raw], opts) =>
opts.context === "table"
? createPlainNode(raw, opts)
? createPlainNode(raw)
: [
{
type: "blank",
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/CodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { CodeNode, PlainNode } from "./type.ts";

const codeRegExp = /`.*?`/;

const createCodeNode: NodeCreator<CodeNode | PlainNode> = (raw, opts) =>
const createCodeNode: NodeCreator<CodeNode | PlainNode> = ([raw], opts) =>
opts.context === "table"
? createPlainNode(raw, opts)
? createPlainNode(raw)
: [
{
type: "code",
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/CommandLineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { CommandLineNode, PlainNode } from "./type.ts";
const commandLineRegExp = /^[$%] .+$/;

const createCommandLineNode: NodeCreator<CommandLineNode | PlainNode> = (
raw: string,
[raw],
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const symbol = raw[0] ?? "";
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/DecorationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ type AsteriskDecorationChar =
export type Decoration = Exclude<DecorationChar, "*"> | AsteriskDecorationChar;

const createDecorationNode: NodeCreator<DecorationNode | PlainNode> = (
raw,
[raw],
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const separatorIndex = raw.indexOf(" ");
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/ExternalLinkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const bracketedUrlRegExp = /\[https?:\/\/[^\s\]]+\]/;
const httpRegExp = /https?:\/\/[^\s]+/;

const createExternalLinkNode: NodeCreator<LinkNode | PlainNode> = (
raw,
[raw],
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const inner =
Expand Down
7 changes: 5 additions & 2 deletions src/block/node/FormulaNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import type { FormulaNode, PlainNode } from "./type.ts";
const formulaWithTailHalfSpaceRegExp = /\[\$ .+? \]/;
const formulaRegExp = /\[\$ [^\]]+\]/;

const createFormulaNode: NodeCreator<FormulaNode | PlainNode> = (raw, opts) =>
const createFormulaNode: NodeCreator<FormulaNode | PlainNode> = (
[raw],
opts,
) =>
opts.context === "table"
? createPlainNode(raw, opts)
? createPlainNode(raw)
: [
{
type: "formula",
Expand Down
11 changes: 3 additions & 8 deletions src/block/node/GoogleMapNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ const parseCoordinate: (format: string) => Coordinate = (format) => {
};

const createGoogleMapNode: NodeCreator<GoogleMapNode | PlainNode> = (
raw,
match,
opts,
) => {
const raw = match[0];
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const match =
raw.match(placeFirstGoogleMapRegExp) ??
raw.match(coordFirstGoogleMapRegExp);
if (match === null) return [];
Comment on lines -34 to -37
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createGoogleMapNode execute String.prototype.match with patterns of NodeParser.
However, RegExp.prototype.exec has already executed for all patterns of NodeParserCreatorOptions.


const isCoordFirst = raw.startsWith("[N") || raw.startsWith("[S");
const [, coord = "", place = ""] = isCoordFirst
? match
Expand Down
9 changes: 6 additions & 3 deletions src/block/node/HashTagNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import type { HashTagNode, PlainNode } from "./type.ts";

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

const createHashTagNode: NodeCreator<HashTagNode | PlainNode> = (raw, opts) => {
const createHashTagNode: NodeCreator<HashTagNode | PlainNode> = (
[raw],
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

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

return [
...createPlainNode(space, opts),
...createPlainNode(space),
{
type: "hashTag",
raw: tag,
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/HelpfeelNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { HelpfeelNode, PlainNode } from "./type.ts";
const helpfeelRegExp = /^\? .+$/;

const createHelpfeelNode: NodeCreator<HelpfeelNode | PlainNode> = (
raw,
[raw],
opts,
) =>
opts.context === "table"
? createPlainNode(raw, opts)
? createPlainNode(raw)
: [
{
type: "helpfeel",
Expand Down
2 changes: 1 addition & 1 deletion src/block/node/IconNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { IconNode } from "./type.ts";

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

const createIconNode: NodeCreator<IconNode> = (raw) => {
const createIconNode: NodeCreator<IconNode> = ([raw]) => {
const target = raw.substring(1, raw.length - 1);
const index = target.lastIndexOf(".icon");
const path = target.substring(0, index);
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/ImageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const isImageUrl = (text: string): boolean =>
const isGyazoImageUrl = (text: string): boolean =>
/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(text);

const createImageNode: NodeCreator<ImageNode | PlainNode> = (raw, opts) => {
const createImageNode: NodeCreator<ImageNode | PlainNode> = ([raw], opts) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const index = raw.search(/\s/);
Expand Down
2 changes: 1 addition & 1 deletion src/block/node/InternalLinkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LinkNode } from "./type.ts";

const internalLinkRegExp = /\[\/?[^[\]]+\]/;

const createInternalLinkNode: NodeCreator<LinkNode> = (raw) => {
const createInternalLinkNode: NodeCreator<LinkNode> = ([raw]) => {
const href = raw.substring(1, raw.length - 1);
return [
{
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/NumberListNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { NumberListNode, PlainNode } from "./type.ts";
const numberListRegExp = /^[0-9]+\. .*$/;

const createNumberListNode: NodeCreator<NumberListNode | PlainNode> = (
raw,
[raw],
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const separatorIndex = raw.indexOf(" ");
Expand Down
3 changes: 1 addition & 2 deletions src/block/node/PlainNode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { NodeCreator } from "./creator.ts";
import type { TerminateNodeParser } from "./index.ts";
import type { PlainNode } from "./type.ts";

export const createPlainNode: NodeCreator<PlainNode> = (raw) => [
export const createPlainNode = (raw: string): [PlainNode] => [
{
type: "plain",
raw,
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/QuoteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { PlainNode, QuoteNode } from "./type.ts";

const quoteRegExp = /^>.*$/;

const createQuoteNode: NodeCreator<QuoteNode | PlainNode> = (raw, opts) =>
const createQuoteNode: NodeCreator<QuoteNode | PlainNode> = ([raw], opts) =>
opts.context === "table"
? createPlainNode(raw, opts)
? createPlainNode(raw)
: [
{
type: "quote",
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/StrongIconNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type { PlainNode, StrongIconNode } from "./type.ts";
const strongIconRegExp = /\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/;

const createStrongIconNode: NodeCreator<StrongIconNode | PlainNode> = (
raw,
[raw],
opts,
) => {
if (opts.context === "table") return createPlainNode(raw, opts);
if (opts.context === "table") return createPlainNode(raw);

const target = raw.substring(2, raw.length - 2);
const index = target.lastIndexOf(".icon");
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/StrongImageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const strongGyazoImageRegExp =
/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/;

const createStrongImageNode: NodeCreator<StrongImageNode | PlainNode> = (
raw,
[raw],
opts,
) => {
if (opts.context === "table") {
return createPlainNode(raw, opts);
return createPlainNode(raw);
}

const src = raw.substring(2, raw.length - 2);
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/StrongNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { PlainNode, StrongNode } from "./type.ts";

const strongRegExp = /\[\[(?:[^[]|\[[^[]).*?\]*\]\]/;

const createStrongNode: NodeCreator<StrongNode | PlainNode> = (raw, opts) =>
const createStrongNode: NodeCreator<StrongNode | PlainNode> = ([raw], opts) =>
opts.context === "table"
? createPlainNode(raw, opts)
? createPlainNode(raw)
: [
{
type: "strong",
Expand Down
4 changes: 2 additions & 2 deletions src/block/node/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { convertToNodes } from "./index.ts";
import type { Node } from "./type.ts";

export type NodeCreator<T extends Node> = (
target: string,
match: RegExpExecArray,
opts: NodeParserOption,
) => T[];

Expand Down Expand Up @@ -33,7 +33,7 @@ export const createNodeParser: NodeParserCreator<Node> = (
const left = text.substring(0, match.index);
const right = text.substring(match.index + match[0].length);

const node = nodeCreator(match[0], opts);
const node = nodeCreator(match, opts);
return [
...convertToNodes(left, opts),
...node,
Expand Down
Loading