Skip to content

Commit

Permalink
feat(docs): improve link validation (#5394)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Feb 10, 2021
1 parent 78ab295 commit c12374e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/api/class-page.md
Expand Up @@ -1488,7 +1488,7 @@ User can inspect selectors or perform manual steps while paused. Resume will con
the place it was paused.

:::note
This method requires Playwright to be started in a headed mode, with a falsy [`options: headless`] value in
This method requires Playwright to be started in a headed mode, with a falsy [`option: headless`] value in
the [`method: BrowserType.launch`].
:::

Expand Down
2 changes: 1 addition & 1 deletion types/types.d.ts
Expand Up @@ -2089,7 +2089,7 @@ export interface Page {
* User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
* the place it was paused.
*
* > NOTE: This method requires Playwright to be started in a headed mode, with a falsy [`options: headless`] value in the
* > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the
* [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchoptions).
*/
pause(): Promise<void>;
Expand Down
22 changes: 12 additions & 10 deletions utils/doclint/documentation.js
Expand Up @@ -49,7 +49,7 @@ const md = require('../markdown');
* option?: string
* }): string} Renderer
*/

class Documentation {
/**
* @param {!Array<!Documentation.Class>} classesArray
Expand Down Expand Up @@ -254,7 +254,7 @@ Documentation.Class = class {
}
}

/**
/**
* @param {function(Documentation.Member|Documentation.Class): void} visitor
*/
visit(visitor) {
Expand Down Expand Up @@ -383,7 +383,7 @@ Documentation.Member = class {
return new Documentation.Member('event', langs, name, type, [], spec);
}

/**
/**
* @param {function(Documentation.Member|Documentation.Class): void} visitor
*/
visit(visitor) {
Expand Down Expand Up @@ -637,13 +637,14 @@ function patchLinks(classOrMember, spec, classesMap, membersMap, linkRenderer) {
md.visitAll(spec, node => {
if (!node.text)
return;
node.text = node.text.replace(/\[`((?:event|method|property): [^\]]+)`\]/g, (match, p1) => {
const member = membersMap.get(p1);
if (!member)
throw new Error('Undefined member references: ' + match);
return linkRenderer({ member }) || match;
});
node.text = node.text.replace(/\[`(param|option): ([^\]]+)`\]/g, (match, p1, p2) => {
node.text = node.text.replace(/\[`(\w+): ([^\]]+)`\]/g, (match, p1, p2) => {
if (['event', 'method', 'property'].includes(p1)) {
const memberName = p1 + ': ' + p2;
const member = membersMap.get(memberName);
if (!member)
throw new Error('Undefined member references: ' + match);
return linkRenderer({ member }) || match;
}
if (p1 === 'param') {
let alias = p2;
if (classOrMember) {
Expand All @@ -659,6 +660,7 @@ function patchLinks(classOrMember, spec, classesMap, membersMap, linkRenderer) {
}
if (p1 === 'option')
return linkRenderer({ option: p2 }) || match;
throw new Error(`Undefined link prefix, expected event|method|property|param|option, got: ` + match);
});
node.text = node.text.replace(/\[([\w]+)\]/g, (match, p1) => {
const clazz = classesMap.get(p1);
Expand Down

0 comments on commit c12374e

Please sign in to comment.