Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Nov 5, 2024
1 parent 56cb507 commit 08d96b7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@diplodoc/transform",
"version": "4.34.0",
"version": "4.35.0-beta5",
"description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
"keywords": [
"markdown",
Expand Down
2 changes: 0 additions & 2 deletions src/transform/plugins/video/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export enum VideoService {
Yandex = 'yandex',
Vk = 'vk',
Rutube = 'rutube',
Dzen = 'dzen',
}

export type Service = {
Expand All @@ -31,6 +30,5 @@ export const defaults: VideoFullOptions = {
osf: {width: '100%', height: '100%'},
yandex: {width: 640, height: 390},
vk: {width: 640, height: 390},
dzen: {width: 640, height: 390},
rutube: {width: 640, height: 390},
};
6 changes: 5 additions & 1 deletion src/transform/plugins/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ function videoEmbed(md: MarkdownIt, _options: VideoFullOptions): ParserInline.Ru
}

theState.pos += theState.src.indexOf(')', theState.pos);
append(state.env.meta, 'csp', csp);

if (csp) {
state.env.meta ??= {};
append(state.env.meta, 'csp', csp);
}

return true;
};
Expand Down
14 changes: 5 additions & 9 deletions src/transform/plugins/video/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ export function rutubeParser(url: string) {
return match ? match[1] : url;
}

const dzenRegex = /^https:\/\/dzen\.ru\/video\/watch\/([a-zA-Z0-9]+)/;
export function dzenParser(url: string) {
const match = url.match(dzenRegex);
return match ? match[1] : url;
/*
dzen /embed/<id> and /video/watch/<id> are not the same
so we can't extract something from url and should pass it next
*/
return url;
}

const supportedServices = Object.entries({
Expand Down Expand Up @@ -88,12 +90,6 @@ const supportedServices = Object.entries({
'frame-src': 'https://rutube.ru/play/embed/',
},
},
dzen: {
extract: dzenParser,
csp: {
'frame-src': 'https://dzen.ru/embed/',
},
},
}) as Services;

export function parseVideoUrl(service: string, url: string) {
Expand Down
2 changes: 0 additions & 2 deletions src/transform/plugins/video/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export const videoUrl: VideoUrlFn = (service, videoID, options) => {
return `https://vk.com/video_ext.php?${videoID}`;
case 'rutube':
return `https://rutube.ru/play/embed/${videoID}`;
case 'dzen':
return `https://dzen.ru/video/watch/${videoID}`;
default:
return service;
}
Expand Down

0 comments on commit 08d96b7

Please sign in to comment.