Skip to content

Commit 6a37b1d

Browse files
ryanoglesby08sapegin
authored andcommitted
Refactor: Replace Markdown links with the Link component instead of the styles (#650)
1 parent e0f576d commit 6a37b1d

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/rsg-components/Link/LinkRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import cx from 'classnames';
44
import Styled from 'rsg-components/Styled';
55

6-
export const styles = ({ color }) => ({
6+
const styles = ({ color }) => ({
77
link: {
88
'&, &:link, &:visited': {
99
fontSize: 'inherit',

src/rsg-components/Markdown/Markdown.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { compiler } from 'markdown-to-jsx';
44
import mapValues from 'lodash/mapValues';
55
// import memoize from 'lodash/memoize';
66
import Styled from 'rsg-components/Styled';
7-
import { styles as linkStyles } from 'rsg-components/Link';
7+
import Link from 'rsg-components/Link';
88
import { styles as paraStyles } from 'rsg-components/Para';
99

1010
// We’re explicitly specifying Webpack loaders here so we could skip specifying them in Webpack configuration.
@@ -39,6 +39,9 @@ const getBaseOverrides = memoize(classes => {
3939

4040
return {
4141
...styleOverrides,
42+
a: {
43+
component: Link,
44+
},
4245
code: {
4346
component: Code,
4447
props: {
@@ -70,7 +73,6 @@ const styles = ({ space, fontFamily, fontSize, color, borderRadius }) => ({
7073
fontSize: 'inherit',
7174
},
7275
para: paraStyles({ space, color, fontFamily }).para,
73-
a: linkStyles({ color }).link,
7476
h1: {
7577
composes: '$para',
7678
fontSize: fontSize.h1,

src/rsg-components/Markdown/Markdown.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { html } from 'cheerio';
33
import Markdown from './Markdown';
44

55
describe('Markdown', () => {
6+
it('should render links', () => {
7+
const markdown = 'a [link](http://test.com)';
8+
9+
const actual = render(<Markdown text={markdown} />);
10+
11+
expect(html(actual)).toMatchSnapshot();
12+
});
13+
614
it('should render Markdown with custom CSS classes', () => {
715
const markdown = `
816
# Header
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Markdown should render Markdown in span in inline mode 1`] = `"<span class=\\"rsg--base-0\\">Hello <em class=\\"rsg--em-16 rsg--base-0\\">world</em>!</span>"`;
3+
exports[`Markdown should render Markdown in span in inline mode 1`] = `"<span class=\\"rsg--base-0\\">Hello <em class=\\"rsg--em-15 rsg--base-0\\">world</em>!</span>"`;
44
5-
exports[`Markdown should render Markdown with custom CSS classes 1`] = `"<div><h1 class=\\"rsg--h1-3 rsg--para-1\\">Header</h1><p class=\\"rsg--p-9 rsg--para-1\\">Text with <em class=\\"rsg--em-16 rsg--base-0\\">some</em> <strong class=\\"rsg--strong-17 rsg--base-0\\">formatting</strong> and a <a class=\\"rsg--a-2\\" href=\\"/foo\\">link</a>.</p><p class=\\"rsg--p-9 rsg--para-1\\"><img alt=\\"Image\\" src=\\"/bar.png\\"></p></div>"`;
5+
exports[`Markdown should render Markdown with custom CSS classes 1`] = `"<div><h1 class=\\"rsg--h1-2 rsg--para-1\\">Header</h1><p class=\\"rsg--p-8 rsg--para-1\\">Text with <em class=\\"rsg--em-15 rsg--base-0\\">some</em> <strong class=\\"rsg--strong-16 rsg--base-0\\">formatting</strong> and a <a href=\\"/foo\\" class=\\"rsg--link-26\\">link</a>.</p><p class=\\"rsg--p-8 rsg--para-1\\"><img alt=\\"Image\\" src=\\"/bar.png\\"></p></div>"`;
66
7-
exports[`Markdown should render check-lists correctly 1`] = `"<ul class=\\"rsg--ul-10 rsg--para-1\\"><li class=\\"rsg--li-12 rsg--base-0\\"><input type=\\"checkbox\\" class=\\"rsg--input-13\\" readonly>list 1</li><li class=\\"rsg--li-12 rsg--base-0\\"><input type=\\"checkbox\\" class=\\"rsg--input-13\\" readonly>list 2</li><li class=\\"rsg--li-12 rsg--base-0\\"><input type=\\"checkbox\\" class=\\"rsg--input-13\\" checked readonly>list 3</li></ul>"`;
7+
exports[`Markdown should render check-lists correctly 1`] = `"<ul class=\\"rsg--ul-9 rsg--para-1\\"><li class=\\"rsg--li-11 rsg--base-0\\"><input type=\\"checkbox\\" class=\\"rsg--input-12\\" readonly>list 1</li><li class=\\"rsg--li-11 rsg--base-0\\"><input type=\\"checkbox\\" class=\\"rsg--input-12\\" readonly>list 2</li><li class=\\"rsg--li-11 rsg--base-0\\"><input type=\\"checkbox\\" class=\\"rsg--input-12\\" checked readonly>list 3</li></ul>"`;
88

9-
exports[`Markdown should render code blocks without escaping 1`] = `"<pre class=\\"rsg--pre-19 rsg--para-1\\"><code class=\\"rsg--code-18 lang-html\\"><foo></foo></code></pre>"`;
9+
exports[`Markdown should render code blocks without escaping 1`] = `"<pre class=\\"rsg--pre-18 rsg--para-1\\"><code class=\\"rsg--code-17 lang-html\\"><foo></foo></code></pre>"`;
1010
11-
exports[`Markdown should render headings correctly 1`] = `"<div><h1 class=\\"rsg--h1-3 rsg--para-1\\">one</h1><h2 class=\\"rsg--h2-4 rsg--para-1\\">two</h2><h3 class=\\"rsg--h3-5 rsg--para-1\\">three</h3><h4 class=\\"rsg--h4-6 rsg--para-1\\">four</h4><h5 class=\\"rsg--h5-7 rsg--para-1\\">five</h5><h6 class=\\"rsg--h6-8 rsg--para-1\\">six</h6></div>"`;
11+
exports[`Markdown should render headings correctly 1`] = `"<div><h1 class=\\"rsg--h1-2 rsg--para-1\\">one</h1><h2 class=\\"rsg--h2-3 rsg--para-1\\">two</h2><h3 class=\\"rsg--h3-4 rsg--para-1\\">three</h3><h4 class=\\"rsg--h4-5 rsg--para-1\\">four</h4><h5 class=\\"rsg--h5-6 rsg--para-1\\">five</h5><h6 class=\\"rsg--h6-7 rsg--para-1\\">six</h6></div>"`;
1212
13-
exports[`Markdown should render inline code with escaping 1`] = `"<p class=\\"rsg--p-9 rsg--para-1\\">Foo <code class=\\"rsg--code-18\\">&lt;bar&gt;</code> baz</p>"`;
13+
exports[`Markdown should render inline code with escaping 1`] = `"<p class=\\"rsg--p-8 rsg--para-1\\">Foo <code class=\\"rsg--code-17\\">&lt;bar&gt;</code> baz</p>"`;
1414
15-
exports[`Markdown should render mixed nested lists correctly 1`] = `"<ul class=\\"rsg--ul-10 rsg--para-1\\"><li class=\\"rsg--li-12 rsg--base-0\\">list 1</li><li class=\\"rsg--li-12 rsg--base-0\\"><p class=\\"rsg--p-9 rsg--para-1\\">list 2</p><ol class=\\"rsg--ol-11 rsg--para-1\\" start=\\"1\\"><li class=\\"rsg--li-12 rsg--base-0\\">Sub-list</li><li class=\\"rsg--li-12 rsg--base-0\\">Sub-list</li><li class=\\"rsg--li-12 rsg--base-0\\">Sub-list</li></ol></li><li class=\\"rsg--li-12 rsg--base-0\\">list 3</li></ul>"`;
15+
exports[`Markdown should render links 1`] = `"<p class=\\"rsg--p-8 rsg--para-1\\">a <a href=\\"http://test.com\\" class=\\"rsg--link-26\\">link</a></p>"`;
1616
17-
exports[`Markdown should render ordered lists correctly 1`] = `"<ol class=\\"rsg--ol-11 rsg--para-1\\" start=\\"1\\"><li class=\\"rsg--li-12 rsg--base-0\\">list</li><li class=\\"rsg--li-12 rsg--base-0\\">item</li><li class=\\"rsg--li-12 rsg--base-0\\">three</li></ol>"`;
17+
exports[`Markdown should render mixed nested lists correctly 1`] = `"<ul class=\\"rsg--ul-9 rsg--para-1\\"><li class=\\"rsg--li-11 rsg--base-0\\">list 1</li><li class=\\"rsg--li-11 rsg--base-0\\"><p class=\\"rsg--p-8 rsg--para-1\\">list 2</p><ol class=\\"rsg--ol-10 rsg--para-1\\" start=\\"1\\"><li class=\\"rsg--li-11 rsg--base-0\\">Sub-list</li><li class=\\"rsg--li-11 rsg--base-0\\">Sub-list</li><li class=\\"rsg--li-11 rsg--base-0\\">Sub-list</li></ol></li><li class=\\"rsg--li-11 rsg--base-0\\">list 3</li></ul>"`;
1818
19-
exports[`Markdown should render unordered lists correctly 1`] = `"<ul class=\\"rsg--ul-10 rsg--para-1\\"><li class=\\"rsg--li-12 rsg--base-0\\">list</li><li class=\\"rsg--li-12 rsg--base-0\\">item</li><li class=\\"rsg--li-12 rsg--base-0\\">three</li></ul>"`;
19+
exports[`Markdown should render ordered lists correctly 1`] = `"<ol class=\\"rsg--ol-10 rsg--para-1\\" start=\\"1\\"><li class=\\"rsg--li-11 rsg--base-0\\">list</li><li class=\\"rsg--li-11 rsg--base-0\\">item</li><li class=\\"rsg--li-11 rsg--base-0\\">three</li></ol>"`;
20+
21+
exports[`Markdown should render unordered lists correctly 1`] = `"<ul class=\\"rsg--ul-9 rsg--para-1\\"><li class=\\"rsg--li-11 rsg--base-0\\">list</li><li class=\\"rsg--li-11 rsg--base-0\\">item</li><li class=\\"rsg--li-11 rsg--base-0\\">three</li></ul>"`;

0 commit comments

Comments
 (0)