-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #509 from zenn-dev/feat-docswell
ドクセル埋め込み対応
- Loading branch information
Showing
6 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/zenn-markdown-html/__tests__/custom-syntax/embed/docswell.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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が不正です'); | ||
}); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/zenn-markdown-html/__tests__/matchers/isDocswellUrl.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters