-
Notifications
You must be signed in to change notification settings - Fork 1
/
video-extension.js
48 lines (42 loc) · 1.57 KB
/
video-extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function (extension) {
'use strict';
if (typeof showdown !== 'undefined') {
// global (browser or nodejs global)
extension(showdown);
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['showdown'], extension);
} else if (typeof exports === 'object') {
// Node, CommonJS-like
module.exports = extension(require('showdown'));
} else {
// showdown was not found so we throw
throw Error('Could not find showdown library');
}
}(function (showdown) {
'use strict';
/**
* 支持 ![](https://video.mp4) 语法的视频显示。
*
* Support for the syntax of video display, syntax: ![](https://video.mp4)
*/
showdown.extension('video', function () {
return [
{
type: 'output',
regex: '<p><img src="(.+(mp4|ogg|webm).*?)"(.+?)\\/>',
replace: function (match, url, format, other) {
// Check if we matched the leading \ and return nothing changed if so
if (url === ('.' + format)) {
return match;
} else {
// src="https://image.png" alt="image alt text" title="image title" width="100" height="auto"
// var regex = /([a-z]+)="(.*?)"/g;
// return `<video src="${url}" ${other} controls>I am sorry; your browser does not support HTML5 video in WebM with VP8/VP9 or MP4 with H.264.</video>`;
return `<video ${other} controls><source src="${url}" type="video/${format}">I am sorry, Your browser does not support the <code>video</code> element.</video>`;
}
}
},
];
});
}));