@@ -70,75 +70,6 @@ export function quotePrecedesLinkOpen(text: string | undefined): boolean {
7070 return text . endsWith ( '"' ) || text . endsWith ( "'" )
7171}
7272
73- // Filters a list of tokens by token type only when they match
74- // a specific token type order.
75- // For example, if a list of tokens contains:
76- //
77- // [
78- // { type: 'inline'},
79- // { type: 'list_item_close'},
80- // { type: 'list_item_open'},
81- // { type: 'paragraph_open'},
82- // { type: 'inline'},
83- // { type: 'paragraph_close'},
84- // ]
85- //
86- // And if the `tokenOrder` being looked for is:
87- //
88- // [
89- // 'list_item_open',
90- // 'paragraph_open',
91- // 'inline'
92- // ]
93- //
94- // Then the return value would be the items that match that sequence:
95- // Index 2-4:
96- // [
97- // { type: 'inline'}, <-- Index 0 - NOT INCLUDED
98- // { type: 'list_item_close'}, <-- Index 1 - NOT INCLUDED
99- // { type: 'list_item_open'}, <-- Index 2 - INCLUDED
100- // { type: 'paragraph_open'}, <-- Index 3 - INCLUDED
101- // { type: 'inline'}, <-- Index 4 - INCLUDED
102- // { type: 'paragraph_close'}, <-- Index 5 - NOT INCLUDED
103- // ]
104- //
105- export function filterTokensByOrder (
106- tokens : MarkdownToken [ ] ,
107- tokenOrder : string [ ] ,
108- ) : MarkdownToken [ ] {
109- const matches : MarkdownToken [ ] = [ ]
110-
111- // Get a list of token indexes that match the
112- // first token (root) in the tokenOrder array
113- const tokenRootIndexes : number [ ] = [ ]
114- const firstTokenOrderType = tokenOrder [ 0 ]
115- for ( let index = 0 ; index < tokens . length ; index ++ ) {
116- const token = tokens [ index ]
117- if ( token . type === firstTokenOrderType ) {
118- tokenRootIndexes . push ( index )
119- }
120- }
121-
122- // Loop through each root token index and check if
123- // the order matches the tokenOrder array
124- for ( const tokenRootIndex of tokenRootIndexes ) {
125- for ( let i = 1 ; i < tokenOrder . length ; i ++ ) {
126- if ( tokens [ tokenRootIndex + i ] . type !== tokenOrder [ i ] ) {
127- // This tokenRootIndex was a possible start,
128- // but doesn't match the tokenOrder perfectly, so break out
129- // of the inner loop before it reaches the end.
130- break
131- }
132- if ( i === tokenOrder . length - 1 ) {
133- matches . push ( ...tokens . slice ( tokenRootIndex , tokenRootIndex + i + 1 ) )
134- }
135- }
136- }
137- return matches
138- }
139-
140- export const docsDomains = [ 'docs.github.com' , 'help.github.com' , 'developer.github.com' ]
141-
14273// Lines is an array of strings read from a
14374// Markdown file a split around new lines.
14475// This is the format we get from Markdownlint.
0 commit comments