Skip to content

Commit c8c6fcb

Browse files
committed
Merge Getting Started Guide content
1 parent 21dbac6 commit c8c6fcb

File tree

26 files changed

+1072
-48
lines changed

26 files changed

+1072
-48
lines changed

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/MarkdownDoc.module.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
color: inherit;
1010

1111
counter-reset: devCenterHeading2;
12+
counter-reset: devCenterHeading3;
1213

1314
*:not(pre) code {
1415
@include font-roboto-mono;
@@ -58,12 +59,30 @@
5859

5960
margin: 80px 0 $space-xxl;
6061
counter-increment: devCenterHeading2;
62+
counter-reset: devCenterHeading3;
6163

6264
&::before {
6365
content: counter(devCenterHeading2) ". ";
6466
font: inherit;
6567
color: inherit;
6668
}
69+
}
70+
71+
.heading3 {
72+
@include font-barlow;
73+
@include font-weight-semibold;
74+
font-size: 22px;
75+
line-height: 26px;
76+
color: inherit;
77+
text-transform: uppercase;
78+
margin: 10px 0 $space-xxl;
79+
counter-increment: devCenterHeading3;
80+
81+
&::before {
82+
content: counter(devCenterHeading2) "." counter(devCenterHeading3) ". ";
83+
font: inherit;
84+
color: inherit;
85+
}
6786

6887
&:first-child {
6988
margin-top: $space-xxl;

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/TableOfContents.module.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
color: inherit;
1919
text-transform: uppercase;
2020

21-
padding: 0 0 0 $space-xxxxl;
21+
padding: 0 0 0 $space-xxxl;
2222
margin: 0 0 $space-xxl;
2323
}
2424

@@ -49,5 +49,12 @@
4949
color: $black-60;
5050

5151
display: block;
52-
padding: $space-sm 0 $space-sm $space-xxxxl;
5352
}
53+
54+
.navListItem-link-padding-level2 {
55+
padding: $space-sm 0 $space-sm $space-xxxl;
56+
}
57+
58+
.navListItem-link-padding-level3 {
59+
padding: $space-sm 0 $space-sm $space-xxxxl;
60+
}

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/TableOfContents.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const TableOfContents: React.FC<TableOfContentsProps> = (props) => {
1414
] = React.useState(-1)
1515
const { toc }: { toc: TOC } = props
1616
const items: TOC = React.useMemo(() => {
17-
return toc.filter((item) => item.level === 2)
17+
return toc.filter((item) => (item.level === 2 || item.level === 3))
1818
}, [toc])
1919

2020
const findActiveIndex: () => void = React.useCallback(() => {
@@ -49,7 +49,7 @@ export const TableOfContents: React.FC<TableOfContentsProps> = (props) => {
4949
>
5050
<a
5151
href={`#${item.headingId}`}
52-
className={`${styles['navListItem-link']}`}
52+
className={`${styles['navListItem-link']} ${styles[`navListItem-link-padding-level${item.level}`]}`}
5353
>
5454
{item.title}
5555
</a>

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/markdownRenderer/renderer.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type MarkdownString = string
1414
export type MarkdownResult = React.ReactNode
1515
export type TOC = Array<{ headingId: string; level: number; title: string }>
1616

17-
enum MarkdownHeaderTag {
17+
export enum MarkdownHeaderTag {
1818
h1 = 'h1',
1919
h2 = 'h2',
2020
h3 = 'h3',
@@ -28,7 +28,7 @@ enum MarkdownParagraphTag {
2828
}
2929
export interface MarkdownRenderOptions {
3030
baseUrl?: string
31-
groupBy?: MarkdownHeaderTag.h2
31+
groupBy?: MarkdownHeaderTag
3232
highlightCode?: (code: string, lang: string) => string
3333
sanitize?: boolean
3434
toc?: TOC
@@ -75,8 +75,8 @@ export class Renderer implements MarkdownRenderer {
7575
}
7676

7777
const tokens: marked.TokensList = marked.lexer(markdown)
78-
const nodes: Array<React.ReactNode> = tokens.map((token) =>
79-
this.parseToken(token, options)
78+
const nodes: Array<React.ReactNode> = tokens.map((token, index) =>
79+
this.parseToken(token, index, options)
8080
)
8181
const children: ReturnType<typeof this.groupBy> = this.groupBy(
8282
nodes,
@@ -173,6 +173,7 @@ export class Renderer implements MarkdownRenderer {
173173
// tslint:disable-next-line: cyclomatic-complexity
174174
private parseToken(
175175
token: marked.Token,
176+
index: number,
176177
options?: MarkdownRenderOptions
177178
): React.ReactNode {
178179
const isLinkBlock: (t: marked.Token) => boolean = (t: marked.Token) => {
@@ -238,17 +239,19 @@ export class Renderer implements MarkdownRenderer {
238239
)
239240
return htmlString.replace(tagRegExp, '$1')
240241
}
241-
const extractId: (htmlString: string, tagname: string) => string = (
242+
const extractId: (htmlString: string, tagname: string, leadingIndex: number) => string = (
242243
htmlString: string,
243-
tagname: string
244+
tagname: string,
245+
leadingIndex: number
244246
) => {
245247
htmlString = htmlString.trim()
246248
const tagRegExp: RegExp = new RegExp(
247249
`<${tagname}\\b[^>]*id="(.*?)"[^>]*>((.|\\n)*?)</${tagname}>$`,
248250
'g'
249251
)
250252
const matches: RegExpExecArray | null = tagRegExp.exec(htmlString)
251-
return matches ? matches[1] : ''
253+
const id: string = matches ? matches[1] : ''
254+
return `${leadingIndex}-${id}`
252255
}
253256
const extractTag: (htmlString: string) => string = (
254257
htmlString: string
@@ -286,7 +289,7 @@ export class Renderer implements MarkdownRenderer {
286289
const h: string = marked.parser([token], parserOptions)
287290
const level: number = token.depth
288291
const title: string = removeLineBreak(stripTag(h, `h${level}`))
289-
const headingId: string = extractId(h, `h${level}`).trim()
292+
const headingId: string = extractId(h, `h${level}`, index).trim()
290293

291294
options.toc.push({
292295
headingId,
@@ -353,7 +356,7 @@ export class Renderer implements MarkdownRenderer {
353356
let id: string | undefined
354357
if (isHeaderTag) {
355358
token = token as marked.Tokens.Heading
356-
id = extractId(html, `h${token.depth}`).trim()
359+
id = extractId(html, `h${token.depth}`, index).trim()
357360
}
358361
return React.createElement(tag, {
359362
className: getClassname(token),

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/markdownRenderer/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import DOMPurify from 'dompurify'
22
import hljs from 'highlight.js'
33

4-
import { MarkdownRenderOptions, MarkdownString, Renderer, TOC } from './renderer'
4+
import { MarkdownHeaderTag, MarkdownRenderOptions, MarkdownString, Renderer, TOC } from './renderer'
55

66
export function renderMarkdown(
77
markdown: MarkdownString,
@@ -10,7 +10,7 @@ export function renderMarkdown(
1010
const renderer: Renderer = Renderer.getInstance()
1111
const defaultOptions: MarkdownRenderOptions = {
1212
baseUrl: '/',
13-
groupBy: 'h2',
13+
groupBy: MarkdownHeaderTag.h3,
1414
highlightCode(code: string, lang: string): string {
1515
const language: string = hljs.getLanguage(lang) ? lang : ''
1616
return language ? hljs.highlight(code, { language }).value : code

0 commit comments

Comments
 (0)