Skip to content

Commit

Permalink
ドクセル埋め込み対応
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-dyoshikawa committed Sep 12, 2024
1 parent 5502684 commit 6ed6868
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/zenn-cli/articles/305-example-embed-others.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ published: true

@[speakerdeck](4f926da9cb4cd0001f00a1ff)

## docswell

@[docswell](https://www.docswell.com/slide/LK7J5V/embed)

### embed用でないdocswell URL

@[docswell](https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell)

## jsfiddle

@[jsfiddle](https://jsfiddle.net/9wkngdue/embedded)
Expand Down
1 change: 1 addition & 0 deletions packages/zenn-content-css/src/_embed.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ span.embed-block {
}
.embed-slideshare,
.embed-speakerdeck,
.embed-docswell,
.embed-codepen,
.embed-jsfiddle,
.embed-youtube,
Expand Down
12 changes: 11 additions & 1 deletion packages/zenn-markdown-html/src/embed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { MarkdownOptions } from './types';

import { escapeHtml } from 'markdown-it/lib/common/utils';
import { extractYoutubeVideoParameters } from './utils/url-matcher';
import {
extractYoutubeVideoParameters,
isDocswellUrl,
} from './utils/url-matcher';
import {
sanitizeEmbedToken,
generateEmbedServerIframe,
Expand All @@ -25,6 +28,7 @@ export type EmbedType =
| 'slideshare'
| 'speakerdeck'
| 'jsfiddle'
| 'docswell'
| 'codepen'
| 'codesandbox'
| 'stackblitz'
Expand Down Expand Up @@ -77,6 +81,12 @@ export const embedGenerators: Readonly<EmbedGeneratorList> = {
key
)}" scrolling="no" allowfullscreen allow="encrypted-media" loading="lazy"></iframe></span>`;
},
docswell(str) {
if (!isDocswellUrl(str)) {
return 'Docswellのembed用のURLを指定してください';
}
return `<span class="embed-block embed-docswell"><iframe src="${str}" 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>`;
},
jsfiddle(str) {
if (!isJsfiddleUrl(str)) {
return 'jsfiddleのURLが不正です';
Expand Down
4 changes: 4 additions & 0 deletions packages/zenn-markdown-html/src/utils/url-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function isJsfiddleUrl(url: string): boolean {
return /^(http|https):\/\/jsfiddle\.net\/[a-zA-Z0-9_,/-]+$/.test(url);
}

export function isDocswellUrl(url: string): boolean {
return /^https:\/\/www\.docswell\.com\/[a-zA-Z0-9_,/-]+\/embed$/.test(url);
}

export function isYoutubeUrl(url: string): boolean {
return [
/^https?:\/\/youtu\.be\/[\w-]+(?:\?[\w=&-]+)?$/,
Expand Down

0 comments on commit 6ed6868

Please sign in to comment.