Skip to content

Commit 0ae0c4d

Browse files
authored
Merge pull request #1754 from progfay/format20240821
`npm run format`
2 parents b9f2c1b + 46b3941 commit 0ae0c4d

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

src/block/node/ImageNode.ts

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,54 @@ import type { NodeCreator } from "./creator.ts";
55
import type { ImageNode, PlainNode } from "./type.ts";
66

77
const srcFirstStrongImageRegExp =
8-
/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i;
8+
/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i;
99
const linkFirstStrongImageRegExp =
10-
/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i;
10+
/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i;
1111
const srcFirstStrongGyazoImageRegExp =
12-
/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/;
12+
/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/;
1313
const linkFirstStrongGyazoImageRegExp =
14-
/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/;
14+
/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/;
1515

1616
const isImageUrl = (text: string): boolean =>
17-
/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(text) ||
18-
isGyazoImageUrl(text);
17+
/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(text) ||
18+
isGyazoImageUrl(text);
1919

2020
const isGyazoImageUrl = (text: string): boolean =>
21-
/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(text);
21+
/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(text);
2222

2323
const createImageNode: NodeCreator<ImageNode | PlainNode> = (raw, opts) => {
24-
if (opts.context === "table") {
25-
return createPlainNode(raw, opts);
26-
}
27-
28-
const index = raw.search(/\s/);
29-
const first =
30-
index !== -1 ? raw.substring(1, index) : raw.substring(1, raw.length - 1);
31-
const second =
32-
index !== -1 ? raw.substring(index, raw.length - 1).replace(/^\s+/, '') : "";
33-
const [src, link] = isImageUrl(second) ? [second, first] : [first, second];
34-
35-
return [
36-
{
37-
type: "image",
38-
raw,
39-
src: /^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(src)
40-
? `${src}/thumb/1000`
41-
: src,
42-
link,
43-
},
44-
];
24+
if (opts.context === "table") {
25+
return createPlainNode(raw, opts);
26+
}
27+
28+
const index = raw.search(/\s/);
29+
const first =
30+
index !== -1 ? raw.substring(1, index) : raw.substring(1, raw.length - 1);
31+
const second =
32+
index !== -1
33+
? raw.substring(index, raw.length - 1).replace(/^\s+/, "")
34+
: "";
35+
const [src, link] = isImageUrl(second) ? [second, first] : [first, second];
36+
37+
return [
38+
{
39+
type: "image",
40+
raw,
41+
src: /^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(src)
42+
? `${src}/thumb/1000`
43+
: src,
44+
link,
45+
},
46+
];
4547
};
4648

4749
export const ImageNodeParser = createNodeParser(createImageNode, {
48-
parseOnNested: true,
49-
parseOnQuoted: true,
50-
patterns: [
51-
srcFirstStrongImageRegExp,
52-
linkFirstStrongImageRegExp,
53-
srcFirstStrongGyazoImageRegExp,
54-
linkFirstStrongGyazoImageRegExp,
55-
],
50+
parseOnNested: true,
51+
parseOnQuoted: true,
52+
patterns: [
53+
srcFirstStrongImageRegExp,
54+
linkFirstStrongImageRegExp,
55+
srcFirstStrongGyazoImageRegExp,
56+
linkFirstStrongGyazoImageRegExp,
57+
],
5658
});

0 commit comments

Comments
 (0)