Fix tool picker shows all options in Markdown API (#56335)
This commit is contained in:
@@ -48,7 +48,7 @@ export default class extends Tag {
|
||||
}
|
||||
|
||||
// The following is _mostly_ verbatim from https://github.com/harttle/liquidjs/blob/v9.22.1/src/builtin/tags/if.ts
|
||||
// The additions here are the handleNots() and handleOperators() calls.
|
||||
// The additions here are the handleNots(), handleOperators(), and handleVersionNames() calls.
|
||||
*render(ctx, emitter) {
|
||||
const r = this.liquid.renderer
|
||||
|
||||
@@ -64,6 +64,13 @@ export default class extends Tag {
|
||||
// This will replace syntax like `fpt or ghes < 3.0` with `fpt or true` or `fpt or false`.
|
||||
resolvedBranchCond = this.handleOperators(resolvedBranchCond)
|
||||
|
||||
// Resolve version names to boolean values for Markdown API context.
|
||||
// This will replace syntax like `fpt or ghec` with `true or false` based on current version.
|
||||
// Only apply this transformation in Markdown API context to avoid breaking existing functionality.
|
||||
if (ctx.environments.markdownRequested) {
|
||||
resolvedBranchCond = this.handleVersionNames(resolvedBranchCond, ctx)
|
||||
}
|
||||
|
||||
// Use Liquid's native function for the final evaluation.
|
||||
const cond = yield new Value(resolvedBranchCond, this.liquid).value(ctx, ctx.opts.lenientIf)
|
||||
|
||||
@@ -174,4 +181,27 @@ export default class extends Tag {
|
||||
|
||||
return resolvedBranchCond
|
||||
}
|
||||
|
||||
handleVersionNames(resolvedBranchCond, ctx) {
|
||||
if (!this.currentVersionObj) {
|
||||
console.warn('currentVersionObj not found in ifversion context.')
|
||||
return resolvedBranchCond
|
||||
}
|
||||
|
||||
// Split the condition into tokens for processing
|
||||
const tokens = resolvedBranchCond.split(/\s+/)
|
||||
const processedTokens = tokens.map((token) => {
|
||||
// Check if the token is a version short name (fpt, ghec, ghes, ghae)
|
||||
const versionShortNames = ['fpt', 'ghec', 'ghes', 'ghae']
|
||||
if (versionShortNames.includes(token)) {
|
||||
// Transform version names to boolean values for Markdown API
|
||||
// This fixes the original issue where version names were undefined in API context
|
||||
return token === this.currentVersionObj.shortName ? 'true' : 'false'
|
||||
}
|
||||
// Return the token unchanged if it's not a version name
|
||||
return token
|
||||
})
|
||||
|
||||
return processedTokens.join(' ')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user