Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release v0.1.156 #510

Merged
merged 13 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Resolves #<issue-url>

プルリクエストを作成いただく際、お手数ですが以下の内容についてご確認をお願いします。

- [ ] :book: [Contribution Guide](https://github.com/zenn-dev/zenn-editor/blob/main/CONTRIBUTING.md) を読んだ
- [ ] :book: [Contribution Guide](https://zenn-dev.github.io/zenn-docs-for-developers/contribution) を読んだ
- [ ] :woman_technologist: `canary` ブランチに対するプルリクエストである
- [ ] zenn-cli で実行して正しく動作しているか確認する
- [ ] 不要なコードが含まれていないか( コメントやログの消し忘れに注意 )
Expand Down
48 changes: 0 additions & 48 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packages": [
"packages/*"
],
"version": "0.1.155",
"version": "0.1.156-alpha.0",
"npmClient": "pnpm"
}
6 changes: 6 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,12 @@ published: true

@[speakerdeck](4f926da9cb4cd0001f00a1ff)

## docswell

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

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

## jsfiddle

@[jsfiddle](https://jsfiddle.net/9wkngdue/embedded)
Expand Down
2 changes: 1 addition & 1 deletion packages/zenn-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-cli",
"version": "0.1.155",
"version": "0.1.156-alpha.0",
"description": "Preview Zenn content locally.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/zenn-content-css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-content-css",
"version": "0.1.155",
"version": "0.1.156-alpha.0",
"license": "MIT",
"description": "Zenn flavor content style.",
"repository": {
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
2 changes: 1 addition & 1 deletion packages/zenn-embed-elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-embed-elements",
"version": "0.1.155",
"version": "0.1.156-alpha.0",
"license": "MIT",
"description": "Web components for embedded contents.",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, test, expect } from 'vitest';
import markdownToHtml from '../../../src/index';

describe('Docswell', () => {
describe('Docswellの埋め込み用URLの場合', () => {
test('Docswellのiframeを返すこと', () => {
const html = markdownToHtml(
'@[docswell](https://www.docswell.com/slide/LK7J5V/embed)'
);
expect(html).toContain(
'<span class="embed-block embed-docswell"><iframe src="https://www.docswell.com/slide/LK7J5V/embed" allowfullscreen="true" width="620" style="border:1px solid #ccc;display:block;margin:0px auto;padding:0px;aspect-ratio:620/349"></iframe></span>'
);
});
});

describe('DocswellのスライドURLの場合', () => {
test('Docswellのiframeを返すこと', () => {
const html = markdownToHtml(
'@[docswell](https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell)'
);
expect(html).toContain(
'<span class="embed-block embed-docswell"><iframe src="https://www.docswell.com/slide/LK7J5V/embed" allowfullscreen="true" width="620" style="border:1px solid #ccc;display:block;margin:0px auto;padding:0px;aspect-ratio:620/349"></iframe></span>'
);
});
});

describe('DocswellのURLが不正な場合', () => {
test('エラーメッセージを返すこと', () => {
const html = markdownToHtml(
'@[docswell](https://www.docswell.com/invalid)'
);
expect(html).toContain('DocswellのスライドURLが不正です');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { isDocswellUrl } from '../../src/utils/url-matcher';
import { describe, test, expect } from 'vitest';

describe('isDocswellUrlのテスト', () => {
describe('Docswellの埋め込み用URLの場合', () => {
test('trueを返すこと', () => {
const docswellEmbedUrl = 'https://www.docswell.com/slide/LK7J5V/embed';
expect(isDocswellUrl(docswellEmbedUrl)).toBe(true);
});
});

describe('DocswellのスライドURLの場合', () => {
test('trueを返すこと', () => {
const docswellSlideUrl =
'https://www.docswell.com/s/ku-suke/LK7J5V-hello-docswell';
expect(isDocswellUrl(docswellSlideUrl)).toBe(true);
});
});

describe('Docswellの他の画面のURLの場合', () => {
test('falseを返すこと', () => {
const docswellUrls = ['https://www.docswell.com/'];

docswellUrls.forEach((url) => {
expect(isDocswellUrl(url)).toBe(false);
});
});
});

describe('他のサイトのURLの場合', () => {
test('falseを返すこと', () => {
const otherSiteUrls = ['https://zenn.dev/', 'https://github.com/'];

otherSiteUrls.forEach((url) => {
expect(isDocswellUrl(url)).toBe(false);
});
});
});
});
2 changes: 1 addition & 1 deletion packages/zenn-markdown-html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-markdown-html",
"version": "0.1.155",
"version": "0.1.156-alpha.0",
"license": "MIT",
"description": "Convert markdown to zenn flavor html.",
"main": "lib/index.js",
Expand Down
16 changes: 15 additions & 1 deletion packages/zenn-markdown-html/src/embed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MarkdownOptions } from './types';

import { escapeHtml } from 'markdown-it/lib/common/utils';
import { extractYoutubeVideoParameters } from './utils/url-matcher';
import {
sanitizeEmbedToken,
generateEmbedServerIframe,
Expand All @@ -17,6 +16,9 @@ import {
isBlueprintUEUrl,
isFigmaUrl,
isValidHttpUrl,
isDocswellUrl,
extractYoutubeVideoParameters,
extractDocswellEmbedUrl,
} from './utils/url-matcher';

/* 埋め込み要素の種別 */
Expand All @@ -25,6 +27,7 @@ export type EmbedType =
| 'slideshare'
| 'speakerdeck'
| 'jsfiddle'
| 'docswell'
| 'codepen'
| 'codesandbox'
| 'stackblitz'
Expand Down Expand Up @@ -77,6 +80,17 @@ export const embedGenerators: Readonly<EmbedGeneratorList> = {
key
)}" scrolling="no" allowfullscreen allow="encrypted-media" loading="lazy"></iframe></span>`;
},
docswell(str) {
const errorMessage = 'DocswellのスライドURLが不正です';
if (!isDocswellUrl(str)) {
return errorMessage;
}
const slideUrl = extractDocswellEmbedUrl(str);
if (!slideUrl) {
return errorMessage;
}
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>`;
},
jsfiddle(str) {
if (!isJsfiddleUrl(str)) {
return 'jsfiddleのURLが不正です';
Expand Down
27 changes: 27 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,17 @@ export function isJsfiddleUrl(url: string): boolean {
return /^(http|https):\/\/jsfiddle\.net\/[a-zA-Z0-9_,/-]+$/.test(url);
}

const docswellNormalUrlRegex =
/^https:\/\/www\.docswell\.com\/s\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
const docswellEmbedUrlRegex =
/^https:\/\/www\.docswell\.com\/slide\/[a-zA-Z0-9_-]+\/embed$/;

export function isDocswellUrl(url: string): boolean {
return [docswellNormalUrlRegex, docswellEmbedUrlRegex].some((pattern) =>
pattern.test(url)
);
}

export function isYoutubeUrl(url: string): boolean {
return [
/^https?:\/\/youtu\.be\/[\w-]+(?:\?[\w=&-]+)?$/,
Expand Down Expand Up @@ -80,6 +91,22 @@ export function extractYoutubeVideoParameters(
return { videoId, start };
}

export function extractDocswellEmbedUrl(url: string): string | null {
// Embed用URLの場合、そのまま返す
if (docswellEmbedUrlRegex.test(url)) {
return url;
}
// Embed用URLでない場合 https://www.docswell.com/s/:username/{slideId}-hello-docswell のslideIdを抽出する
const slideId = new URL(url).pathname.split('/').at(3)?.split('-').at(0);
if (!slideId) {
return null;
}
return new URL(
`/slide/${slideId}/embed`,
'https://www.docswell.com'
).toString();
}

/**
* 参考: https://blueprintue.com/
* 生成されるURLをもとに正規表現を定義した
Expand Down
2 changes: 1 addition & 1 deletion packages/zenn-model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-model",
"version": "0.1.155",
"version": "0.1.156-alpha.0",
"license": "MIT",
"description": "Model utils for Zenn contents",
"main": "lib/index.js",
Expand Down
Loading