Skip to content

Commit ea61c4b

Browse files
authored
AFP-229 Render code in markdown docs using the atlaskit code component
* Render code in markdown docs using the atlaskit code component * Disable line numbers in code blocks * Add changeset
1 parent 808443e commit ea61c4b

File tree

18 files changed

+198
-30
lines changed

18 files changed

+198
-30
lines changed

.changeset/38881e12/changes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"releases": [{ "name": "@brisk-docs/website", "type": "patch" }],
3+
"dependents": []
4+
}

.changeset/38881e12/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Display code blocks in markdown as syntax highlighted

.eslintrc

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,37 @@
2525
"never",
2626
{ "css": "ignorePackages", "json": "always" }
2727
],
28-
"react/sort-comp": "off"
28+
"react/sort-comp": "off",
29+
"import/no-extraneous-dependencies": [
30+
"error",
31+
{
32+
"devDependencies": [
33+
"**/*.test.js",
34+
"**/*.spec.js",
35+
"**/*.test.ts",
36+
"**/*.spec.ts",
37+
"**/*.test.tsx",
38+
"**/*.spec.tsx"
39+
]
40+
}
41+
]
2942
},
3043
"settings": {
3144
"import/resolver": {
32-
"node": {
33-
"extensions": [
34-
".js",
35-
".jsx",
36-
".ts",
37-
".tsx"
38-
]
39-
}
45+
"node": {
46+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
4047
}
41-
48+
}
4249
},
4350
"overrides": [
44-
{
45-
"files": ["**/**/*.ts", "**/**/*.tsx"],
46-
"parser": "@typescript-eslint/parser",
47-
"plugins": ["emotion", "@typescript-eslint"],
48-
"rules": {
49-
"no-unused-vars": "off",
50-
"@typescript-eslint/no-unused-vars": "error"
51-
}
52-
}
53-
]
51+
{
52+
"files": ["**/**/*.ts", "**/**/*.tsx"],
53+
"parser": "@typescript-eslint/parser",
54+
"plugins": ["emotion", "@typescript-eslint"],
55+
"rules": {
56+
"no-unused-vars": "off",
57+
"@typescript-eslint/no-unused-vars": "error"
58+
}
59+
}
60+
]
5461
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@atlaskit/avatar": "^14.1.8",
4141
"@atlaskit/banner": "^8.0.1",
4242
"@atlaskit/button": "^8.2.4",
43+
"@atlaskit/code": "^9.0.0",
4344
"@atlaskit/css-reset": "^3.0.5",
4445
"@atlaskit/docs": "^6.0.2",
4546
"@atlaskit/drawer": "^2.7.1",

packages/website/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ docs alongside your code.
77

88
Start by installing Brisk Docs in your project
99

10-
```sh
10+
```shell
1111
npm install @brisk-docs/website
1212
```
1313

1414
To start your docs website locally, simply run:
1515

16-
```sh
16+
```shell
1717
npm run brisk
1818
```
1919

