是否可以使用 C# Markdown 库在 Markdown 中嵌入 Youtube/Vimeo 视频 [英] Is it possible to embed Youtube/Vimeo videos in Markdown using a C# Markdown library

查看:58
本文介绍了是否可以使用 C# Markdown 库在 Markdown 中嵌入 Youtube/Vimeo 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 .NET MVC4 中编写一个 Web 应用程序,并且想使用 Markdown.我知道有一些开源 C# Markdown 库,但我还没有找到一个明显支持在 Markdown 文本中嵌入 youtube 或 Vimeo 视频的库.

I'm writing a web app in .NET MVC4 and would like to use Markdown. I understand there are a few open source C# Markdown libraries, but I haven't found one that obviously supports embedding youtube or Vimeo videos inside Markdown text.

有人知道这是否可能吗?

Does anyone know if it's possible?

推荐答案

The Solution using Standard Markdown ( not iFrame! )

使用 iframe 不是明显"的解决方案...尤其如果 Markdown 解析器 (或发布平台)您使用的不支持内联来自其他网站的内容......相反,您可以通过在 Markdown 中包含有效链接图像来伪造"文件,使用以下格式:

The Solution using Standard Markdown ( not iFrame! )

Using an iframe is not the "obvious" solution... especially if the Markdown parser (or publishing platform) you are using does not support inlining content from a different website ... Instead you can "fake it" by including a valid linked-image in your Markdown file, using this format:

[![IMAGE ALT TEXT](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE"视频标题")

如果这个 Markdown 代码片段看起来很复杂,请将其分解为两部分:

If this markdown snippet looks complicated, break it down into two parts:

一张图片
![图片替代文字](http//example.io/link-to-image)
包裹在链接中
[链接文字](http//example.io/my-link "链接标题")

我们从 YouTube 直接获取缩略图图像并链接到实际视频,因此当人们点击图像/缩略图时,他们将被带到视频中.

We are sourcing the thumbnail image directly from YouTube and linking to the actual video, so when the person clicks the image/thumbnail they will be taken to the video.

[![一切都很棒](https://img.youtube.com/vi/StTqXEQ2l-Y/0.jpg)](https://www.youtube.com/watch?v=StTqXEQ2l-Y一切都很棒")

OR如果您想给读者一个视觉提示,即图像/缩略图实际上是一个可播放视频,在 YouTube 中拍摄您自己的视频截图,并将其用作缩略图.

OR If you want to give readers a visual cue that the image/thumbnail is actually a playable video, take your own screenshot of the video in YouTube and use that as the thumbnail instead.

[![一切都很棒](http://i.imgur.com/Ot5DWAW.png)](https://youtu.be/StTqXEQ2l-Y?t=35s "一切都很棒")

虽然这需要几个额外的步骤 (a) 截取视频的屏幕截图和 (b) 上传它 因此您可以将图像用作缩略图,它确实具有3 个明显优势:

While this requires a couple of extra steps (a) taking the screenshot of the video and (b) uploading it so you can use the image as your thumbnail it does have 3 clear advantages:

  1. 阅读您的 Markdown(或生成的 html 页面)的人有一个视觉提示告诉他们他们可以观看视频(视频控件鼓励点击)
  2. 您可以选择视频中的特定帧用作缩略图(从而使您的内容更具吸引力)
  3. 您可以链接到视频中的特定时间,点击链接的图像时将从该时间开始播放.(在我们的例子中是 35 秒)
  1. The person reading your markdown (or resulting html page) has a visual cue telling them they can watch the video (video controls encourage clicking)
  2. You can chose a specific frame in the video to use as the thumbnail (thus making your content more engaging)
  3. You can link to a specific time in the video from which play will start when the linked-image is clicked. (in our case from 35 seconds)

截取屏幕截图需要几秒钟时间,每个操作系统都有键盘快捷键,可以将屏幕截图复制到剪贴板,这意味着您可以粘贴以加快上传速度.

Taking a screenshot takes a few seconds and there are keyboard shortcuts for each OS which copy the screenshot to your clipboard which means you can paste it for even faster upload.

而且由于这是100% 标准降价,它适用于任何地方(不仅适用于C#code> 解析器!) ...在 GitHub、Reedit 或 Ghost 上试用!

And since this is 100% Standard markdown, it works everywhere (not just for the C# parser!) ... try it on GitHub, Redit or Ghost!

这种方法也适用于 Vimeo 视频

This approach also works with Vimeo videos

[![Little red ridning hood](http://i.imgur.com/7YTMFQp.png)](https://vimeo.com/3514904 "Little red riding hood - Click to Watch!")

注意事项:

  • 如何截取屏幕截图:http://www.take-a-screenshot.org/(所有平台!)
  • 上传缩略图:截取屏幕截图后,您可以将其拖放imgur.com上传并立即将其用作您的缩略图;再简单不过了
  • YouTube 缩略图信息:如何如何从 YouTube API 获取 YouTube 视频缩略图?
  • Markdown 格式借用/修改/扩展自:嵌入 YouTube 视频

    Notes:

    • How to take screenshot: http://www.take-a-screenshot.org/ (all platforms!)
    • Upload Thumbnail Image: Once you've taken your screenshot you can drag-and-drop it into imgur.com to upload and immediately use it as your thumbnail; couldn't be easier!
    • YouTube thumbnail info: How do I get a YouTube video thumbnail from the YouTube API?
    • Markdown format borrowed/modified/expanded from: Embed a YouTube video
    • 这篇关于是否可以使用 C# Markdown 库在 Markdown 中嵌入 Youtube/Vimeo 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