Skip to content

Commit d5c3fdb

Browse files
chargomea-hariti
andauthored
docs(contributing): Document new syntax for onboarding snippets (#13469)
* document new product options syntax * migrate missed line * remove support for the old options syntax --------- Co-authored-by: Abdellah Hariti <[email protected]>
1 parent 705db9e commit d5c3fdb

File tree

4 files changed

+18
-97
lines changed

4 files changed

+18
-97
lines changed

docs/contributing/pages/components.mdx

+13-8
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,23 @@ Attributes:
378378

379379
## Onboarding Options
380380

381-
If you're writing product feature specific docs, you can specify code block `onboardingOptions` metadata:
381+
If you're writing product feature specific docs, you can specify markers within code blocks that enable or disable certain parts of snippets:
382382

383383
````markdown
384-
```go {"onboardingOptions": {"performance": "13-17"}}
385-
// your code here
384+
```go
385+
// ___PRODUCT_OPTION_START___ performance
386+
// your code here
387+
// ___PRODUCT_OPTION_END___ performance
386388
```
387389
````
388390

389-
the general syntax is `{"onboardingOptions": {"feature": "range"}}` where `feature` is the feature id
390-
and `range` is the corresponding line range (similar to the line highlighting syntax).
391+
the syntax uses the standard comment style of the programming language you're documenting. For example:
391392

392-
You can specify multiple features by separating them with a comma:
393+
- TypeScript/JavaScript: `// ___PRODUCT_OPTION_START___ feature`
394+
- Python: `# ___PRODUCT_OPTION_START___ feature`
395+
396+
where `feature` is the feature id (e.g. `performance`, `profiling` or `session-replay`).
393397

394-
`{"onboardingOptions": {"performance": "13-17", "profiling": "5-6"}}`
395398

396399
The range visibility will be controlled by the `OnboardingOptionButtons` component:
397400

@@ -427,7 +430,7 @@ Example (output of the above):
427430
dontStick
428431
/>
429432

430-
```go {"onboardingOptions": {"performance": "13-17"}}
433+
```go
431434
import (
432435
"fmt"
433436
"net/http"
@@ -440,11 +443,13 @@ import (
440443
// To initialize Sentry's handler, you need to initialize Sentry itself beforehand
441444
if err := sentry.Init(sentry.ClientOptions{
442445
Dsn: "___PUBLIC_DSN___",
446+
// ___PRODUCT_OPTION_START___ performance
443447
EnableTracing: true,
444448
// Set TracesSampleRate to 1.0 to capture 100%
445449
// of transactions for performance monitoring.
446450
// We recommend adjusting this value in production,
447451
TracesSampleRate: 1.0,
452+
// ___PRODUCT_OPTION_END___ performance
448453
// Adds request headers and IP for users,
449454
// visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
450455
SendDefaultPII: true,

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
"next-plausible": "^3.12.4",
7575
"next-themes": "^0.3.0",
7676
"nextjs-toploader": "^1.6.6",
77-
"parse-numeric-range": "^1.3.0",
7877
"platformicons": "^8.0.1",
7978
"prism-sentry": "^1.0.2",
8079
"query-string": "^6.13.1",

platform-includes/debug-symbols-apple/_default.mdx

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ You can also upload your code for source context. This feature allows Sentry to
3131
options={[{ id:"source-context", checked: false }]}
3232
/>
3333

34-
```bash {"onboardingOptions": {"source-context": "2"}}
34+
```bash
3535
sentry-cli debug-files upload --auth-token ___ORG_AUTH_TOKEN___ \
36+
# ___PRODUCT_OPTION_START___ source-context
3637
--include-sources \
38+
# ___PRODUCT_OPTION_END___ source-context
3739
--org ___ORG_SLUG___ \
3840
--project ___PROJECT_SLUG___ \
3941
PATH_TO_DSYMS

src/rehype-onboarding-lines.js

+2-87
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
* @typedef {import('hast').Root} Root
44
*/
55
import {toString} from 'hast-util-to-string';
6-
import rangeParser from 'parse-numeric-range';
76
import {visit} from 'unist-util-visit';
87

98
/**
10-
* Rehype plugin that adds the `data-onboarding-option="some-option-id"` attribute and `hidden` class name
11-
* to each line of code based on the metastring of the code block.
12-
*
13-
* The metastring should be in the format of:
14-
* `{"onboardingOptions": {"performance": "1, 3-4", "profiling": "5-6"}}`
15-
* where the keys are the onboarding options, the line numbers can be individual or ranges separated by a comma.
9+
* a Rehype plugin that adds the `data-onboarding-option="option-id"` attribute and `hidden` class name
10+
* to each line of code enclosed within a `___PRODUCT_OPTION_START___ option-id` and `___PRODUCT_OPTION_END___ option-id` markers.
1611
*
1712
* These lines will be hidden by default and shown based on the user's selection of `<OnboardingOptionsButtons ... />`
1813
*
@@ -34,15 +29,6 @@ function visitor(node) {
3429
if (!node.properties.className?.includes('code-highlight')) {
3530
return;
3631
}
37-
38-
const meta = /** @type {string} */ (
39-
node?.data?.meta || node?.properties?.metastring || ''
40-
);
41-
42-
if (meta.includes('onboardingOptions')) {
43-
handle_metadata_options(node, meta);
44-
return;
45-
}
4632
handle_inline_options(node);
4733
}
4834

@@ -70,74 +56,3 @@ function handle_inline_options(node) {
7056
}
7157
});
7258
}
73-
74-
/**
75-
* Parse the line numbers from the metastring
76-
* @param {string} meta
77-
* @return {number[]}
78-
* @example
79-
* parseLines('1, 3-4') // [1, 3, 4]
80-
* parseLines('') // []
81-
*/
82-
const parseLines = meta => {
83-
const RE = /([\d,-]+)/;
84-
// Remove space between {} e.g. {1, 3}
85-
const parsedMeta = meta
86-
.split(',')
87-
.map(str => str.trim())
88-
.join(',');
89-
if (RE.test(parsedMeta)) {
90-
const strlineNumbers = RE.exec(parsedMeta)?.[1];
91-
if (!strlineNumbers) {
92-
return [];
93-
}
94-
const lineNumbers = rangeParser(strlineNumbers);
95-
return lineNumbers;
96-
}
97-
return [];
98-
};
99-
100-
/**
101-
* Create a closure that returns an onboarding option `id` for a given line if it exists
102-
*
103-
* @param {string} meta
104-
* @return { (index:number) => string | undefined }
105-
*/
106-
const getOptionForLine = meta => {
107-
// match the onboardingOptions object, but avoid `other stuff`
108-
const optionsRE = /{"onboardingOptions":\s*({[^}]*})\s*}/;
109-
let linesForOptions = {};
110-
const options = optionsRE.exec(meta)?.[1];
111-
if (!options) {
112-
return () => undefined;
113-
}
114-
115-
// eval provides the convenience of not having to wrap the object properties in quotes
116-
const parsedOptions = JSON.parse(options);
117-
linesForOptions = Object.keys(parsedOptions).reduce((acc, key) => {
118-
acc[key] = parseLines(parsedOptions[key]);
119-
return acc;
120-
}, {});
121-
return index => {
122-
for (const key in linesForOptions) {
123-
if (linesForOptions[key].includes(index + 1)) {
124-
return key;
125-
}
126-
}
127-
return undefined;
128-
};
129-
};
130-
131-
/**
132-
* @param {Element} node
133-
*/
134-
function handle_metadata_options(node, meta) {
135-
const optionForLine = getOptionForLine(meta);
136-
137-
node.children.forEach((line, index) => {
138-
const option = optionForLine(index);
139-
if (option) {
140-
line.properties['data-onboarding-option'] = option;
141-
}
142-
});
143-
}

0 commit comments

Comments
 (0)