@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.
Files changed (38) hide show
  1. package/dist/css/_yfm-only.css.map +2 -2
  2. package/dist/css/_yfm-only.min.css.map +2 -2
  3. package/dist/css/base.css.map +2 -2
  4. package/dist/css/base.min.css.map +2 -2
  5. package/dist/css/print.css.map +2 -2
  6. package/dist/css/yfm.css.map +2 -2
  7. package/dist/css/yfm.min.css.map +2 -2
  8. package/dist/js/base.js +2 -2
  9. package/dist/js/base.js.map +1 -1
  10. package/dist/js/base.min.js +1 -1
  11. package/dist/js/base.min.js.map +2 -2
  12. package/dist/js/yfm.js +5 -5
  13. package/dist/js/yfm.js.map +1 -1
  14. package/dist/js/yfm.min.js +1 -1
  15. package/dist/js/yfm.min.js.map +2 -2
  16. package/lib/plugins/images/index.js +1 -1
  17. package/lib/plugins/images/index.js.map +1 -1
  18. package/lib/plugins/video/const.d.ts +1 -6
  19. package/lib/plugins/video/const.js +3 -3
  20. package/lib/plugins/video/const.js.map +1 -1
  21. package/lib/plugins/video/index.js +10 -5
  22. package/lib/plugins/video/index.js.map +1 -1
  23. package/lib/plugins/video/parsers.d.ts +0 -1
  24. package/lib/plugins/video/parsers.js +12 -22
  25. package/lib/plugins/video/parsers.js.map +1 -1
  26. package/lib/plugins/video/types.d.ts +6 -1
  27. package/lib/plugins/video/utils.js +2 -5
  28. package/lib/plugins/video/utils.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/transform/plugins/images/index.ts +1 -1
  31. package/src/transform/plugins/video/const.ts +3 -10
  32. package/src/transform/plugins/video/index.ts +14 -9
  33. package/src/transform/plugins/video/parsers.ts +13 -21
  34. package/src/transform/plugins/video/types.ts +8 -1
  35. package/src/transform/plugins/video/utils.ts +2 -5
  36. package/lib/plugins/csp.d.ts +0 -6
  37. package/lib/plugins/csp.js +0 -26
  38. package/lib/plugins/csp.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import {Services} from './const';
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
- export function dzenParser(url: string) {
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 = Object.entries({
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
- dzen: {
94
- extract: dzenParser,
95
- csp: {
96
- 'frame-src': ['https://dzen.ru/embed/', 'https://dzen.ru/video/'],
97
- },
88
+ url: {
89
+ extract: urlParser,
98
90
  },
99
- }) as Services;
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.find(([name]) => name === normalizedService);
96
+ const parsed = supportedServices[normalizedService as VideoService];
105
97
 
106
98
  if (!parsed) {
107
99
  return false;
108
100
  }
109
101
 
110
- const [, videoParser] = parsed;
102
+ const {extract, csp} = parsed;
111
103
 
112
- videoID = videoParser.extract(url);
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, videoParser.csp] as const;
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
- url: VideoUrlFn;
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 'dzen':
27
- if (videoID.startsWith('https')) {
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
  }
@@ -1,6 +0,0 @@
1
- export declare type CustomCSP = Record<string, string | string[]>;
2
- declare const requestCSP: (policy: CustomCSP) => void;
3
- declare const collect: () => {
4
- [x: string]: string[];
5
- };
6
- export { requestCSP, collect };
@@ -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
@@ -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"}