File tree Expand file tree Collapse file tree 1 file changed +33
-5
lines changed Expand file tree Collapse file tree 1 file changed +33
-5
lines changed Original file line number Diff line number Diff line change 11
2- import * as monaco from 'monaco-editor'
3-
42/* Add custom blocks parsing (for tech.io):
53// { [autofold]
64// custom block content
75// }
86*/
97const CUSTOM_BLOCK_BEGIN_REGEX = '^\\s*(?:\\/\\/|#).*(?:\\{|#region)'
108const CUSTOM_BLOCK_END_REGEX = '^\\s*(?:\\/\\/|#).*(?:\\}|#endregion)'
11- export function addCustomFoldingMarkers ( configuration : monaco . extra . ILanguageConfiguration ) : monaco . extra . ILanguageConfiguration {
9+
10+ interface IRegExp {
11+ pattern : string
12+ flags ?: string
13+ }
14+ export interface ILanguageConfiguration {
15+ folding ?: {
16+ offSide ?: boolean
17+ markers ?: {
18+ start ?: string | IRegExp
19+ end ?: string | IRegExp
20+ }
21+ }
22+ }
23+
24+ function regexOr ( regex : string , add : string ) : string
25+ function regexOr ( regex : undefined | string | IRegExp , add : string ) : string | IRegExp
26+ function regexOr ( regex : undefined | string | IRegExp , add : string ) : string | IRegExp {
27+ if ( regex == null ) {
28+ return add
29+ } else if ( typeof regex === 'string' ) {
30+ return `(?:${ regex } )|(?:${ add } )`
31+ } else {
32+ return {
33+ flags : regex . flags ,
34+ pattern : regexOr ( regex . pattern , add )
35+ }
36+ }
37+ }
38+
39+ export function addCustomFoldingMarkers < T extends ILanguageConfiguration > ( configuration : T ) : T {
1240 const markers = configuration . folding ?. markers
1341 return {
1442 ...configuration ,
1543 folding : {
1644 ...configuration . folding ?? { } ,
1745 markers : {
18- start : markers != null ? new RegExp ( markers . start . source + '|' + CUSTOM_BLOCK_BEGIN_REGEX ) : new RegExp ( CUSTOM_BLOCK_BEGIN_REGEX ) ,
19- end : markers != null ? new RegExp ( markers . end . source + '|' + CUSTOM_BLOCK_END_REGEX ) : new RegExp ( CUSTOM_BLOCK_END_REGEX )
46+ start : regexOr ( markers ? .start , CUSTOM_BLOCK_BEGIN_REGEX ) ,
47+ end : regexOr ( markers ? .end , CUSTOM_BLOCK_END_REGEX )
2048 }
2149 }
2250 }
You can’t perform that action at this time.
0 commit comments