docs: support custom hrefs for api links (#18514)
This commit is contained in:
parent
1d2fc1e963
commit
8292398692
|
|
@ -10,13 +10,13 @@ a way to find element(s) on the page at any moment.
|
||||||
|
|
||||||
These are the recommended built in locators.
|
These are the recommended built in locators.
|
||||||
|
|
||||||
- [`method: Page.getByRole`] to locate by explicit and implicit accessibility attributes.
|
- [`method: Page.getByRole`](#locate-based-on-accessible-attributes) to locate by explicit and implicit accessibility attributes.
|
||||||
- [`method: Page.getByText`] to locate by text content.
|
- [`method: Page.getByText`](#locate-by-text) to locate by text content.
|
||||||
- [`method: Page.getByLabel`] to locate a form control by associated label's text.
|
- [`method: Page.getByLabel`](#locate-by-label-text) to locate a form control by associated label's text.
|
||||||
- [`method: Page.getByPlaceholder`] to locate an input by placeholder.
|
- [`method: Page.getByPlaceholder`](#locate-by-placeholder-text) to locate an input by placeholder.
|
||||||
- [`method: Page.getByAltText`] to locate an element, usually image, by its text alternative.
|
- [`method: Page.getByAltText`](#locate-by-alt-text) to locate an element, usually image, by its text alternative.
|
||||||
- [`method: Page.getByTitle`] to locate an element by its title.
|
- [`method: Page.getByTitle`](#locate-by-title) to locate an element by its title.
|
||||||
- [`method: Page.getByTestId`] to locate an element based on its `data-testid` attribute (other attribute can be configured).
|
- [`method: Page.getByTestId`](#define-explicit-contract-and-use-a-data-testid-attribute) to locate an element based on its `data-testid` attribute (other attribute can be configured).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
await page.getByLabel('User Name').fill('John');
|
await page.getByLabel('User Name').fill('John');
|
||||||
|
|
|
||||||
2
packages/playwright-core/types/types.d.ts
vendored
2
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -2039,7 +2039,7 @@ export interface Page {
|
||||||
/**
|
/**
|
||||||
* > NOTE: Only available for Chromium atm.
|
* > NOTE: Only available for Chromium atm.
|
||||||
*
|
*
|
||||||
* Browser-specific Coverage implementation. See [Coverage](#class-coverage) for more details.
|
* Browser-specific Coverage implementation. See [Coverage] for more details.
|
||||||
*/
|
*/
|
||||||
coverage: Coverage;
|
coverage: Coverage;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,9 @@ const md = require('../markdown');
|
||||||
* clazz?: Documentation.Class,
|
* clazz?: Documentation.Class,
|
||||||
* member?: Documentation.Member,
|
* member?: Documentation.Member,
|
||||||
* param?: string,
|
* param?: string,
|
||||||
* option?: string
|
* option?: string,
|
||||||
* }): string} Renderer
|
* href?: string,
|
||||||
|
* }): string|undefined} Renderer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -773,13 +774,13 @@ function patchLinks(classOrMember, spec, classesMap, membersMap, linkRenderer) {
|
||||||
md.visitAll(spec, node => {
|
md.visitAll(spec, node => {
|
||||||
if (!node.text)
|
if (!node.text)
|
||||||
return;
|
return;
|
||||||
node.text = node.text.replace(/\[`(\w+): ([^\]]+)`\]/g, (match, p1, p2) => {
|
node.text = node.text.replace(/\[`(\w+): ([^\]]+)`\](?:\(([^)]*?)\))?/g, (match, p1, p2, href) => {
|
||||||
if (['event', 'method', 'property'].includes(p1)) {
|
if (['event', 'method', 'property'].includes(p1)) {
|
||||||
const memberName = p1 + ': ' + p2;
|
const memberName = p1 + ': ' + p2;
|
||||||
const member = membersMap.get(memberName);
|
const member = membersMap.get(memberName);
|
||||||
if (!member)
|
if (!member)
|
||||||
throw new Error('Undefined member references: ' + match);
|
throw new Error('Undefined member references: ' + match);
|
||||||
return linkRenderer({ member }) || match;
|
return linkRenderer({ member, href }) || match;
|
||||||
}
|
}
|
||||||
if (p1 === 'param') {
|
if (p1 === 'param') {
|
||||||
let alias = p2;
|
let alias = p2;
|
||||||
|
|
@ -792,16 +793,16 @@ function patchLinks(classOrMember, spec, classesMap, membersMap, linkRenderer) {
|
||||||
throw new Error(`Referenced parameter ${match} not found in the parent method ${method.name} `);
|
throw new Error(`Referenced parameter ${match} not found in the parent method ${method.name} `);
|
||||||
alias = param.alias;
|
alias = param.alias;
|
||||||
}
|
}
|
||||||
return linkRenderer({ param: alias }) || match;
|
return linkRenderer({ param: alias, href }) || match;
|
||||||
}
|
}
|
||||||
if (p1 === 'option')
|
if (p1 === 'option')
|
||||||
return linkRenderer({ option: p2 }) || match;
|
return linkRenderer({ option: p2, href }) || match;
|
||||||
throw new Error(`Undefined link prefix, expected event|method|property|param|option, got: ` + match);
|
throw new Error(`Undefined link prefix, expected event|method|property|param|option, got: ` + match);
|
||||||
});
|
});
|
||||||
node.text = node.text.replace(/\[([\w]+)\]/g, (match, p1) => {
|
node.text = node.text.replace(/\[([\w]+)\](?:\(([^)]*?)\))?/g, (match, p1, href) => {
|
||||||
const clazz = classesMap.get(p1);
|
const clazz = classesMap.get(p1);
|
||||||
if (clazz)
|
if (clazz)
|
||||||
return linkRenderer({ clazz }) || match;
|
return linkRenderer({ clazz, href }) || match;
|
||||||
return match;
|
return match;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue