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} />;

0 commit comments

Comments
 (0)