(languageId?: string)
| 24 | export const filepathCodeBlockMarker = 'filepath:'; |
| 25 | |
| 26 | export function createFilepathRegexp(languageId?: string): RegExp { |
| 27 | const language = getLanguage(languageId); |
| 28 | const prefixes: string[] = ['#', '\\/\\/']; // always allow # and // as comment start |
| 29 | const suffixes: string[] = []; |
| 30 | function add(lineComment: { start: string; end?: string }) { |
| 31 | prefixes.push(escapeRegExpCharacters(lineComment.start)); |
| 32 | if (lineComment.end) { |
| 33 | suffixes.push(escapeRegExpCharacters(lineComment.end)); |
| 34 | } |
| 35 | } |
| 36 | add(language.lineComment); |
| 37 | language.alternativeLineComments?.forEach(add); |
| 38 | const startMatch = `(?:${prefixes.join('|')})`; |
| 39 | const optionalEndMatch = suffixes.length ? `(?:\\s*${suffixes.join('|')})?` : ''; |
| 40 | return new RegExp(`^\\s*${startMatch}\\s*${filepathCodeBlockMarker}\\s*(.*?)${optionalEndMatch}\\s*$`); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Create a markdown code block with an optional language id and an optional file path. |
no test coverage detected
searching dependent graphs…