zenn-markdown-html 0.1.155 → 0.1.156

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { MarkdownOptions } from './types';
2
- export type EmbedType = 'youtube' | 'slideshare' | 'speakerdeck' | 'jsfiddle' | 'codepen' | 'codesandbox' | 'stackblitz' | 'tweet' | 'blueprintue' | 'figma' | 'card' | 'gist' | 'github' | 'mermaid';
2
+ export type EmbedType = 'youtube' | 'slideshare' | 'speakerdeck' | 'jsfiddle' | 'docswell' | 'codepen' | 'codesandbox' | 'stackblitz' | 'tweet' | 'blueprintue' | 'figma' | 'card' | 'gist' | 'github' | 'mermaid';
3
3
  /** embedサーバーで表示する埋め込み要素の種別 */
4
4
  export type EmbedServerType = Extract<EmbedType, 'tweet' | 'card' | 'mermaid' | 'github' | 'gist'>;
5
5
  /** 埋め込み要素のHTMLを生成する関数 */
package/lib/embed.js CHANGED
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.embedKeys = exports.embedGenerators = void 0;
7
7
  var _utils = require("markdown-it/lib/common/utils");
8
- var _urlMatcher = require("./utils/url-matcher");
9
8
  var _embedHelper = require("./utils/embed-helper");
9
+ var _urlMatcher = require("./utils/url-matcher");
10
10
  /** 埋め込み要素のHTMLを生成する関数をまとめたオブジェクト */
11
11
  const embedGenerators = {
12
12
  youtube(str) {
@@ -33,6 +33,17 @@ const embedGenerators = {
33
33
  }
34
34
  return `<span class="embed-block embed-speakerdeck"><iframe src="https://speakerdeck.com/player/${(0, _utils.escapeHtml)(key)}" scrolling="no" allowfullscreen allow="encrypted-media" loading="lazy"></iframe></span>`;
35
35
  },
36
+ docswell(str) {
37
+ const errorMessage = 'DocswellのスライドURLが不正です';
38
+ if (!(0, _urlMatcher.isDocswellUrl)(str)) {
39
+ return errorMessage;
40
+ }
41
+ const slideUrl = (0, _urlMatcher.extractDocswellEmbedUrl)(str);
42
+ if (!slideUrl) {
43
+ return errorMessage;
44
+ }
45
+ return `<span class="embed-block embed-docswell"><iframe src="${slideUrl}" allowfullscreen="true" class="docswell-iframe" width="620" height="349" style="border: 1px solid #ccc; display: block; margin: 0px auto; padding: 0px; aspect-ratio: 620/349;"></iframe></span>`;
46
+ },
36
47
  jsfiddle(str) {
37
48
  if (!(0, _urlMatcher.isJsfiddleUrl)(str)) {
38
49
  return 'jsfiddleのURLが不正です';
@@ -7,6 +7,7 @@ export declare function isStackblitzUrl(url: string): boolean;
7
7
  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
+ export declare function isDocswellUrl(url: string): boolean;
10
11
  export declare function isYoutubeUrl(url: string): boolean;
11
12
  /**
12
13
  * youtube の URL から videoId と開始位置の秒数を取得する
@@ -15,6 +16,7 @@ export declare function extractYoutubeVideoParameters(youtubeUrl: string): {
15
16
  videoId: string;
16
17
  start?: string;
17
18
  } | undefined;
19
+ export declare function extractDocswellEmbedUrl(url: string): string | null;
18
20
  /**
19
21
  * 参考: https://blueprintue.com/
20
22
  * 生成されるURLをもとに正規表現を定義した
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.extractDocswellEmbedUrl = extractDocswellEmbedUrl;
6
7
  exports.extractYoutubeVideoParameters = extractYoutubeVideoParameters;
7
8
  exports.isBlueprintUEUrl = isBlueprintUEUrl;
8
9
  exports.isCodepenUrl = isCodepenUrl;
9
10
  exports.isCodesandboxUrl = isCodesandboxUrl;
11
+ exports.isDocswellUrl = isDocswellUrl;
10
12
  exports.isFigmaUrl = isFigmaUrl;
11
13
  exports.isGistUrl = isGistUrl;
12
14
  exports.isGithubUrl = isGithubUrl;
@@ -47,6 +49,11 @@ function isCodepenUrl(url) {
47
49
  function isJsfiddleUrl(url) {
48
50
  return /^(http|https):\/\/jsfiddle\.net\/[a-zA-Z0-9_,/-]+$/.test(url);
49
51
  }
52
+ const docswellNormalUrlRegex = /^https:\/\/www\.docswell\.com\/s\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
53
+ const docswellEmbedUrlRegex = /^https:\/\/www\.docswell\.com\/slide\/[a-zA-Z0-9_-]+\/embed$/;
54
+ function isDocswellUrl(url) {
55
+ return [docswellNormalUrlRegex, docswellEmbedUrlRegex].some(pattern => pattern.test(url));
56
+ }
50
57
  function isYoutubeUrl(url) {
51
58
  return [/^https?:\/\/youtu\.be\/[\w-]+(?:\?[\w=&-]+)?$/, /^https?:\/\/(?:www\.)?youtube\.com\/watch\?[\w=&-]+$/].some(pattern => pattern.test(url));
52
59
  }
@@ -75,6 +82,19 @@ function extractYoutubeVideoParameters(youtubeUrl) {
75
82
  start
76
83
  };
77
84
  }
85
+ function extractDocswellEmbedUrl(url) {
86
+ var _URL$pathname$split$a;
87
+ // Embed用URLの場合、そのまま返す
88
+ if (docswellEmbedUrlRegex.test(url)) {
89
+ return url;
90
+ }
91
+ // Embed用URLでない場合 https://www.docswell.com/s/:username/{slideId}-hello-docswell のslideIdを抽出する
92
+ const slideId = (_URL$pathname$split$a = new URL(url).pathname.split('/').at(3)) === null || _URL$pathname$split$a === void 0 ? void 0 : _URL$pathname$split$a.split('-').at(0);
93
+ if (!slideId) {
94
+ return null;
95
+ }
96
+ return new URL(`/slide/${slideId}/embed`, 'https://www.docswell.com').toString();
97
+ }
78
98
 
79
99
  /**
80
100
  * 参考: https://blueprintue.com/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenn-markdown-html",
3
- "version": "0.1.155",
3
+ "version": "0.1.156",
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": "7c4b0fd3e18ab7df9ff92657598ebd8616cac538",
63
+ "gitHead": "42c7d274c5b157fe99905608d77a1df8d1b1c1f6",
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  }