rehype-video 1.1.0 → 1.2.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/README.md +43 -4
- package/lib/index.js +6 -4
- package/lib/index.js.map +1 -1
- package/package.json +14 -12
- package/src/index.ts +9 -3
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@ rehype-video
|
|
|
7
7
|
[](https://jaywcjlove.github.io/rehype-video/lcov-report/)
|
|
8
8
|
[](https://bundlephobia.com/result?p=rehype-video)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Add improved video syntax: links to `.mp4` and `.mov` turn into videos. like [`github video`](https://github.blog/2021-05-13-video-uploads-available-github/) features.
|
|
11
11
|
|
|
12
12
|
The following is a sample test of the video preview in GitHub:
|
|
13
13
|
|
|
14
|
-
https://user-images.githubusercontent.com/1680273/138299599-88547edd-859c-44c9-8b52-2cc06f7f2dd3.mov
|
|
14
|
+
https://user-images.githubusercontent.com/1680273/138299599-88547edd-859c-44c9-8b52-2cc06f7f2dd3.mov?!#label=rehype-video
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
@@ -35,7 +35,10 @@ https://files.github.com/001.mp4 hi!
|
|
|
35
35
|
|
|
36
36
|
https://files.github.com/002.mp4
|
|
37
37
|
|
|
38
|
-
Good \`idea
|
|
38
|
+
Good \`idea\`!!
|
|
39
|
+
|
|
40
|
+
https://github.com/002.mp4?!#title=Custom%20Title
|
|
41
|
+
`;
|
|
39
42
|
|
|
40
43
|
const htmlStr = unified()
|
|
41
44
|
.use(remarkParse)
|
|
@@ -59,6 +62,14 @@ Output:
|
|
|
59
62
|
<video muted controls style="max-height:640px;" src="https://github.com/002.mp4"></video>
|
|
60
63
|
</details>
|
|
61
64
|
<p>Good <code>idea</code>!!</p>
|
|
65
|
+
<details open>
|
|
66
|
+
<summary>
|
|
67
|
+
<svg aria-hidden height="16" width="16" viewBox="0 0 16 16" version="1.1" class="octicon octicon-device-camera-video"><path fill-rule="evenodd" d="M16 3.75a.75.75 0 00-1.136-.643L11 5.425V4.75A1.75 1.75 0 009.25 3h-7.5A1.75 1.75 0 000 4.75v6.5C0 12.216.784 13 1.75 13h7.5A1.75 1.75 0 0011 11.25v-.675l3.864 2.318A.75.75 0 0016 12.25v-8.5zm-5 5.075l3.5 2.1v-5.85l-3.5 2.1v1.65zM9.5 6.75v-2a.25.25 0 00-.25-.25h-7.5a.25.25 0 00-.25.25v6.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-4.5z"></path></svg>
|
|
68
|
+
<span aria-label="Video description Custom Title">Custom Title</span>
|
|
69
|
+
<span class="dropdown-caret"></span>
|
|
70
|
+
</summary>
|
|
71
|
+
<video muted controls style="max-height:640px;" src="https://github.com/002.mp4"></video>
|
|
72
|
+
</details>
|
|
62
73
|
```
|
|
63
74
|
|
|
64
75
|
### Example 1
|
|
@@ -101,6 +112,34 @@ Output:
|
|
|
101
112
|
<video muted controls style="max-height:640px;" src="https://github.com/004.mp4"></video>
|
|
102
113
|
```
|
|
103
114
|
|
|
115
|
+
## Custom Title
|
|
116
|
+
|
|
117
|
+
Define custom title parameter(E.g: `title=RehypeVideo`) with hash route:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const string = `https://github.com/002.mp4?!#title=Custom%20Title`;
|
|
121
|
+
const htmlStr = unified()
|
|
122
|
+
.use(remarkParse)
|
|
123
|
+
.use(remark2rehype, { allowDangerousHtml: true })
|
|
124
|
+
.use(rehypeVideo)
|
|
125
|
+
.use(stringify)
|
|
126
|
+
.processSync(string)
|
|
127
|
+
.toString();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Output:
|
|
131
|
+
|
|
132
|
+
```html
|
|
133
|
+
<details open>
|
|
134
|
+
<summary>
|
|
135
|
+
<svg aria-hidden height="16" width="16" viewBox="0 0 16 16" version="1.1" class="octicon octicon-device-camera-video"><path fill-rule="evenodd" d="M16 3.75a.75.75 0 00-1.136-.643L11 5.425V4.75A1.75 1.75 0 009.25 3h-7.5A1.75 1.75 0 000 4.75v6.5C0 12.216.784 13 1.75 13h7.5A1.75 1.75 0 0011 11.25v-.675l3.864 2.318A.75.75 0 0016 12.25v-8.5zm-5 5.075l3.5 2.1v-5.85l-3.5 2.1v1.65zM9.5 6.75v-2a.25.25 0 00-.25-.25h-7.5a.25.25 0 00-.25.25v6.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-4.5z"></path></svg>
|
|
136
|
+
<span aria-label="Video description Custom Title">Custom Title</span>
|
|
137
|
+
<span class="dropdown-caret"></span>
|
|
138
|
+
</summary>
|
|
139
|
+
<video muted controls style="max-height:640px;" src="https://github.com/002.mp4"></video>
|
|
140
|
+
</details>
|
|
141
|
+
```
|
|
142
|
+
|
|
104
143
|
## Options
|
|
105
144
|
|
|
106
145
|
```ts
|
|
@@ -130,4 +169,4 @@ export declare type RehypeVideoOptions = {
|
|
|
130
169
|
|
|
131
170
|
## License
|
|
132
171
|
|
|
133
|
-
MIT © [Kenny Wong](https://github.com/jaywcjlove)
|
|
172
|
+
MIT © [Kenny Wong](https://github.com/jaywcjlove)
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
-
import { detailsNode } from './detailsNode';
|
|
2
|
+
import { detailsNode } from './detailsNode.js';
|
|
3
3
|
const properties = { muted: 'muted', controls: 'controls', style: 'max-height:640px;' };
|
|
4
|
+
const queryStringToObject = (url) => [...new URLSearchParams(url.split('?!#')[1])].reduce((a, [k, v]) => ((a[k] = v), a), {});
|
|
4
5
|
function reElement(node, details, href) {
|
|
5
|
-
const filename = href.split('/').pop();
|
|
6
|
+
const filename = href.split('/').pop()?.replace(/(\?|!|\#|$).+/, '');
|
|
6
7
|
node.properties = { ...properties, src: href };
|
|
7
8
|
node.tagName = 'video';
|
|
8
9
|
node.children = [];
|
|
10
|
+
const { title = filename } = queryStringToObject(href);
|
|
9
11
|
if (details) {
|
|
10
|
-
const reNode = detailsNode(
|
|
12
|
+
const reNode = detailsNode(title);
|
|
11
13
|
reNode.children.push({ ...node });
|
|
12
14
|
node.children = reNode.children;
|
|
13
15
|
node.tagName = reNode.tagName;
|
|
@@ -18,7 +20,7 @@ const RehypeVideo = (options) => {
|
|
|
18
20
|
const { test = /\/(.*)(.mp4|.mov)$/, details = true } = options || {};
|
|
19
21
|
return (tree) => {
|
|
20
22
|
visit(tree, 'element', (node, index, parent) => {
|
|
21
|
-
const isChecked = (str) => test.test(str);
|
|
23
|
+
const isChecked = (str) => test.test(str.replace(/(\?|!|\#|$).+/g, ''));
|
|
22
24
|
const child = node.children[0];
|
|
23
25
|
const delimiter = /((?:https?:\/\/)(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/g;
|
|
24
26
|
// const delimiter = /((?:https?:\/\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/g;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAe5C,MAAM,UAAU,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAA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,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;oBAC1J,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;iBACjD;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rehype-video",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Markdown supports video play with `.mp4` and `.mov` URLs.",
|
|
5
5
|
"homepage": "https://jaywcjlove.github.io/rehype-video",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"prepack": "npm run build",
|
|
14
14
|
"watch": "tsbb watch --disable-babel",
|
|
15
|
-
"build": "tsbb build --disable-babel",
|
|
15
|
+
"build": "tsbb build --disable-babel && npm run fix",
|
|
16
|
+
"fix": "tsc-esm-fix --target='lib' --ext='.js'",
|
|
16
17
|
"type-check": "tsc --noEmit",
|
|
17
18
|
"test": "tsbb test",
|
|
18
|
-
"coverage": "tsbb test --coverage"
|
|
19
|
+
"coverage": "tsbb test --coverage --bail"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -44,16 +45,17 @@
|
|
|
44
45
|
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"unified": "10.1.
|
|
48
|
-
"unist-util-visit": "4.1.0"
|
|
48
|
+
"unified": "~10.1.1",
|
|
49
|
+
"unist-util-visit": "~4.1.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"rehype": "12.0.0",
|
|
52
|
-
"rehype-stringify": "9.0.2",
|
|
53
|
-
"remark": "14.0.1",
|
|
54
|
-
"remark-gfm": "3.0.0",
|
|
55
|
-
"remark-parse": "10.0.0",
|
|
56
|
-
"remark-rehype": "10.
|
|
57
|
-
"
|
|
52
|
+
"rehype": "~12.0.0",
|
|
53
|
+
"rehype-stringify": "~9.0.2",
|
|
54
|
+
"remark": "~14.0.1",
|
|
55
|
+
"remark-gfm": "~3.0.0",
|
|
56
|
+
"remark-parse": "~10.0.0",
|
|
57
|
+
"remark-rehype": "~10.1.0",
|
|
58
|
+
"tsc-esm-fix": "~2.7.3",
|
|
59
|
+
"tsbb": "~3.7.1"
|
|
58
60
|
}
|
|
59
61
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,14 +17,20 @@ export type RehypeVideoOptions = {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const properties = { muted: 'muted', controls: 'controls', style: 'max-height:640px;' };
|
|
20
|
+
const queryStringToObject = (url: string) =>
|
|
21
|
+
[...new URLSearchParams(url.split('?!#')[1])].reduce(
|
|
22
|
+
(a: Record<string, string>, [k, v]) => ((a[k] = v), a),
|
|
23
|
+
{}
|
|
24
|
+
);
|
|
20
25
|
|
|
21
26
|
function reElement(node: Element, details: boolean, href: string) {
|
|
22
|
-
const filename = href.split('/').pop();
|
|
27
|
+
const filename = href.split('/').pop()?.replace(/(\?|!|\#|$).+/, '');
|
|
23
28
|
node.properties = { ...properties, src: href };
|
|
24
29
|
node.tagName = 'video';
|
|
25
30
|
node.children = [];
|
|
31
|
+
const { title = filename }= queryStringToObject(href);
|
|
26
32
|
if (details) {
|
|
27
|
-
const reNode = detailsNode(
|
|
33
|
+
const reNode = detailsNode(title);
|
|
28
34
|
reNode.children.push({ ...node });
|
|
29
35
|
node.children = reNode.children;
|
|
30
36
|
node.tagName = reNode.tagName;
|
|
@@ -36,7 +42,7 @@ const RehypeVideo: Plugin<[RehypeVideoOptions?], Root> = (options) => {
|
|
|
36
42
|
const { test = /\/(.*)(.mp4|.mov)$/, details = true } = options || {};
|
|
37
43
|
return (tree) => {
|
|
38
44
|
visit(tree, 'element', (node, index, parent) => {
|
|
39
|
-
const isChecked = (str: string) => test.test(str)
|
|
45
|
+
const isChecked = (str: string) => test.test(str.replace(/(\?|!|\#|$).+/g, ''))
|
|
40
46
|
const child = node.children[0];
|
|
41
47
|
const delimiter = /((?:https?:\/\/)(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/g;
|
|
42
48
|
// const delimiter = /((?:https?:\/\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/g;
|