packages/website/bin/page-generator/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ function generatePackagePages(packageInfo, generatorConfig) {
8484

8585
const rawPagesPath = path.join(homePath, 'examples/isolated', example.id);
8686
const isolatedPath = path.join('/', `${rawPagesPath}`);
87+
const pageTitle = titleCase(example.id);
8788

8889
generateExamplePage(
8990
`${pagePath}.js`,
9091
`${rawPagesPath}.js`,
9192
example.path,
92-
{ ...pageData, isolatedPath },
93+
{ ...pageData, isolatedPath, pageTitle },
9394
generatorConfig,
94-
titleCase(example.id),
95+
pageTitle,
9596
);
9697

9798
return {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react';
2+
import { shallow } from 'enzyme';
3+
import { AkCodeBlock } from '@atlaskit/code';
4+
5+
import CodeBlock from './block';
6+
7+
const sampleCode = 'const x = 1;';
8+
9+
describe('Code block markdown component', () => {
10+
it('renders a AkCodeBlock component', () => {
11+
const wrapper = shallow(<CodeBlock>{sampleCode}</CodeBlock>);
12+
const codeBlocks = wrapper.find(AkCodeBlock);
13+
expect(codeBlocks).toHaveLength(1);
14+
expect(codeBlocks.first().props()).toHaveProperty('text', sampleCode);
15+
});
16+
17+
it('transforms the language classname to select the rendered language', () => {
18+
const wrapper = shallow(
19+
<CodeBlock className="language-js">{sampleCode}</CodeBlock>,
20+
);
21+
22+
expect(
23+
wrapper
24+
.find(AkCodeBlock)
25+
.first()
26+
.props(),
27+
).toHaveProperty('language', 'js');
28+
});
29+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import { AkCodeBlock } from '@atlaskit/code';
3+
4+
interface Props {
5+
children: string;
6+
className?: string;
7+
}
8+
9+
const getLanguageName = (className: string) => {
10+
return className.replace(/language-/, '');
11+
};
12+
13+
export default ({ children, className }: Props) => (
14+
<AkCodeBlock
15+
text={children}
16+
language={className && getLanguageName(className)}
17+
showLineNumbers={false}
18+
/>
19+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as CodeBlock } from './block';
2+
export { default as InlineCode } from './inline';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as React from 'react';
2+
import { AkCode } from '@atlaskit/code';
3+
4+
interface Props {
5+
children: string;
6+
}
7+
8+
export default ({ children }: Props) => <AkCode text={children} />;

packages/website/components/mdx/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Heading from './Heading';
33
import Link from '../switch-link';
4+
import { CodeBlock, InlineCode } from './code';
45

56
const components = {
67
h1: props => <Heading {...props} tag="h1" />,
@@ -10,6 +11,8 @@ const components = {
1011
h5: props => <Heading {...props} tag="h5" />,
1112
h6: props => <Heading {...props} tag="h6" />,
1213
a: Link,
14+
code: CodeBlock,
15+
inlineCode: InlineCode,
1316
};
1417

1518
export default components;

packages/website/components/page-templates/package-example.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,9 @@ const PackageExample = ({ data, fileContents, children }) => {
8686
<PageContent>
8787
<ExampleStyle>
8888
<Header>
89-
<h1>Dynamic Table</h1>
89+
<h1>{data.pageTitle}</h1>
9090
<LinkButton href={data.isolatedPath}>Full page view</LinkButton>
9191
</Header>
92-
<div style={{ padding: '24px 0px' }}>
93-
The Dynamic Table component is a table component with pagination and
94-
sorting functionality.
95-
</div>
9692
<ExampleComponentContainer>
9793
<div className="inner-container">{children}</div>
9894
</ExampleComponentContainer>
@@ -109,6 +105,7 @@ PackageExample.propTypes = {
109105
data: PropTypes.shape({
110106
id: PropTypes.string.isRequired,
111107
packageName: PropTypes.string.isRequired,
108+
pageTitle: PropTypes.string.isRequired,
112109
}).isRequired,
113110
fileContents: PropTypes.string.isRequired,
114111
children: PropTypes.node.isRequired,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import Markdown from './sample-markdown/code-blocks.md';
3+
/*
4+
## Inline code examples
5+
6+
Some inline bash code `echo "You are a wonderful person" >> affirmations.txt`
7+
8+
`const myBestFeatures = ['kind', 'generous']`, a javascript snippet
9+
10+
## Code block examples
11+
12+
A js example
13+
14+
```js
15+
// a React component
16+
17+
import generateAffirmation from './generate-affirmation';
18+
19+
const Affirmation = () => <div>{generateAffirmation()}</div>;
20+
```
21+
22+
A C++ example
23+
24+
```c++
25+
// Thanks to WebAssembly this is also valid for the web!
26+
#include <iostream>
27+
using namespace std;
28+
29+
int main()
30+
{
31+
cout << "Today will be a great day!";
32+
return 0;
33+
}
34+
```
35+
*/
36+
37+
export default () => <Markdown />;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Inline code examples
2+
3+
Some inline bash code `echo "You are a wonderful person" >> affirmations.txt`
4+
5+
`const myBestFeatures = ['kind', 'generous']`, a javascript snippet
6+
7+
## Code block examples
8+
9+
A js example
10+
11+
```js
12+
// a React component
13+
14+
import generateAffirmation from './generate-affirmation';
15+
16+
const Affirmation = () => <div>{generateAffirmation()}</div>;
17+
```
18+
19+
A C++ example
20+
21+
```c++
22+
/* Thanks to WebAssembly this is also valid for the web! */
23+
#include <iostream>
24+
using namespace std;
25+
26+
int main()
27+
{
28+
cout << "Today will be a great day!";
29+
return 0;
30+
}
31+
```

packages/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"@atlaskit/avatar": "^14.1.8",
1919
"@atlaskit/button": "^8.2.4",
20+
"@atlaskit/code": "^9.0.0",
2021
"@atlaskit/css-reset": "^3.0.5",
2122
"@atlaskit/docs": "^6.0.2",
2223
"@atlaskit/drawer": "^2.7.1",

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"include": [
2424
"packages/react-changelogs/src/**/*",
25+
"packages/website/**/*",
2526
"typings/**/*"
2627
],
2728
"typeRoots": ["./typings", "./node_modules/@types"],
28-
}
29+
}

typings/atlaskit.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ declare module '@atlaskit/pagination' {
1212
export default adefault;
1313
}
1414

15+
declare module '@atlaskit/code' {
16+
declare const AkCode: React.ComponentClass<any, any>;
17+
declare const AkCodeBlock: React.ComponentClass<any, any>;
18+
19+
export { AkCode, AkCodeBlock };
20+
}
21+
1522
interface ArrayConstructor {
1623
from(arrayLike: any, mapFn?: (item: any, index: number) => any): Array<any>;
1724
}

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@
153153
memoize-one "^3.0.1"
154154
react-syntax-highlighter "^10.0.1"
155155

156+
"@atlaskit/code@^9.0.0":
157+
version "9.0.0"
158+
resolved "https://registry.yarnpkg.com/@atlaskit/code/-/code-9.0.0.tgz#a5c3fcb1d490df43f25b47c928049a175f64fbcf"
159+
integrity sha512-lYLV2S9TQxt4Lr+nA26QP0FNCrspw3GPwVqQx0PX7Coe+3nbXZc2HNQwqN+urs2WAc11B41jSy6NYXQ7+tTDIg==
160+
dependencies:
161+
"@atlaskit/theme" "^8.0.0"
162+
"@babel/runtime" "^7.0.0"
163+
memoize-one "^3.0.1"
164+
react-syntax-highlighter "^10.0.1"
165+
156166
"@atlaskit/css-reset@^3.0.5":
157167
version "3.0.5"
158168
resolved "https://packages.atlassian.com/api/npm/npm-remote/@atlaskit/css-reset/-/css-reset-3.0.5.tgz#c942746e2dc0b4b1c9aba58155383cdb92f50329"
@@ -481,6 +491,15 @@
481491
exenv "^1.2.2"
482492
prop-types "^15.5.10"
483493

494+
"@atlaskit/theme@^8.0.0":
495+
version "8.1.1"
496+
resolved "https://registry.yarnpkg.com/@atlaskit/theme/-/theme-8.1.1.tgz#bb546eb80eeb88969cd77454000d634d14b8140a"
497+
integrity sha512-4LRj7ClY6OPoT8f2/s/G9Vt0CxOrL0hNNaPLqOwo8X6cMsIVcy2nfTIOFOurvK3zY9aJvRj5OFnoMim+6tTVMQ==
498+
dependencies:
499+
"@babel/runtime" "^7.0.0"
500+
exenv "^1.2.2"
501+
prop-types "^15.5.10"
502+
484503
"@atlaskit/theme@^8.0.1":
485504
version "8.0.1"
486505
resolved "https://registry.yarnpkg.com/@atlaskit/theme/-/theme-8.0.1.tgz#aa474bed386963203d5e384806fe1a5cf732a533"

0 commit comments

Comments
 (0)