File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ export declare type DocumentationBlock = {
54
54
name : string ;
55
55
description : string ;
56
56
additionalTags : DocumentationTag [ ] ;
57
+ urlFragment ?: string ;
57
58
} ;
58
59
export declare type MethodDocumentationBlock = DocumentationBlock & {
59
60
signature : string ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
findFirstHeading ,
14
14
consumeTypedKeysList ,
15
15
findProcess ,
16
+ slugifyHeading ,
16
17
} from '../markdown-helpers' ;
17
18
import { DocumentationTag } from '../ParsedDocumentation' ;
18
19
@@ -539,4 +540,13 @@ foo`),
539
540
expect ( proc . renderer ) . toEqual ( true ) ;
540
541
} ) ;
541
542
} ) ;
543
+
544
+ describe ( 'slugifyHeading' , ( ) => {
545
+ it ( 'should correctly slugify a complex heading' , ( ) => {
546
+ const heading =
547
+ '`systemPreferences.isHighContrastColorScheme()` _macOS_ _Windows_ _Deprecated_' ;
548
+ const slugified = 'systempreferencesishighcontrastcolorscheme-macos-windows-deprecated' ;
549
+ expect ( slugifyHeading ( heading ) ) . toBe ( slugified ) ;
550
+ } ) ;
551
+ } ) ;
542
552
} ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
findContentAfterHeadingClose ,
14
14
StripReturnTypeBehavior ,
15
15
consumeTypedKeysList ,
16
+ slugifyHeading ,
16
17
} from './markdown-helpers' ;
17
18
import {
18
19
MethodDocumentationBlock ,
@@ -130,6 +131,7 @@ export const _headingToMethodBlock = (
130
131
parameters,
131
132
returns : parsedReturnType ,
132
133
additionalTags : parseHeadingTags ( headingTags ) ,
134
+ urlFragment : `#${ slugifyHeading ( heading . heading ) } ` ,
133
135
} ;
134
136
} ;
135
137
@@ -159,6 +161,7 @@ export const _headingToPropertyBlock = (heading: HeadingContent): PropertyDocume
159
161
description : parsedDescription ,
160
162
required : ! / \( o p t i o n a l \) / i. test ( parsedDescription ) ,
161
163
additionalTags : parseHeadingTags ( headingTags ) ,
164
+ urlFragment : `#${ slugifyHeading ( heading . heading ) } ` ,
162
165
...parsedReturnType ! ,
163
166
} ;
164
167
} ;
@@ -196,6 +199,7 @@ export const _headingToEventBlock = (heading: HeadingContent): EventDocumentatio
196
199
description,
197
200
parameters,
198
201
additionalTags : parseHeadingTags ( headingTags ) ,
202
+ urlFragment : `#${ slugifyHeading ( heading . heading ) } ` ,
199
203
} ;
200
204
} ;
201
205
Original file line number Diff line number Diff line change @@ -766,3 +766,10 @@ export const findProcess = (tokens: Token[]): ProcessBlock => {
766
766
}
767
767
return { main : true , renderer : true } ;
768
768
} ;
769
+
770
+ export const slugifyHeading = ( heading : string ) : string => {
771
+ return heading
772
+ . replace ( / [ ^ A - Z a - z 0 - 9 \- ] / g, '' )
773
+ . replace ( / / g, '-' )
774
+ . toLowerCase ( ) ;
775
+ } ;
You can’t perform that action at this time.
0 commit comments