();
+ const spec = meta.match(/\{([\d,\s-]+)\}/)?.[1];
+ for (const part of spec?.split(',') ?? []) {
+ const [from, to = from] = part.trim().split('-').map(Number);
+ for (let n = from; n <= to; n++) {
+ lines.add(n);
+ }
+ }
+ return lines;
+}
+
+/**
+ * Splits highlighted HTML into lines. Highlighting can open a span on one
+ * line and close it on a later one, so open spans are closed at each line
+ * end and reopened on the next line.
+ */
+function splitLines(html: string): string[] {
+ const open: string[] = [];
+ return html.split('\n').map((line) => {
+ const prefix = open.join('');
+ for (const tag of line.match(/]*>|<\/span>/g) ?? []) {
+ if (tag === '') {
+ open.pop();
+ } else {
+ open.push(tag);
+ }
+ }
+ return prefix + line + ''.repeat(open.length);
+ });
+}
+
/** Consecutive fenced blocks with a `tab="…"` attribute, shown as one tabbed block. */
interface CodeTabsToken {
type: 'codeTabs';
@@ -213,11 +271,30 @@ function codeBody({ text, lang }: Tokens.Code) {
const title = meta.join(' ').match(/title="?([^"]+)"?/)?.[1];
const shell = SHELL_LANGUAGES.has(language);
const known = language && hljs.getLanguage(language);
- const body = shell
+ const highlighted = lineRanges(meta.join(' '));
+ let body = shell
? renderShell(text)
: known
? hljs.highlight(text, { language }).value
: escapeHtml(text);
+ // Highlighted lines and diffs wrap each line, so it can be marked.
+ if (!shell && (highlighted.size || language === 'diff')) {
+ const raw = text.split('\n');
+ body = splitLines(body)
+ .map((line, i) => {
+ const classes = ['code-line'];
+ if (highlighted.has(i + 1)) {
+ classes.push('is-highlighted');
+ }
+ if (language === 'diff' && (raw[i] ?? '').startsWith('+')) {
+ classes.push('is-added');
+ } else if (language === 'diff' && (raw[i] ?? '').startsWith('-')) {
+ classes.push('is-removed');
+ }
+ return `${line}`;
+ })
+ .join('\n');
+ }
return {
title,
shell,
@@ -375,7 +452,7 @@ export function renderMarkdown(
: inner;
const anchor =
depth > 1
- ? `#`
+ ? `${LINK_ICON}`
: '';
return `${label}${anchor}\n`;
},
@@ -414,7 +491,7 @@ export function renderMarkdown(
const kind = match[1];
const rest = inner.slice(match[0].length);
const body = rest.startsWith('') ? rest.slice(4) : `${rest}`;
- return `\n`;
+ return `\n`;
},
table({ header, rows }: Tokens.Table) {
const labels = header.map((c) =>
diff --git a/packages/docs/src/content/cli/init.md b/packages/docs/src/content/cli/init.md
index c9d602f4..cd0184ee 100644
--- a/packages/docs/src/content/cli/init.md
+++ b/packages/docs/src/content/cli/init.md
@@ -47,6 +47,22 @@ Point `--rcPath` at the file you want to change and pass only the values that sh
npx user-flow init --rcPath .user-flowrc.ci.json --outPath tmp/measures
```
+Only the value you passed changes:
+
+```diff title=".user-flowrc.ci.json"
+ {
+ "collect": {
+ "url": "https://coffee-cart.netlify.app/",
+ "ufPath": "./user-flows"
+ },
+ "persist": {
+- "outPath": "./measures",
++ "outPath": "tmp/measures",
+ "format": ["html"]
+ }
+ }
+```
+
> [!TIP]
> Combine `init` with `--verbose` to print the resolved rc file without changing anything:
> `npx user-flow init --rcPath .user-flowrc.ci.json --verbose`
diff --git a/packages/docs/src/content/user-flows/recorder-exports.md b/packages/docs/src/content/user-flows/recorder-exports.md
index 3ae7c2c7..9ee0bff2 100644
--- a/packages/docs/src/content/user-flows/recorder-exports.md
+++ b/packages/docs/src/content/user-flows/recorder-exports.md
@@ -70,7 +70,7 @@ One timespan over everything is a coarse measurement. To see each interaction on
| `startTimespan` / `endTimespan` | `flow.startTimespan()` / `flow.endTimespan()` |
| `snapshot` | `flow.snapshot()` |
-```json title="recordings/order-coffee.replay.json"
+```json {4,11,12} title="recordings/order-coffee.replay.json"
{
"title": "Order coffee",
"steps": [
@@ -102,7 +102,7 @@ const interactions: UserFlowInteractionsFn = async (ctx: UserFlowContext): Promi
Measurement steps accept the same options as their Lighthouse counterparts through `stepOptions`. A `name` makes the report readable:
-```json title="recordings/order-coffee.replay.json"
+```json {5,16} title="recordings/order-coffee.replay.json"
{
"steps": [
{
diff --git a/packages/docs/src/styles.scss b/packages/docs/src/styles.scss
index e4c7720f..8023a309 100644
--- a/packages/docs/src/styles.scss
+++ b/packages/docs/src/styles.scss
@@ -303,12 +303,26 @@ pre {
}
.heading-anchor {
+ display: inline-flex;
margin-left: var(--space-2);
+ vertical-align: middle;
color: var(--text-subtle);
text-decoration: none;
- font-weight: 400;
opacity: 0;
- transition: opacity 0.15s ease-out;
+ translate: -4px 0;
+ transition:
+ opacity var(--duration-fast) ease-out,
+ translate var(--duration-base) var(--ease-out),
+ color var(--duration-fast) ease-out;
+
+ svg {
+ width: 0.8em;
+ height: 0.8em;
+ }
+
+ &:hover {
+ color: var(--link);
+ }
}
h2:hover .heading-anchor,
@@ -316,6 +330,7 @@ pre {
h4:hover .heading-anchor,
.heading-anchor:focus {
opacity: 1;
+ translate: 0;
}
p,
@@ -552,8 +567,8 @@ pre {
height: 2rem;
border: 1px solid var(--accent-outline);
border-radius: var(--radius-full);
- background: var(--accent-soft);
- color: var(--accent-soft-text);
+ background: var(--surface-raised);
+ color: var(--link);
font-family: var(--font-mono);
font-size: 0.875rem;
font-weight: 600;
@@ -833,6 +848,9 @@ pre {
}
.callout-title {
+ display: flex;
+ align-items: center;
+ gap: var(--space-1-5);
margin: 0 0 var(--space-1) !important;
font-family: var(--font-mono);
font-size: 0.75rem;
@@ -843,6 +861,12 @@ pre {
color: var(--callout-title);
}
+.callout-icon {
+ flex: none;
+ width: 1rem;
+ height: 1rem;
+}
+
.callout-tip {
--callout-border: var(--callout-tip-border);
--callout-bg: var(--callout-tip-bg);
@@ -997,6 +1021,30 @@ pre {
opacity: 1;
}
+/* Highlighted lines (`{1,3-4}`) and diff lines span the full width of the block. */
+.code-line {
+ display: inline-block;
+ min-width: calc(100% + 2 * var(--space-4));
+ margin: 0 calc(-1 * var(--space-4));
+ padding: 0 var(--space-4);
+ border-left: 2px solid transparent;
+}
+
+.code-line.is-highlighted {
+ background: rgb(139 92 246 / 0.16);
+ border-left-color: var(--color-primary-400);
+}
+
+.code-line.is-added {
+ background: rgb(34 197 94 / 0.14);
+ border-left-color: var(--color-success-400);
+}
+
+.code-line.is-removed {
+ background: rgb(239 68 68 / 0.14);
+ border-left-color: var(--color-error-400);
+}
+
/* Terminal blocks: window dots in the title bar, a prompt before each
command (a pseudo-element, so it is never selected or copied), muted
comments and dimmer output. */