Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 31d63d8

Browse files
author
Dom Harrington
committed
Remove enclosing <div> from markdown content
remarkjs/remark-react#54
1 parent 72872f7 commit 31d63d8

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`anchors 1`] = `
4-
"<div><p><a href=\\"http://example.com\\" target=\\"_self\\">link</a><br/>
4+
"<p><a href=\\"http://example.com\\" target=\\"_self\\">link</a><br/>
55
<a target=\\"_self\\" href=\\"\\">xss</a><br/>
66
<a href=\\"/docs/slug\\" target=\\"_self\\" class=\\"doc-link\\" data-sidebar=\\"slug\\">doc</a><br/>
77
<a href=\\"/reference#slug\\" target=\\"_self\\">ref</a><br/>
88
<a href=\\"/blog/slug\\" target=\\"_self\\">blog</a><br/>
99
<a href=\\"/page/slug\\" target=\\"_self\\">page</a><br/>
10-
</p></div>"
10+
</p>"
1111
`;
1212
1313
exports[`check list items 1`] = `
14-
"<div><ul>
14+
"<ul>
1515
<li><input type=\\"checkbox\\" disabled=\\"\\"/> checklistitem1</li>
1616
<li><input type=\\"checkbox\\" checked=\\"\\" disabled=\\"\\"/> checklistitem1</li>
17-
</ul></div>"
17+
</ul>"
1818
`;
1919
2020
exports[`code samples 1`] = `
21-
"<div><pre><code class=\\"lang-javascript\\"><span class=\\"cm-s-neo\\"><span class=\\"cm-keyword\\">var</span> <span class=\\"cm-def\\">a</span> <span class=\\"cm-operator\\">=</span> <span class=\\"cm-number\\">1</span>;
21+
"<pre><code class=\\"lang-javascript\\"><span class=\\"cm-s-neo\\"><span class=\\"cm-keyword\\">var</span> <span class=\\"cm-def\\">a</span> <span class=\\"cm-operator\\">=</span> <span class=\\"cm-number\\">1</span>;
2222
</span></code></pre>
2323
<pre><code><span class=\\"cm-s-neo\\">code-without-language
24-
</span></code></pre></div>"
24+
</span></code></pre>"
2525
`;
2626
2727
exports[`emojis 1`] = `
28-
"<div><p><img src=\\"/img/emojis/joy.png\\" alt=\\":joy:\\" title=\\":joy:\\" class=\\"emoji\\" align=\\"absmiddle\\" height=\\"20\\" width=\\"20\\"/><br/>
28+
"<p><img src=\\"/img/emojis/joy.png\\" alt=\\":joy:\\" title=\\":joy:\\" class=\\"emoji\\" align=\\"absmiddle\\" height=\\"20\\" width=\\"20\\"/><br/>
2929
<i class=\\"fa fa-lock\\"></i><br/>
3030
:unknown-emoji:<br/>
31-
</p></div>"
31+
</p>"
3232
`;
3333
3434
exports[`headings 1`] = `
35-
"<div><h1 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h1\\"></div>h1<a class=\\"fa fa-anchor\\" href=\\"#section-h1\\"></a></h1>
35+
"<h1 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h1\\"></div>h1<a class=\\"fa fa-anchor\\" href=\\"#section-h1\\"></a></h1>
3636
<h2 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h2\\"></div>h2<a class=\\"fa fa-anchor\\" href=\\"#section-h2\\"></a></h2>
3737
<h3 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h3\\"></div>h3<a class=\\"fa fa-anchor\\" href=\\"#section-h3\\"></a></h3>
3838
<h4 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h4\\"></div>h4<a class=\\"fa fa-anchor\\" href=\\"#section-h4\\"></a></h4>
3939
<h5 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h5\\"></div>h5<a class=\\"fa fa-anchor\\" href=\\"#section-h5\\"></a></h5>
4040
<h6 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h6\\"></div>h6<a class=\\"fa fa-anchor\\" href=\\"#section-h6\\"></a></h6>
41-
<h1 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-heading-with-some-more-content\\"></div>heading with some more CONTENT<a class=\\"fa fa-anchor\\" href=\\"#section-heading-with-some-more-content\\"></a></h1></div>"
41+
<h1 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-heading-with-some-more-content\\"></div>heading with some more CONTENT<a class=\\"fa fa-anchor\\" href=\\"#section-heading-with-some-more-content\\"></a></h1>"
4242
`;
4343
44-
exports[`image 1`] = `"<div><p><img src=\\"http://example.com/image.png\\" alt=\\"Image\\"/></p></div>"`;
44+
exports[`image 1`] = `"<p><img src=\\"http://example.com/image.png\\" alt=\\"Image\\"/></p>"`;
4545
4646
exports[`list items 1`] = `
47-
"<div><ul>
47+
"<ul>
4848
<li>listitem1</li>
49-
</ul></div>"
49+
</ul>"
5050
`;
5151
52-
exports[`should strip out inputs 1`] = `"<div></div>"`;
52+
exports[`should strip out inputs 1`] = `""`;
5353
5454
exports[`tables 1`] = `
55-
"<div><div class=\\"marked-table\\"><table>
55+
"<div class=\\"marked-table\\"><table>
5656
<thead><tr><th>Tables</th><th style=\\"text-align:center\\">Are</th><th style=\\"text-align:right\\">Cool</th></tr></thead>
5757
<tbody><tr><td>col 3 is</td><td style=\\"text-align:center\\">right-aligned</td><td style=\\"text-align:right\\">$1600</td></tr><tr><td>col 2 is</td><td style=\\"text-align:center\\">centered</td><td style=\\"text-align:right\\">$12</td></tr><tr><td>zebra stripes</td><td style=\\"text-align:center\\">are neat</td><td style=\\"text-align:right\\">$1</td></tr></tbody>
58-
</table></div></div>"
58+
</table></div>"
5959
`;

