Markdown includes syntax for embedding images, but not audio and video files. Embedded video in particular has become a lot more commonplace since John Gruber wrote the original Markdown spec. It would be good to have a standard, er common, way to embedded audio and video using Markdown.
I currently use the following syntax, transforming image tags based on particular file extensions:
![](filename.mp3)
produces
<audio controls="controls">
<source type="audio/mp3" src="filename.mp3"></source>
<source type="audio/ogg" src="filename.ogg"></source>
<p>Your browser does not support the audio element.</p>
</audio>
And for video:
![](filename.mp4)
produces:
<video controls="controls">
<source type="video/mp4" src="filename.mp4"></source>
<source type="video/webm" src="filename.webm"></source>
<p>Your browser does not support the video element.</p>
</video>
The solution I posted works because the system deals with very particular file formats and extensions. I can see it creating problems with more flexible systems.
Something like the solution you posted seems good. I would use sensible defaults for the options, rather than getting the user to explicitly define them.
Need to necro this topic , coz worth it .
As @chrisalley did. How about we agree on letting the implementation decide what to display, and just use common syntax for everything?
![](whatever it is.png/jpg/gif/mp4/webm/mp3/audio)
<audio controls="controls">
<source type="audio/mp3" src="filename.mp3"></source>
<source type="audio/ogg" src="filename.ogg"></source>
<p>Your browser does not support the audio element.</p>
</audio>
I would like to suggest that we use
![](filename.mp3 filename.ogg)
using white space to separate the files and having the first file to dictate the HTML element.
For example
![](filename.mp4 filename.mp3)
will create
<video controls="controls">
<source type="video/mp4" src="filename.mp4"></source>
<source type="video/mp3" src="filename.mp3"></source>
<p>Your browser does not support the video element.</p>
</video>
I agree, hence ![foo](bar) should not be seen and described as “image syntax”, but as “embedded resource syntax”. Embedding is special kind of hyperlinking.
Back in the day, when <img> was new to HTML and terminals were more common than GUIs and bandwidth was scarce, images – most likely figures then – would often be shown on demand only and not embedded within the text, although the name of the src attribute already suggests that it should be treated differently than those with href. Anyhow, an embedded resource is a special kind of link, whether it be a static image, video, audio, text (<iframe>) or an interactive component (<embed>).
A third type of links are transclusions. This kind is not necessary to support in a front-end format such as HTML, but should be a feature of a back-end format like Commonmark. Otherwise one needs another tool layer, i.e. a preprocessor. A well-known example are {{templates}} in MediaWiki. Transclusions in CM/MD should use a syntax similar to embeds, probably just switch the exclamation mark for a different punctuation character, maybe require them to be in a line or block by themselves, e.g.:
<[Introduction](chapter0.md)
This does not solve external code listings well, though, because you would have to put markup inside them since fences and indents won’t work:
Agreed on a common syntax. There should be a sensible default rendering as well so that CommonMark documents are compatible across different websites and apps.
Explicitly listing the file types like this is probably the safest route. Otherwise the parser would have to know in advance (or check at the time of rendering) which files to include. If another file format is added in the future (say, a flac version), the document could either be updated manually (or perhaps programmatically if a flac version is added for every audio track in the larger file set).
I’m in agreement (as a CommonMark extension, not as part of the core spec).
If the extension is enabled, the ![]() syntax should render the content based on the specified file extension, e.g. ![](file.mp4) would render the HTML <video> tag. If the extension is not enabled, the syntax will attempt to render the HTML <img> tag regardless of the specified file extension.
For the extension to be viable we would need a white list of file extensions that would be used to render as the particular content types - image, audio, video, and perhaps other content types.
The reference implementation is only for CommonMark syntax I believe. But @jgm has not yet confirmed if an audio and video extension will be supported, or if the syntax we’ve discussed here will be used.
syntax not just for images but for embedded audio and video, and let the renderer create tags appropriate for the resource, based on the extension.
This might call for some changes in the spec, renaming the element from “image” to “media” or something more generic, and adding some words about the flexibility in rendering. I’m not sure. In any case, as an extension this idea is completely natural.
@v3ss0n, are you going to shape your code as a plugin? We at diaspora need it to implement audio/video embedding. If not, I could probably make the plugin by myself basing on your code.
I will make a repo , i still learning how to do a proper markdown-it plugin.
We are also building something similar to diaspora but aimed for Group Conversation , instead of social network.
I think it would be best if the core spec continues to describe the element as “image”. The HTML5 spec refers to the category of elements as embedded content. If the element is called “embedded content” or “media” in the core spec, people might be lead to believe that other embedded content is available as part of CommonMark-core. But this is intended as an extension, correct?
I was actually not thinking of it as an extension. More of a terminology change.
Currently the spec attempts to define parsing (transformation from source to AST) without being too detailed about exactly how each element should be rendered into HTML (or other formats). Loosening up the terminology would invite renderers to do something useful with movie and sound URLs in ![]() contexts, without requiring anything specific.
A further step would be to say explicitly that renderers must be sensitive to the URL or file extension (if there is one) and render the media in a way that makes sense. But I’m thinking this might be a bit much to require. And maybe the terminology change doesn’t make sense without this, I’m not sure.