Skip to content

Commit 2b6df07

Browse files
authored
Add support for <iframe> to link or ignoring
Closes GH-48.
1 parent 1f58cc6 commit 2b6df07

File tree

7 files changed

+52
-10
lines changed

7 files changed

+52
-10
lines changed

lib/handlers/iframe.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
module.exports = iframe
4+
5+
var resolve = require('../util/resolve')
6+
7+
function iframe(h, node) {
8+
var src = node.properties.src
9+
var title = node.properties.title
10+
11+
// Only create a link if there is a title.
12+
// We can’t use `content` because conforming HTML parsers treat it as text,
13+
// whereas legacy parsers treat it as HTML, so they will likely contain tags
14+
// that will show up in text.
15+
if (src && title) {
16+
return {
17+
type: 'link',
18+
title: null,
19+
url: resolve(h, src),
20+
children: [{type: 'text', value: title}]
21+
}
22+
}
23+
}

lib/handlers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var dataList = require('./data-list')
1212
var del = require('./delete')
1313
var emphasis = require('./emphasis')
1414
var heading = require('./heading')
15+
var iframe = require('./iframe')
1516
var image = require('./image')
1617
var inlineCode = require('./inline-code')
1718
var link = require('./link')
@@ -149,6 +150,7 @@ exports.h5 = heading
149150
exports.h6 = heading
150151
exports.hr = thematicBreak
151152
exports.i = emphasis
153+
exports.iframe = iframe
152154
exports.img = image
153155
exports.image = image
154156
exports.kbd = inlineCode

lib/handlers/list-item.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ function listItem(h, node) {
4444
}
4545
}
4646

47-
// Drop empty paragraph.
48-
if (content.length === 1) {
49-
head = content[0]
50-
51-
if (head.type === 'paragraph' && head.children.length === 0) {
52-
content = []
53-
}
54-
}
55-
5647
return h(
5748
node,
5849
'listItem',

lib/handlers/paragraph.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@ module.exports = paragraph
55
var all = require('../all')
66

77
function paragraph(h, node) {
8-
return h(node, 'paragraph', all(h, node))
8+
var children = node.children
9+
var nodes = all(h, node)
10+
11+
if (children && children.length !== 0 && nodes.length === 0) {
12+
return
13+
}
14+
15+
return h(node, 'paragraph', nodes)
916
}

test/fixtures/iframe/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<p><iframe sandbox srcdoc="<em>alpha</em>"></iframe></p>
2+
3+
<p><iframe src="bravo.html" sandbox></iframe></p>
4+
5+
<p>
6+
<iframe src="charlie.html" title="Delta">
7+
Echo <code>foxtrot</code> <em>golf</em>.
8+
</iframe>
9+
</p>
10+
11+
<p><iframe src="hotel.html" title="India"></iframe></p>
12+
13+
<p><iframe src="juliett.html"></iframe></p>

test/fixtures/iframe/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"fragment": true
3+
}

test/fixtures/iframe/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Delta](charlie.html)
2+
3+
[India](hotel.html)

0 commit comments

Comments
 (0)