From 383e81a35cd263781f9f2fa5df3de6f19c281c46 Mon Sep 17 00:00:00 2001 From: Juho Rutila Date: Thu, 8 Aug 2024 08:30:36 +0300 Subject: [PATCH 1/2] Initial local player support --- index.js | 18 ++++++++++++++++++ test/fixtures/video.txt | 7 +++++++ test/test.js | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/index.js b/index.js index ab35e1e..9028a75 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ // Process @[vine](vineVideoID) // Process @[prezi](preziID) // Process @[osf](guid) +// Process @[local](url) const ytRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/; function youtubeParser(url) { @@ -74,6 +75,8 @@ function videoEmbed(md, options) { videoID = preziParser(videoID); } else if (serviceLower === 'osf') { videoID = mfrParser(videoID); + } else if (serviceLower === 'local') { + // videoID = videoID; } else if (!options[serviceLower]) { return false; } @@ -176,6 +179,8 @@ function videoUrl(service, videoID, url, options) { 'landing_sign=1kD6c0N6aYpMUS0wxnQjxzSqZlEB8qNFdxtdjYhwSuI'; case 'osf': return 'https://mfr.osf.io/render?url=https://osf.io/' + videoID + '/?action=download'; + case 'local': + return videoID; default: return service; } @@ -202,6 +207,18 @@ function tokenizeVideo(md, options) { ' }); '; } + if (service === 'local' && videoID) { + const localPlayerAttrs = []; + + const keys = Object.keys(options[service]); + const values = Object.values(options[service]); + + for (let i = 0; i < keys.length; i += 1) { + localPlayerAttrs.push(keys[i] + '="' + values[i] + '"'); + } + return ''; + } + return videoID === '' ? '' : '

. +Coverage. Local from URL +. +@[local](test_video.webm) +. +

+. + Coverage. Line Breaks . @[vine](MhQ2lvg29Un) @[vine](MhQ2lvg29Un) diff --git a/test/test.js b/test/test.js index 2d11b3e..fbfd9fb 100644 --- a/test/test.js +++ b/test/test.js @@ -32,6 +32,10 @@ describe('markdown-it-video: options', function () { autoplay: 0, }, }, + local: { + controls: false, + allowfullscreen: false, + }, }); var renderedHtml; @@ -44,6 +48,11 @@ describe('markdown-it-video: options', function () { renderedHtml = md.render('@[youtube](youtube.com/embed/0zM3nApSvMg?autoplay=1&rel=0)'); assert.equal(renderedHtml, '

\n'); }); + + it('local options', function () { + renderedHtml = md.render('@[local](test_video.webm)'); + assert.equal(renderedHtml, '

\n'); + }); }); // Because the mfr iframe requires a random id these tests cannont be part of From a37c5b5516095bc3a9cbdf6ee76868770ca5680e Mon Sep 17 00:00:00 2001 From: Juho Rutila Date: Thu, 8 Aug 2024 08:31:01 +0300 Subject: [PATCH 2/2] Update README for local video --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 19c00f6..47cae97 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,22 @@ Alternately, you could use the url. ```md @[osf](https://mfr.osf.io/render?url=https://osf.io/kuvg9/?action=download) ``` + +#### Local video + +This mode results in default HTML5 video player using the given url as source. +The url can point to external source or something relative for current path. + +```md +@[local](test_video.webm) +``` + +is interpreted as + +```html +

+``` + ## Options