zenn-markdown-html 0.1.142 → 0.1.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/url-matcher.d.ts +7 -7
- package/lib/utils/url-matcher.js +26 -19
- package/package.json +2 -2
|
@@ -8,6 +8,13 @@ export declare function isCodesandboxUrl(url: string): boolean;
|
|
|
8
8
|
export declare function isCodepenUrl(url: string): boolean;
|
|
9
9
|
export declare function isJsfiddleUrl(url: string): boolean;
|
|
10
10
|
export declare function isYoutubeUrl(url: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* youtube の URL から videoId と開始位置の秒数を取得する
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractYoutubeVideoParameters(youtubeUrl: string): {
|
|
15
|
+
videoId: string;
|
|
16
|
+
start?: string;
|
|
17
|
+
} | undefined;
|
|
11
18
|
/**
|
|
12
19
|
* 参考: https://blueprintue.com/
|
|
13
20
|
* 生成されるURLをもとに正規表現を定義した
|
|
@@ -17,10 +24,3 @@ export declare function isBlueprintUEUrl(url: string): boolean;
|
|
|
17
24
|
* 参考: https://www.figma.com/developers/embed
|
|
18
25
|
*/
|
|
19
26
|
export declare function isFigmaUrl(url: string): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* youtube の URL から videoId と開始位置の秒数を取得する
|
|
22
|
-
*/
|
|
23
|
-
export declare function extractYoutubeVideoParameters(youtubeUrl: string): {
|
|
24
|
-
videoId: string;
|
|
25
|
-
start?: string;
|
|
26
|
-
} | undefined;
|
package/lib/utils/url-matcher.js
CHANGED
|
@@ -47,9 +47,33 @@ function isCodepenUrl(url) {
|
|
|
47
47
|
function isJsfiddleUrl(url) {
|
|
48
48
|
return /^(http|https):\/\/jsfiddle\.net\/[a-zA-Z0-9_,/-]+$/.test(url);
|
|
49
49
|
}
|
|
50
|
-
const youtubeRegexp = /^(http(s?):\/\/)?(www\.)?youtu(be)?\.([a-z])+\/(watch(.*?)([?&])v=)?(.*?)(&(.)*)?$/;
|
|
51
50
|
function isYoutubeUrl(url) {
|
|
52
|
-
return
|
|
51
|
+
return [/^https?:\/\/youtu\.be\/[\w-]+(?:\?[\w=&-]+)?$/, /^https?:\/\/(?:www\.)?youtube\.com\/watch\?[\w=&-]+$/].some(pattern => pattern.test(url));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** YoutubeのVideoIdの文字列の長さ */
|
|
55
|
+
const YOUTUBE_VIDEO_ID_LENGTH = 11;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* youtube の URL から videoId と開始位置の秒数を取得する
|
|
59
|
+
*/
|
|
60
|
+
function extractYoutubeVideoParameters(youtubeUrl) {
|
|
61
|
+
var _params$get;
|
|
62
|
+
if (!isYoutubeUrl(youtubeUrl)) return void 0;
|
|
63
|
+
const url = new URL(youtubeUrl);
|
|
64
|
+
const params = new URLSearchParams(url.search || '');
|
|
65
|
+
|
|
66
|
+
// https://youtu.be/Hoge の "HogeHoge" の部分または、
|
|
67
|
+
// https://www.youtube.com/watch?v=Hoge の "Hoge" の部分を値とする
|
|
68
|
+
const videoId = params.get('v') || url.pathname.split('/')[1];
|
|
69
|
+
|
|
70
|
+
// https://www.youtube.com/watch?v=Hoge&t=100s の "100" の部分を値とする
|
|
71
|
+
const start = (_params$get = params.get('t')) === null || _params$get === void 0 ? void 0 : _params$get.replace('s', '');
|
|
72
|
+
if ((videoId === null || videoId === void 0 ? void 0 : videoId.length) !== YOUTUBE_VIDEO_ID_LENGTH) return void 0;
|
|
73
|
+
return {
|
|
74
|
+
videoId,
|
|
75
|
+
start
|
|
76
|
+
};
|
|
53
77
|
}
|
|
54
78
|
|
|
55
79
|
/**
|
|
@@ -66,21 +90,4 @@ function isBlueprintUEUrl(url) {
|
|
|
66
90
|
*/
|
|
67
91
|
function isFigmaUrl(url) {
|
|
68
92
|
return /^https:\/\/([\w.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/[\w-?=&%]+)?$/.test(url);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* youtube の URL から videoId と開始位置の秒数を取得する
|
|
73
|
-
*/
|
|
74
|
-
function extractYoutubeVideoParameters(youtubeUrl) {
|
|
75
|
-
const match = youtubeUrl.match(youtubeRegexp);
|
|
76
|
-
if (match && match[9].length == 11) {
|
|
77
|
-
const urlParams = new URLSearchParams(youtubeUrl);
|
|
78
|
-
const start = urlParams.get('t');
|
|
79
|
-
return {
|
|
80
|
-
videoId: match[9],
|
|
81
|
-
start: start === null || start === void 0 ? void 0 : start.replace('s', '') // https://www.youtube.com/watch?v=ABCSDGG&t=19101s => 19101
|
|
82
|
-
};
|
|
83
|
-
} else {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
93
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenn-markdown-html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.143",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Convert markdown to zenn flavor html.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"prismjs": "^1.29.0",
|
|
57
57
|
"sanitize-html": "^2.9.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "70c3496e4f43b393f87d136bb594c49f603f4087",
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
}
|