zenn-markdown-html 0.1.160 → 0.1.161
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/embed.js +1 -1
- package/lib/utils/url-matcher.js +33 -5
- package/package.json +2 -2
package/lib/embed.js
CHANGED
|
@@ -33,7 +33,7 @@ const embedGenerators = {
|
|
|
33
33
|
}
|
|
34
34
|
const [key, slideParamStr] = str.split('?');
|
|
35
35
|
const slideQuery = slideParamStr ? `?${slideParamStr}` : '';
|
|
36
|
-
return `<span class="embed-block embed-speakerdeck"><iframe src="https://speakerdeck.com/player/${(0, _utils.escapeHtml)(key)}${slideQuery}" scrolling="no" allowfullscreen allow="encrypted-media" loading="lazy"></iframe></span>`;
|
|
36
|
+
return `<span class="embed-block embed-speakerdeck"><iframe src="https://speakerdeck.com/player/${(0, _utils.escapeHtml)(key)}${(0, _utils.escapeHtml)(slideQuery)}" scrolling="no" allowfullscreen allow="encrypted-media" loading="lazy"></iframe></span>`;
|
|
37
37
|
},
|
|
38
38
|
docswell(str) {
|
|
39
39
|
const errorMessage = 'DocswellのスライドURLが不正です';
|
package/lib/utils/url-matcher.js
CHANGED
|
@@ -49,8 +49,15 @@ function isCodepenUrl(url) {
|
|
|
49
49
|
function isJsfiddleUrl(url) {
|
|
50
50
|
return /^(http|https):\/\/jsfiddle\.net\/[a-zA-Z0-9_,/-]+$/.test(url);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
|
|
53
|
+
// 例: https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell
|
|
54
|
+
// 例: https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell#p13
|
|
55
|
+
// 例: https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell/13
|
|
56
|
+
const docswellNormalUrlRegex = /^https:\/\/www\.docswell\.com\/s\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+(\/\d+)?(#p\d+)?$/;
|
|
57
|
+
|
|
58
|
+
// 例: https://www.docswell.com/slide/LK7J5V/embed
|
|
59
|
+
// 例: https://www.docswell.com/slide/LK7J5V/embed#p12
|
|
60
|
+
const docswellEmbedUrlRegex = /^https:\/\/www\.docswell\.com\/slide\/[a-zA-Z0-9_-]+\/embed(#p\d+)?$/;
|
|
54
61
|
function isDocswellUrl(url) {
|
|
55
62
|
return [docswellNormalUrlRegex, docswellEmbedUrlRegex].some(pattern => pattern.test(url));
|
|
56
63
|
}
|
|
@@ -83,17 +90,38 @@ function extractYoutubeVideoParameters(youtubeUrl) {
|
|
|
83
90
|
};
|
|
84
91
|
}
|
|
85
92
|
function extractDocswellEmbedUrl(url) {
|
|
86
|
-
var _URL$pathname$split$a;
|
|
87
93
|
// Embed用URLの場合、そのまま返す
|
|
88
94
|
if (docswellEmbedUrlRegex.test(url)) {
|
|
89
95
|
return url;
|
|
90
96
|
}
|
|
91
97
|
// Embed用URLでない場合 https://www.docswell.com/s/:username/{slideId}-hello-docswell のslideIdを抽出する
|
|
92
|
-
const
|
|
98
|
+
const urlObj = new URL(url); // URLオブジェクトを作成
|
|
99
|
+
const pathSegments = urlObj.pathname.split('/');
|
|
100
|
+
// pathSegmentsの例: ["", "s", "ku-suke", "LK7J5V-hello-docswell", "10"]
|
|
101
|
+
// slideIdは pathSegments[3] の先頭部分
|
|
102
|
+
const slideIdPart = pathSegments.at(3);
|
|
103
|
+
const slideId = slideIdPart === null || slideIdPart === void 0 ? void 0 : slideIdPart.split('-').at(0);
|
|
93
104
|
if (!slideId) {
|
|
94
105
|
return null;
|
|
95
106
|
}
|
|
96
|
-
|
|
107
|
+
let pageSuffix = '';
|
|
108
|
+
// #pXX 形式のページ番号を優先 (例: #p18)
|
|
109
|
+
if (urlObj.hash && /^#p\d+$/.test(urlObj.hash)) {
|
|
110
|
+
pageSuffix = urlObj.hash;
|
|
111
|
+
} else {
|
|
112
|
+
// /XX 形式のページ番号 (例: /28)
|
|
113
|
+
// 通常URLの形式: /s/{username}/{slideId-slug}/{optional_page_num}
|
|
114
|
+
// ページ番号がある場合、pathSegmentsの長さは5になる (e.g., ["", "s", "username", "slide-slug", "page"])
|
|
115
|
+
if (pathSegments.length === 5) {
|
|
116
|
+
const pageCandidate = pathSegments.at(4);
|
|
117
|
+
if (pageCandidate && /^\d+$/.test(pageCandidate)) {
|
|
118
|
+
pageSuffix = `#p${pageCandidate}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return new URL(`/slide/${slideId}/embed${pageSuffix}`,
|
|
123
|
+
// pageSuffixを結合
|
|
124
|
+
'https://www.docswell.com').toString();
|
|
97
125
|
}
|
|
98
126
|
|
|
99
127
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenn-markdown-html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.161",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Convert markdown to zenn flavor html.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"prismjs": "^1.29.0",
|
|
61
61
|
"sanitize-html": "^2.9.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "743a5f1677cb17c25504be97f1e8fd5824d3e1a6",
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
}
|