packages/api-explorer/__tests__/lib/markdown.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ test('should render nothing if nothing passed in', () => {
7676
});
7777

7878
test('`correctnewlines` option', () => {
79-
expect(shallow(markdown('test\ntest\ntest', { correctnewlines: true })).html()).toBe('<div><p>test\ntest\ntest</p></div>');
79+
expect(shallow(markdown('test\ntest\ntest', { correctnewlines: true })).html()).toBe('<p>test\ntest\ntest</p>');
8080
expect(shallow(markdown('test\ntest\ntest', { correctnewlines: false })).html()).toBe(
81-
'<div><p>test<br/>\ntest<br/>\ntest</p></div>',
81+
'<p>test<br/>\ntest<br/>\ntest</p>',
8282
);
8383
});
8484

packages/api-explorer/src/form-components/DescriptionField.jsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,9 @@ function DescriptionField(props) {
1010
// See #312: Ensure compatibility with old versions of React.
1111
return null;
1212
}
13-
if (typeof description === 'string') {
14-
return (
15-
<p
16-
id={id}
17-
className="field-description"
18-
>{markdown(description)}</p>
19-
);
20-
}
2113
return (
2214
<div id={id} className="field-description">
23-
{description}
15+
{typeof description === 'string'? markdown(description) : description}
2416
</div>
2517
);
2618
}

packages/api-explorer/src/lib/markdown/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ module.exports = function markdown(text, opts = {}) {
124124
className: language ? `lang-${language}` : null,
125125
dangerouslySetInnerHTML: { __html: syntaxHighlighter(props.children[0], language) },
126126
});
127-
}
127+
},
128+
// Remove enclosing <div>
129+
// https://github.com/mapbox/remark-react/issues/54
130+
div: function(props) {
131+
return React.createElement(React.Fragment, props);
132+
},
128133
},
129134
})
130135
.processSync(text).contents;

0 commit comments

Comments
 (0)