Skip to content

Commit

Permalink
docs(markdown): parse :::note's text as children (#32510)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Sep 26, 2024
1 parent a2bdb2f commit 3b86a9c
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 27 deletions.
6 changes: 2 additions & 4 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -3138,11 +3138,9 @@ Things to keep in mind:
:::warning
Running the handler will alter your page state mid-test. For example it will change the currently focused element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on the focus and mouse state being unchanged.
<br />
<br />
For example, consider a test that calls [`method: Locator.focus`] followed by [`method: Keyboard.press`]. If your handler clicks a button between these two actions, the focused element most likely will be wrong, and key press will happen on the unexpected element. Use [`method: Locator.press`] instead to avoid this problem.
<br />
<br />
Another example is a series of mouse actions, where [`method: Mouse.move`] is followed by [`method: Mouse.down`]. Again, when the handler runs between these two actions, the mouse position will be wrong during the mouse down. Prefer self-contained actions like [`method: Locator.click`] that do not rely on the state being unchanged by a handler.
:::
Expand Down
2 changes: 0 additions & 2 deletions docs/src/selenium-grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Playwright can connect to [Selenium Grid Hub](https://www.selenium.dev/documenta
:::warning
There is a risk of Playwright integration with Selenium Grid Hub breaking in the future. Make sure you weight risks against benefits before using it.

<br />
<br />
<details>
<summary>
<span style={{textTransform:'uppercase',fontSize:'smaller',fontWeight:'bold',opacity:'0.6'}}>More details</span>
Expand Down
2 changes: 0 additions & 2 deletions docs/src/trace-viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ When tracing with the [`option: Tracing.start.snapshots`] option turned on (defa
|Action|A snapshot at the moment of the performed input. This type of snapshot is especially useful when exploring where exactly Playwright clicked.|
|After|A snapshot after the action.|

<br/>

Here is what the typical Action snapshot looks like:

![action tab in trace viewer](https://github.com/microsoft/playwright/assets/13063165/7168d549-eb0a-4964-9c93-483f03711fa9)
Expand Down
104 changes: 98 additions & 6 deletions packages/playwright-core/types/types.d.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,7 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue
*
* **NOTE** Using serial is not recommended. It is usually better to make your tests isolated, so they can be run
* independently.
*
* - `test.describe.serial(title, callback)`
* - `test.describe.serial(title)`
* - `test.describe.serial(title, details, callback)`
Expand Down Expand Up @@ -2565,6 +2566,7 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue
*
* **NOTE** Using serial is not recommended. It is usually better to make your tests isolated, so they can be run
* independently.
*
* - `test.describe.serial.only(title, callback)`
* - `test.describe.serial.only(title)`
* - `test.describe.serial.only(title, details, callback)`
Expand Down Expand Up @@ -7926,6 +7928,7 @@ export interface TestInfo {
* **NOTE** [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach)
* automatically takes care of copying attached files to a location that is accessible to reporters. You can safely
* remove the attachment after awaiting the attach call.
*
* @param name Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk.
* @param options
*/
Expand Down
7 changes: 1 addition & 6 deletions utils/doclint/documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,9 @@ function generateSourceCodeComment(spec) {
node.liType = 'default';
if (node.type === 'code' && node.codeLang)
node.codeLang = parseCodeLang(node.codeLang).highlighter;
if (node.type === 'note') {
// @ts-ignore
node.type = 'text';
node.text = '**NOTE** ' + node.text;
}
});
// 5 is a typical member doc offset.
return md.render(comments, { maxColumns: 120 - 5, omitLastCR: true, flattenText: true });
return md.render(comments, { maxColumns: 120 - 5, omitLastCR: true, flattenText: true, noteMode: 'compact' });
}

/**
Expand Down
26 changes: 19 additions & 7 deletions utils/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@

/** @typedef {MarkdownBaseNode & {
* type: 'note',
* text: string,
* noteType: string,
* }} MarkdownNoteNode */

Expand All @@ -66,8 +65,9 @@
/** @typedef {{
* maxColumns?: number,
* omitLastCR?: boolean,
* flattenText?: boolean
* renderCodeBlockTitlesInHeader?: boolean
* flattenText?: boolean,
* renderCodeBlockTitlesInHeader?: boolean,
* noteMode?: 'docusaurus' | 'compact',
* }} RenderOptions
*/

Expand Down Expand Up @@ -208,7 +208,7 @@ function buildTree(lines) {
tokens.push(line.substring(indent.length));
line = lines[++i];
}
node.text = tokens.join('↵');
node.children = parse(tokens.join('\n'));
appendNode(indent, node);
continue;
}
Expand Down Expand Up @@ -340,9 +340,21 @@ function innerRenderMdNode(indent, node, lastNode, result, options) {

if (node.type === 'note') {
newLine();
result.push(`${indent}:::${node.noteType}`);
result.push(wrapText(node.text, options, indent));
result.push(`${indent}:::`);
if (options?.noteMode !== 'compact')
result.push(`${indent}:::${node.noteType}`);
const children = node.children ?? [];
if (options?.noteMode === 'compact') {
children[0] = {
type: 'text',
text: `**NOTE** ${children[0].text}`,
}
}
for (const child of children) {
innerRenderMdNode(indent, child, lastNode, result, options);
lastNode = child;
}
if (options?.noteMode !== 'compact')
result.push(`${indent}:::`);
newLine();
return;
}
Expand Down

0 comments on commit 3b86a9c

Please sign in to comment.