Skip to content

Commit

Permalink
Add support for <iframe> to link or ignoring
Browse files Browse the repository at this point in the history
Closes GH-48.
  • Loading branch information
wooorm committed May 25, 2019
1 parent 1f58cc6 commit 2b6df07
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
23 changes: 23 additions & 0 deletions lib/handlers/iframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

module.exports = iframe

var resolve = require('../util/resolve')

function iframe(h, node) {
var src = node.properties.src
var title = node.properties.title

// Only create a link if there is a title.
// We can’t use `content` because conforming HTML parsers treat it as text,
// whereas legacy parsers treat it as HTML, so they will likely contain tags
// that will show up in text.
if (src && title) {
return {
type: 'link',
title: null,
url: resolve(h, src),
children: [{type: 'text', value: title}]
}
}
}
2 changes: 2 additions & 0 deletions lib/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var dataList = require('./data-list')
var del = require('./delete')
var emphasis = require('./emphasis')
var heading = require('./heading')
var iframe = require('./iframe')
var image = require('./image')
var inlineCode = require('./inline-code')
var link = require('./link')
Expand Down Expand Up @@ -149,6 +150,7 @@ exports.h5 = heading
exports.h6 = heading
exports.hr = thematicBreak
exports.i = emphasis
exports.iframe = iframe
exports.img = image
exports.image = image
exports.kbd = inlineCode
Expand Down
9 changes: 0 additions & 9 deletions lib/handlers/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ function listItem(h, node) {
}
}

// Drop empty paragraph.
if (content.length === 1) {
head = content[0]

if (head.type === 'paragraph' && head.children.length === 0) {
content = []
}
}

return h(
node,
'listItem',
Expand Down
9 changes: 8 additions & 1 deletion lib/handlers/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ module.exports = paragraph
var all = require('../all')

function paragraph(h, node) {
return h(node, 'paragraph', all(h, node))
var children = node.children
var nodes = all(h, node)

if (children && children.length !== 0 && nodes.length === 0) {
return
}

return h(node, 'paragraph', nodes)
}
13 changes: 13 additions & 0 deletions test/fixtures/iframe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p><iframe sandbox srcdoc="<em>alpha</em>"></iframe></p>

<p><iframe src="bravo.html" sandbox></iframe></p>

<p>
<iframe src="charlie.html" title="Delta">
Echo <code>foxtrot</code> <em>golf</em>.
</iframe>
</p>

<p><iframe src="hotel.html" title="India"></iframe></p>

<p><iframe src="juliett.html"></iframe></p>
3 changes: 3 additions & 0 deletions test/fixtures/iframe/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fragment": true
}
3 changes: 3 additions & 0 deletions test/fixtures/iframe/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Delta](charlie.html)

[India](hotel.html)

0 comments on commit 2b6df07

Please sign in to comment.