* Resolve {{FILE: |...}} tokens: prompt once per identity (full token, * or the shared `|name:` key), cache the chosen file, and render each * occurrence by mode (basename / wikilink / path). Uses the non-mutating * accumulator scan of replaceFieldVarInString — not the in-place splice —
(input: string)
| 1051 | * unresolved/empty token can be emitted literally without re-scan loops. |
| 1052 | */ |
| 1053 | protected async replaceFileInString(input: string): Promise<string> { |
| 1054 | const regex = new RegExp(FILE_REGEX.source, "gi"); |
| 1055 | let output = ""; |
| 1056 | let lastIndex = 0; |
| 1057 | let match: RegExpExecArray | null; |
| 1058 | |
| 1059 | while ((match = regex.exec(input)) !== null) { |
| 1060 | output += input.slice(lastIndex, match.index); |
| 1061 | |
| 1062 | const parsed = parseFileToken(match[1] ?? ""); |
| 1063 | if (!parsed) { |
| 1064 | // Empty folder / malformed: leave the token literal and move on. |
| 1065 | output += match[0]; |
| 1066 | lastIndex = regex.lastIndex; |
| 1067 | continue; |
| 1068 | } |
| 1069 | |
| 1070 | const key = parsed.variableKey; |
| 1071 | if (!this.hasConcreteVariable(key)) { |
| 1072 | this.variables.set(key, await this.suggestForFile(parsed)); |
| 1073 | } |
| 1074 | |
| 1075 | const renderedValue = renderStoredFileValue( |
| 1076 | this.variables.get(key), |
| 1077 | parsed.mode, |
| 1078 | (stored) => this.getFileLinkForStoredValue(stored), |
| 1079 | ); |
| 1080 | if (Array.isArray(renderedValue)) { |
| 1081 | const structuredYamlValue = this.propertyCollector.maybeCollect({ |
| 1082 | input, |
| 1083 | matchStart: match.index, |
| 1084 | matchEnd: match.index + match[0].length, |
| 1085 | rawValue: renderedValue, |
| 1086 | fallbackKey: parsed.aliasName ?? parsed.folderPath, |
| 1087 | collectionActive: this.templatePropertyCollectionDepth > 0, |
| 1088 | heuristicEnabled: false, |
| 1089 | }); |
| 1090 | output += getYamlPlaceholder(structuredYamlValue) ?? renderedValue.join(","); |
| 1091 | } else { |
| 1092 | output += renderedValue; |
| 1093 | } |
| 1094 | lastIndex = regex.lastIndex; |
| 1095 | } |
| 1096 | |
| 1097 | return output + input.slice(lastIndex); |
| 1098 | } |
| 1099 | |
| 1100 | /** |
| 1101 | * Render a stored FILE value as a wikilink. Only a real pick from the filtered |
nothing calls this directly
no test coverage detected