是否可以使用 C# Markdown 库在 Markdown 中嵌入 Youtube/Vimeo 视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14192709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to embed Youtube/Vimeo videos in Markdown using a C# Markdown library
提问by Matt
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.
我正在 .NET MVC4 中编写一个 Web 应用程序,并想使用 Markdown。我知道有一些开源 C# Markdown 库,但我还没有找到一个明显支持在 Markdown 文本中嵌入 youtube 或 Vimeo 视频的库。
Does anyone know if it's possible?
有谁知道这是否可能?
采纳答案by nelsonic
The Solution using Standard Markdown( not iFrame!)
使用标准 Markdown的解决方案(不是 iFrame!)
Using an iframe is notthe "obvious" solution... especiallyif 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-imagein your Markdown file, using this format:
使用 iframe并不是“显而易见”的解决方案……尤其是如果您使用的 Markdown 解析器(或发布平台)不支持内联来自不同网站的内容……相反,您可以通过包含有效链接来“伪造” -image在您的 Markdown 文件中,使用以下格式:
[](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE "Video Title")
[](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE "Video Title")
Explanation of the Markdown
Markdown 的解释
If this markdown snippet looks complicated, break it down into two parts:
如果这个 Markdown 片段看起来很复杂,请将其分解为两部分:
an image
wrapped in a link[link text](http//example.io/my-link "link title")

包含在链接中的图像[link text](http//example.io/my-link "link title")
Example using Valid Markdown and YouTube Thumbnail:
使用 Valid Markdown 和 YouTube 缩略图的示例:
We are sourcing the thumbnailimage directlyfrom YouTube and linking to the actual video, so when the person clicks the image/thumbnail they will be taken to the video.
我们采购的缩略图像直接从YouTube和链接到实际视频,所以当人点击图像/缩略图,他们将采取视频。
Code:
代码:
[](https://www.youtube.com/watch?v=StTqXEQ2l-Y "Everything Is AWESOME")
[](https://www.youtube.com/watch?v=StTqXEQ2l-Y "Everything Is AWESOME")
ORIf you want to give readers a visual cuethat the image/thumbnail is actually a playablevideo, take your own screenshot of the video in YouTube and use that as the thumbnail instead.
或如果您想向读者提供图像/缩略图实际上是可播放视频的视觉提示,请在 YouTube 中拍摄您自己的视频截图,并将其用作缩略图。
Example using Screenshot with Video Controls as Visual Cue:
使用带有视频控件的屏幕截图作为视觉提示的示例:
Code:
代码:
[](https://youtu.be/StTqXEQ2l-Y?t=35s "Everything Is AWESOME")
[](https://youtu.be/StTqXEQ2l-Y?t=35s "Everything Is AWESOME")
?ClearAdvantages
? 明显的优势
While this requires a couple of extra steps (a) taking the screenshotof the video and (b) uploading itso you can use the image as your thumbnail it does have 3 clearadvantages:
虽然这需要几个额外的步骤 ( a)截取视频的屏幕截图和 ( b)上传它以便您可以将图像用作缩略图,但它确实具有3 个明显的优点:
- The person reading your markdown (or resulting html page) has a visual cuetelling them they can watch the video (video controls encourage clicking)
- You can chose a specific framein the video to use as the thumbnail (thus making your content more engaging)
- You can link to a specific timein the video from which play will start when the linked-image is clicked. (in our case from 35 seconds)
- 阅读您的 Markdown(或生成的 html 页面)的人有一个视觉提示,告诉他们他们可以观看视频(视频控件鼓励点击)
- 您可以选择视频中的特定帧用作缩略图(从而使您的内容更具吸引力)
- 您可以链接到视频中的特定时间,单击链接图像时将从该时间开始播放。(在我们的例子中是 35 秒)
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 pasteit for even faster upload.
截取屏幕截图需要几秒钟,每个操作系统都有键盘快捷键,可以将屏幕截图复制到剪贴板,这意味着您可以粘贴它以加快上传速度。
Not OnlyC#
不是只有C#
And since this is 100% Standardmarkdown, it works everywhere(not just for the C#
parser!) ... try it on GitHub, Redit or Ghost!
由于这是100% 标准降价,它适用于任何地方(不仅仅是C#
解析器!)......在 GitHub、Reedit 或 Ghost 上尝试!
Vimeo
维密欧
This approach also works with Vimeo videos
这种方法也适用于 Vimeo 视频
Example
例子
Code
代码
[](https://vimeo.com/3514904 "Little red riding hood - Click to Watch!")
Notes:
笔记:
- Howto take screenshot: http://www.take-a-screenshot.org/(all platforms!)
- Upload Thumbnail Image: Once you've taken your screenshot you can drag-and-dropit into imgur.comto uploadand 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
- 如何来采取截图:http://www.take-a-screenshot.org/(所有平台!)
- 上传缩略图:截取屏幕截图后,您可以将其拖放到imgur.com进行上传并立即将其用作缩略图;再简单不过了!
- YouTube 缩略图信息:如何从 YouTube API 获取 YouTube 视频缩略图?
- Markdown 格式借用/修改/扩展自:嵌入 YouTube 视频
回答by sloth
You can use inline HTMLto embed your video.
您可以使用内联 HTML来嵌入您的视频。
# this is a *markdown* document
<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/watch?v=TheVideoID?autoplay=1" frameborder="0" allowfullscreen></iframe>
with a **youtube** video embedded
回答by Romain
What about the syntax for embedding image, applied to other media?
嵌入图像的语法如何应用于其他媒体?

Oembed is interesting to make embedding easier: users just have to paste the URL instead of an iframe code. For video, it could be
Oembed 很有趣,可以使嵌入更容易:用户只需粘贴 URL 而不是 iframe 代码。对于视频,它可能是

回答by johnnymire
<iframe width="560" height="315" src="https://www.youtube.com/embed/-mUJnKI3ipI" frameborder="0" allowfullscreen></iframe>