From dde7fa2d72df3d625e4656d8dbf10425fa1736f0 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Tue, 2 May 2023 18:21:47 +0200 Subject: [PATCH] feat(#204): display videos in md --- public/script/utils.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/public/script/utils.js b/public/script/utils.js index 59fe6cb..3062d9c 100644 --- a/public/script/utils.js +++ b/public/script/utils.js @@ -141,19 +141,25 @@ function renderMD(md, baseUrl) { } // call default renderer return rendererCode.call(this, code, lang, escaped); - - // return rendererCode(code, lang, escaped); }; const rendererCodespan = renderer.codespan; renderer.codespan = function (text) { const math = mathsExpression(text); - if (math) { return math; } - return rendererCodespan(text); + return rendererCodespan.call(this, text); + }; + + const rendererLink = renderer.link; + renderer.link = function (href, title, text) { + // wrap videos links (mp4 and mov) with media https://github.blog/2021-05-13-video-uploads-available-github/ + if (href.match(/\.mp4$|\.mov$/)) { + return `
`; + } + return rendererLink.call(this, href, title, text); }; return marked.parse(md, { baseUrl, renderer }); }