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

Commit

Permalink
Linting and updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Jun 29, 2018
1 parent 79337d5 commit 04f1e63
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`anchors 1`] = `
"<p><a href=\\"http://example.com\\" target=\\"_self\\">link</a><br/>
<a target=\\"_self\\" href=\\"\\">xss</a><br/>
<a href=\\"\\" target=\\"_self\\">xss</a><br/>
<a href=\\"/docs/slug\\" target=\\"_self\\" class=\\"doc-link\\" data-sidebar=\\"slug\\">doc</a><br/>
<a href=\\"/reference#slug\\" target=\\"_self\\">ref</a><br/>
<a href=\\"/blog/slug\\" target=\\"_self\\">blog</a><br/>
Expand Down Expand Up @@ -31,6 +31,8 @@ exports[`emojis 1`] = `
</p>"
`;
exports[`glossary 1`] = `"<p></p>"`;
exports[`headings 1`] = `
"<h1 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h1\\"></div>h1<a class=\\"fa fa-anchor\\" href=\\"#section-h1\\"></a></h1>
<h2 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-h2\\"></div>h2<a class=\\"fa fa-anchor\\" href=\\"#section-h2\\"></a></h2>
Expand All @@ -57,3 +59,5 @@ exports[`tables 1`] = `
<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>
</table></div>"
`;
exports[`variables 1`] = `"<p><span>APIKEY</span></p>"`;
8 changes: 8 additions & 0 deletions packages/api-explorer/__tests__/lib/markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ test('`correctnewlines` option', () => {
);
});

test('variables', () => {
expect(shallow(markdown(`<<apiKey>>`)).html()).toMatchSnapshot();
});

test('glossary', () => {
expect(shallow(markdown(`<<glossary:term>>`)).html()).toMatchSnapshot();
});

// TODO not sure if this needs to work or not?
// Isn't it a good thing to always strip HTML?
describe.skip('`stripHtml` option', () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/api-explorer/src/lib/markdown/components/Anchor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const PropTypes = require('prop-types');

// Nabbed from here:
// https://github.com/readmeio/api-explorer/blob/0dedafcf71102feedaa4145040d3f57d79d95752/packages/api-explorer/src/lib/markdown/renderer.js#L52
function getHref(href = '') {
function getHref(href) {
const doc = href.match(/^doc:([-_a-zA-Z0-9#]*)$/);
if (doc) {
return `/docs/${doc[1]}`
Expand Down Expand Up @@ -32,7 +32,7 @@ function getHref(href = '') {
return href;
}

function docLink(href = '') {
function docLink(href) {
const doc = href.match(/^doc:([-_a-zA-Z0-9#]*)$/);
if (!doc) return false;

Expand All @@ -48,7 +48,11 @@ function Anchor(props) {
}

Anchor.propTypes = {
href: PropTypes.string.isRequired,
href: PropTypes.string,
};

Anchor.defaultProps = {
href: '',
};

module.exports = (sanitizeSchema) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const PropTypes = require('prop-types');
function Heading(props) {
const id = `section-${props.children[0].toLowerCase().replace(/[^\w]+/g, '-')}`
return (
React.createElement(props.level, Object.assign({ className: 'header-scroll' }, props), [
React.createElement(props.level, { className: 'header-scroll' }, [
<div className="anchor waypoint" id={id} key={`anchor-${id}`} />,
...props.children,
// eslint-disable-next-line jsx-a11y/anchor-has-content
Expand Down

0 comments on commit 04f1e63

Please sign in to comment.