Skip to content

Commit 2cd9e56

Browse files
committed
fix fonts, signatures
1 parent e035823 commit 2cd9e56

File tree

3 files changed

+31
-57
lines changed

3 files changed

+31
-57
lines changed

src/generators/jsx-ast/utils/createSignatureElements.mjs

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ export const parseListIntoProperties = node => {
3535
if (children[0].type === 'inlineCode') {
3636
name = children.shift().value.trimEnd();
3737
} else if (children[0].value && children[0].value.startsWith('Returns')) {
38-
children.shift();
3938
name = 'Returns';
39+
children[0].value = children[0].value.replace(/^Returns:?\s*/i, '');
40+
if (!children[0].value.trim()) {
41+
children.shift();
42+
}
4043
}
4144

4245
if (children[0]?.value?.trim() === '') {
@@ -129,57 +132,28 @@ export const createPropertyTable = (node, withHeading = true) => {
129132
};
130133

131134
/**
132-
* Generates all valid function signatures based on optional parameters
135+
* Generates the function signature based on optional parameters
133136
* @param {string} functionName - Name of the function
134137
* @param {import('../../legacy-json/types.d.ts').MethodSignature} signature - Signature object
135138
* @param {string} prefix - `'new '` or `''`
136139
*/
137-
export const generateSignatures = (functionName, signature, prefix = '') => {
138-
const { params, return: returnType } = signature;
140+
export const generateSignature = (
141+
functionName,
142+
{ params, return: returnType },
143+
prefix = ''
144+
) => {
139145
const returnStr = returnType ? `: ${returnType.type}` : '';
140-
141-
// Handle case with no optional parameters
142-
const optionalParams = params.filter(param => param.optional);
143-
if (!optionalParams.length) {
144-
const paramsStr = params.map(param => param.name).join(', ');
145-
return [`${prefix}${functionName}(${paramsStr})${returnStr}`];
146-
}
147-
148-
// Find indexes of optional parameters
149-
const optionalIndexes = params
150-
.map((param, index) => (param.optional ? index : -1))
151-
.filter(index => index !== -1);
152-
153-
// Generate all possible combinations of optional parameters
154-
const signatures = [];
155-
const totalCombinations = 1 << optionalIndexes.length; // 2^n using bitshift
156-
157-
for (let i = 0; i < totalCombinations; i++) {
158-
const includedParams = params.filter((param, index) => {
159-
// Always include required parameters
160-
if (!param.optional) {
161-
return true;
146+
const paramsStr = params
147+
.map(param => {
148+
let paramStr = param.name;
149+
if (param.optional || param.default) {
150+
paramStr += '?';
162151
}
152+
return paramStr;
153+
})
154+
.join(', ');
163155

164-
// For optional parameters, check if this combination includes it
165-
const optionalIndex = optionalIndexes.indexOf(index);
166-
return ((i >> optionalIndex) & 1) === 1;
167-
});
168-
169-
const paramsStr = includedParams
170-
.map(param => {
171-
let paramStr = param.name;
172-
if (param.optional || param.default) {
173-
paramStr += '?';
174-
}
175-
return paramStr;
176-
})
177-
.join(', ');
178-
179-
signatures.push(`${prefix}${functionName}(${paramsStr})${returnStr}`);
180-
}
181-
182-
return signatures;
156+
return `${prefix}${functionName}(${paramsStr})${returnStr}`;
183157
};
184158

185159
/**
@@ -189,9 +163,8 @@ export const generateSignatures = (functionName, signature, prefix = '') => {
189163
* @param {string} prefix - `'new '` or `''`
190164
*/
191165
export const createSignatureCodeBlock = (functionName, signature, prefix) => {
192-
const signatures = generateSignatures(functionName, signature, prefix);
193-
const codeContent = signatures.join('\n');
194-
const highlighted = highlightToHast(codeContent, 'typescript');
166+
const sig = generateSignature(functionName, signature, prefix);
167+
const highlighted = highlightToHast(sig, 'typescript');
195168
return createElement('div', { class: 'signature' }, [highlighted]);
196169
};
197170

src/generators/web/template.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>{{title}}</title>
8-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9-
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Open+Sans&display=swap" rel="stylesheet">
108
<link rel="stylesheet" href="styles.css" />
119

12-
<!-- Apply theme before paint to avoid FOUC (Flash of Unstyled Content) -->
13-
<script>
14-
document.documentElement.setAttribute('data-theme', localStorage.getItem('theme') ||
15-
(matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'));
16-
</script>
10+
<link rel="preconnect" href="https://fonts.googleapis.com" />
11+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
12+
13+
<link rel="stylesheet"
14+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Open+Sans:ital,wght@0,300..800;1,300..800" />
15+
16+
<!-- Apply theme before paint to avoid Flash of Unstyled Content -->
17+
<script>document.documentElement.setAttribute("data-theme",localStorage.getItem("theme")||(matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"));</script>
1718
</head>
1819

1920
<body>

src/utils/queries/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ createQueries.UNIST = {
261261
return false;
262262
}
263263

264-
// Check for "Returns:" or "Returns" pattern
265-
if (node.value?.trim() === 'Returns:' || node.value?.trim() === 'Returns') {
264+
// Check for "Returns"
265+
if (node.value?.trimStart().startsWith('Returns')) {
266266
return true;
267267
}
268268

0 commit comments

Comments
 (0)