@diplodoc/transform 4.35.0-beta5 → 4.35.0
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/dist/css/_yfm-only.css.map +2 -2
- package/dist/css/_yfm-only.min.css.map +2 -2
- package/dist/css/base.css.map +2 -2
- package/dist/css/base.min.css.map +2 -2
- package/dist/css/print.css.map +2 -2
- package/dist/css/yfm.css.map +2 -2
- package/dist/css/yfm.min.css.map +2 -2
- package/dist/js/base.js +2 -2
- package/dist/js/base.js.map +1 -1
- package/dist/js/base.min.js +1 -1
- package/dist/js/base.min.js.map +2 -2
- package/dist/js/yfm.js +5 -5
- package/dist/js/yfm.js.map +1 -1
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +2 -2
- package/lib/plugins/images/index.js +1 -1
- package/lib/plugins/images/index.js.map +1 -1
- package/lib/plugins/video/const.d.ts +1 -6
- package/lib/plugins/video/const.js +3 -3
- package/lib/plugins/video/const.js.map +1 -1
- package/lib/plugins/video/index.js +10 -5
- package/lib/plugins/video/index.js.map +1 -1
- package/lib/plugins/video/parsers.d.ts +0 -1
- package/lib/plugins/video/parsers.js +12 -22
- package/lib/plugins/video/parsers.js.map +1 -1
- package/lib/plugins/video/types.d.ts +6 -1
- package/lib/plugins/video/utils.js +2 -5
- package/lib/plugins/video/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/transform/plugins/images/index.ts +1 -1
- package/src/transform/plugins/video/const.ts +3 -10
- package/src/transform/plugins/video/index.ts +14 -9
- package/src/transform/plugins/video/parsers.ts +13 -21
- package/src/transform/plugins/video/types.ts +8 -1
- package/src/transform/plugins/video/utils.ts +2 -5
- package/lib/plugins/csp.d.ts +0 -6
- package/lib/plugins/csp.js +0 -26
- package/lib/plugins/csp.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {VideoService} from './const';
|
|
2
|
+
import {Services} from './types';
|
|
2
3
|
|
|
3
4
|
const ytRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
|
4
5
|
export function youtubeParser(url: string) {
|
|
@@ -51,15 +52,9 @@ export function rutubeParser(url: string) {
|
|
|
51
52
|
return match ? match[1] : url;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
/*
|
|
56
|
-
dzen /embed/<id> and /video/watch/<id> are not the same
|
|
57
|
-
so we can't extract something from url and should pass it next
|
|
58
|
-
*/
|
|
59
|
-
return url;
|
|
60
|
-
}
|
|
55
|
+
const urlParser = (url: string) => url;
|
|
61
56
|
|
|
62
|
-
const supportedServices =
|
|
57
|
+
const supportedServices = {
|
|
63
58
|
osf: {
|
|
64
59
|
extract: mfrParser,
|
|
65
60
|
},
|
|
@@ -81,40 +76,37 @@ const supportedServices = Object.entries({
|
|
|
81
76
|
vk: {
|
|
82
77
|
extract: vkParser,
|
|
83
78
|
csp: {
|
|
84
|
-
'frame-src': 'https://vk.com/',
|
|
79
|
+
'frame-src': ['https://vk.com/'],
|
|
85
80
|
},
|
|
86
81
|
},
|
|
87
82
|
rutube: {
|
|
88
83
|
extract: rutubeParser,
|
|
89
84
|
csp: {
|
|
90
|
-
'frame-src': 'https://rutube.ru/play/embed/',
|
|
85
|
+
'frame-src': ['https://rutube.ru/play/embed/'],
|
|
91
86
|
},
|
|
92
87
|
},
|
|
93
|
-
|
|
94
|
-
extract:
|
|
95
|
-
csp: {
|
|
96
|
-
'frame-src': ['https://dzen.ru/embed/', 'https://dzen.ru/video/'],
|
|
97
|
-
},
|
|
88
|
+
url: {
|
|
89
|
+
extract: urlParser,
|
|
98
90
|
},
|
|
99
|
-
}
|
|
91
|
+
} as Services;
|
|
100
92
|
|
|
101
93
|
export function parseVideoUrl(service: string, url: string) {
|
|
102
94
|
let videoID = '';
|
|
103
95
|
const normalizedService = service.toLowerCase();
|
|
104
|
-
const parsed = supportedServices
|
|
96
|
+
const parsed = supportedServices[normalizedService as VideoService];
|
|
105
97
|
|
|
106
98
|
if (!parsed) {
|
|
107
99
|
return false;
|
|
108
100
|
}
|
|
109
101
|
|
|
110
|
-
const
|
|
102
|
+
const {extract, csp} = parsed;
|
|
111
103
|
|
|
112
|
-
videoID =
|
|
104
|
+
videoID = extract(url);
|
|
113
105
|
|
|
114
106
|
// If the videoID field is empty, regex currently make it the close parenthesis.
|
|
115
107
|
if (videoID === ')') {
|
|
116
108
|
videoID = '';
|
|
117
109
|
}
|
|
118
110
|
|
|
119
|
-
return [videoID,
|
|
111
|
+
return [videoID, csp] as const;
|
|
120
112
|
}
|
|
@@ -17,8 +17,15 @@ export type VideoServicesOptions = {
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
export type Service = {
|
|
21
|
+
csp?: Record<string, string[]>;
|
|
22
|
+
extract(url: string): string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type Services = Record<VideoService, Service>;
|
|
26
|
+
|
|
20
27
|
export type VideoFullOptions = VideoServicesOptions & {
|
|
21
|
-
|
|
28
|
+
videoUrl: VideoUrlFn;
|
|
22
29
|
};
|
|
23
30
|
|
|
24
31
|
export type VideoPluginOptions = Partial<VideoFullOptions>;
|
|
@@ -23,11 +23,8 @@ export const videoUrl: VideoUrlFn = (service, videoID, options) => {
|
|
|
23
23
|
return `https://vk.com/video_ext.php?${videoID}`;
|
|
24
24
|
case 'rutube':
|
|
25
25
|
return `https://rutube.ru/play/embed/${videoID}`;
|
|
26
|
-
case '
|
|
27
|
-
|
|
28
|
-
return videoID;
|
|
29
|
-
}
|
|
30
|
-
return `https://dzen.ru/embed/${videoID}`;
|
|
26
|
+
case 'url':
|
|
27
|
+
return videoID;
|
|
31
28
|
default:
|
|
32
29
|
return service;
|
|
33
30
|
}
|
package/lib/plugins/csp.d.ts
DELETED
package/lib/plugins/csp.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collect = exports.requestCSP = void 0;
|
|
4
|
-
let csp = {};
|
|
5
|
-
const requestCSP = (policy) => {
|
|
6
|
-
for (const [field, content] of Object.entries(policy)) {
|
|
7
|
-
if (!csp[field]) {
|
|
8
|
-
csp[field] = [];
|
|
9
|
-
}
|
|
10
|
-
const flat = Array.isArray(content) ? content : [content];
|
|
11
|
-
for (const value of flat) {
|
|
12
|
-
if (csp[field].includes(value)) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
csp[field].push(value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
exports.requestCSP = requestCSP;
|
|
20
|
-
const collect = () => {
|
|
21
|
-
const usedCSP = Object.assign({}, csp);
|
|
22
|
-
csp = {};
|
|
23
|
-
return usedCSP;
|
|
24
|
-
};
|
|
25
|
-
exports.collect = collect;
|
|
26
|
-
//# sourceMappingURL=csp.js.map
|
package/lib/plugins/csp.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csp.js","sourceRoot":"","sources":["../../src/transform/plugins/csp.ts"],"names":[],"mappings":";;;AAAA,IAAI,GAAG,GAA6B,EAAE,CAAC;AAIvC,MAAM,UAAU,GAAG,CAAC,MAAiB,EAAE,EAAE;IACrC,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACnD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACb,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;SACnB;QAED,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAE1D,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE;YACtB,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC5B,SAAS;aACZ;YAED,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;KACJ;AACL,CAAC,CAAC;AAUM,gCAAU;AARlB,MAAM,OAAO,GAAG,GAAG,EAAE;IACjB,MAAM,OAAO,qBAAO,GAAG,CAAC,CAAC;IAEzB,GAAG,GAAG,EAAE,CAAC;IAET,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEkB,0BAAO"}
|