Skip to content

rjriel/markdown-it-iframe

Repository files navigation

markdown-it-iframe

Build Status NPM version Coverage Status

Iframe (<iframe>) tag plugin for markdown-it markdown parser.

v1.+ requires markdown-it v4.+, see changelog.

Markdown:

Below will render an iframe

/i/https://www.youtube.com/embed/qkcx0kf6jME

HTML:

<p>Below will render an iframe</p>
<div class="iframe-container">
<iframe frameborder="0" src="https://www.youtube.com/embed/qkcx0kf6jME"></iframe>
</div>

Install

node.js, browser:

npm install markdown-it-iframe --save
bower install markdown-it-iframe --save

Use

var md = require('markdown-it')()
            .use(require('markdown-it-iframe'));

md.render(/*...*/) // see example above

markdown-it-iframe also supports the following options:

{
    allowfullscreen: true,
    width: 800,
    height: 600,
    frameborder: 1, // default: 0
    renderIframe: false // default: true
}

If you want to do a live preview of markdown rendering you will run into performance issues when the user is typing out a URL for the iframe. The reason for this is that markdown-it tries to render the URL being typed out with every keystroke. To combat this you can specify renderIframe: false. This will print a message with the markdown instead of the actual iframe.

Differences in browser. If you load script directly into the page, without package system, module will add itself globally as window.markdownitIframe.

License

MIT