Skip to content

Commit b7b0164

Browse files
Merge branch 'main' into fix-scrollbar
2 parents 5809047 + 342d740 commit b7b0164

File tree

5 files changed

+227
-43
lines changed

5 files changed

+227
-43
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
deploy:
2727
needs: build
2828
runs-on: ubuntu-latest
29+
if: github.repository == 'cppdoc-cc/cppdoc'
2930
environment:
3031
name: github-pages
3132
url: ${{ steps.deployment.outputs.page_url }}

migrate/migrate-bot.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ ${html}
221221
console.log(`Normal HTML elements count: ${normalElementsCount}`);
222222

223223
if (normalElementsCount > 4) {
224-
throw new Error("生成的内容中包含过多原生HTML元素,可能转换失败。");
224+
throw new Error(
225+
"The generated content contains too many native HTML elements, conversion may have failed."
226+
);
225227
}
226228

227229
return content;
@@ -231,7 +233,7 @@ ${html}
231233
function getRelativeMDXPath(url: string): string {
232234
const match = url.match(/https?:\/\/.*?cppreference\.com\/w\/(.+)\.html$/);
233235
if (!match) {
234-
throw new Error(`无法从URL解析路径: ${url}`);
236+
throw new Error(`Unable to parse path from URL: ${url}`);
235237
}
236238
const relative = match[1]; // "cpp/comments"
237239
return `src/content/docs/${relative}.mdx`;
@@ -240,7 +242,7 @@ function getRelativeMDXPath(url: string): string {
240242
function getRelativeHTMLPath(url: string): string {
241243
const match = url.match(/https?:\/\/.*?cppreference\.com\/w\/(.+)\.html$/);
242244
if (!match) {
243-
throw new Error(`无法从URL解析路径: ${url}`);
245+
throw new Error(`Unable to parse path from URL: ${url}`);
244246
}
245247
const relative = match[1]; // "cpp/comments"
246248
return `dist/${relative}/index.html`;
@@ -262,7 +264,7 @@ title: ${JSON.stringify(title)}
262264
description: Auto‑generated from cppreference
263265
---\n\n`;
264266
await fs.writeFile(filePath, frontmatter + content, "utf8");
265-
console.log(`写入 ${filePath}`);
267+
console.log(`Written to ${filePath}`);
266268
}
267269

268270
// curl --location --request POST "https://api.imgbb.com/1/upload?expiration=600&key=YOUR_CLIENT_API_KEY" --form "image=R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
@@ -324,18 +326,18 @@ async function createPullRequest(
324326
const webp = visualizeTextDiff(originalInnerText, newInnerText);
325327
if (webp) {
326328
imageUrl = await uploadImageToImgBB(webp);
327-
console.log(`上传文本差异图像到 ImgBB: ${imageUrl}`);
329+
console.log(`Uploaded text diff image to ImgBB: ${imageUrl}`);
328330
}
329331
}
330332

331-
const prBody = `> ${MODEL_NAME} ${url} 自动迁移
333+
const prBody = `> Automatically migrated from ${url} by ${MODEL_NAME}
332334
>
333-
> 📝 [编辑此页面](https://github.com/cppdoc-cc/cppdoc/edit/${branchName}/${getRelativeMDXPath(url)})
335+
> 📝 [Edit this page](https://github.com/cppdoc-cc/cppdoc/edit/${branchName}/${getRelativeMDXPath(url)})
334336
335337
<small>Close #${issue.number}</small>
336338
337-
${imageUrl ? `![Text Diff](${imageUrl})` : "(无文本差异图像)"}
338-
<small>绿色:迁移后词汇出现次数大于迁移前;红色:迁移后词汇出现次数小于迁移前。</small>
339+
${imageUrl ? `![Text Diff](${imageUrl})` : "(No text diff image)"}
340+
<small>Green: word count increased after migration; Red: word count decreased after migration.</small>
339341
`;
340342

341343
const { execSync } = await import("child_process");
@@ -350,7 +352,7 @@ ${imageUrl ? `![Text Diff](${imageUrl})` : "(无文本差异图像)"}
350352
execSync(`git push origin ${branchName}`);
351353
} catch (error) {
352354
console.error(
353-
"Git操作失败:",
355+
"Git operation failed:",
354356
error instanceof Error ? error.message : String(error)
355357
);
356358
throw error;
@@ -365,7 +367,7 @@ ${imageUrl ? `![Text Diff](${imageUrl})` : "(无文本差异图像)"}
365367
base: "main",
366368
});
367369

368-
console.log(`创建PR #${pr.number}`);
370+
console.log(`Created PR #${pr.number}`);
369371
return pr.number;
370372
}
371373

@@ -388,7 +390,7 @@ async function updateIssue(
388390
owner: REPO_OWNER,
389391
repo: REPO_NAME,
390392
issue_number: issue.number,
391-
body: `迁移失败: ${message}\n\n已关闭issue。`,
393+
body: `Migration failed: ${message}\n\nIssue closed.`,
392394
});
393395
await octokit.issues.update({
394396
owner: REPO_OWNER,
@@ -401,13 +403,13 @@ async function updateIssue(
401403
owner: REPO_OWNER,
402404
repo: REPO_NAME,
403405
issue_number: issue.number,
404-
body: `迁移完成!已创建PR [#${prNumber}].`,
406+
body: `Migration completed! Created PR [#${prNumber}].`,
405407
});
406408
}
407409
}
408410

409411
async function main() {
410-
console.log("获取带有标签", LABEL, "的issue...");
412+
console.log("Fetching issues with label", LABEL, "...");
411413
const { data: issues } = await octokit.issues.listForRepo({
412414
owner: REPO_OWNER,
413415
repo: REPO_NAME,
@@ -416,48 +418,48 @@ async function main() {
416418
per_page: 50,
417419
});
418420

419-
console.log(`找到 ${issues.length} 个issue`);
421+
console.log(`Found ${issues.length} issues`);
420422

421423
for (const issue of issues) {
422-
console.log(`处理issue #${issue.number}: ${issue.title}`);
424+
console.log(`Processing issue #${issue.number}: ${issue.title}`);
423425
try {
424426
if (hasPRReference(issue.title)) {
425427
continue;
426428
}
427429

428430
const url = extractLink(issue.title);
429431
if (!url) {
430-
throw new Error("标题中未找到有效的cppreference链接");
432+
throw new Error("No valid cppreference link found in title");
431433
}
432434

433-
console.log(` 获取 ${url}`);
435+
console.log(` Fetching ${url}`);
434436
const { html, title, innerText } = await retry(
435437
() => fetchPageContent(url),
436438
3,
437439
2000
438440
);
439441

440-
console.log(` 转换HTML为MDX...`);
442+
console.log(` Converting HTML to MDX...`);
441443
const mdx = await retry(() => convertToMDX(html, title, url), 3, 2000);
442444

443445
const filePath = getLocalMDXPath(url);
444-
console.log(` 写入 ${filePath}`);
446+
console.log(` Writing to ${filePath}`);
445447
await writeMDXFile(filePath, mdx, title);
446448

447-
console.log(` 重新格式化...`);
449+
console.log(` Re-formatting...`);
448450
spawnSync(`npm`, ["run", "format"], {
449451
stdio: "inherit",
450452
shell: true,
451453
});
452454

453-
console.log(` 构建...`);
455+
console.log(` Building...`);
454456
const res = spawnSync(`npm`, ["run", "build"], {
455457
stdio: "inherit",
456458
shell: true,
457459
});
458460
if (res.status !== 0) {
459461
throw new Error(
460-
"构建失败,可能生成的MDX有问题:" +
462+
"Build failed, possibly due to issues with the generated MDX:" +
461463
res.stderr?.toString() +
462464
res.stdout?.toString() +
463465
res.error?.toString() +
@@ -466,20 +468,20 @@ async function main() {
466468
);
467469
}
468470

469-
console.log(` 创建PR...`);
471+
console.log(` Creating PR...`);
470472
const prNumber = await createPullRequest(issue, filePath, url, innerText);
471473

472-
console.log(` 更新issue...`);
474+
console.log(` Updating issue...`);
473475
await updateIssue(issue, prNumber);
474476

475-
console.log(` issue #${issue.number} 完成`);
477+
console.log(` Issue #${issue.number} completed`);
476478
} catch (error) {
477-
console.error(` issue #${issue.number} 出错:`, error);
479+
console.error(` Issue #${issue.number} error:`, error);
478480
await updateIssue(issue, null, error);
479481
}
480482
}
481483

482-
console.log("全部完成");
484+
console.log("All completed");
483485
}
484486

485487
main().catch((err) => {

src/content/docs/c/comment.mdx

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
title: "Comments"
3+
---
4+
5+
import { Desc, DescList, DocLink, Revision, RevisionBlock } from '@components/index';
6+
7+
Comments serve as a sort of in-code documentation. When inserted into a program, they are effectively ignored by the compiler; they are solely intended to be used as notes by the humans that read source code.
8+
9+
### Syntax
10+
11+
* (1) `/*` _comment_ `*/`
12+
* <Revision since="C99">(2) `//` _comment_ </Revision
13+
14+
1) Often known as "C-style" or "multi-line" comments.
15+
2) Often known as "C++-style" or "single-line" comments.
16+
17+
All comments are removed from the program at <DocLink src="/c/language/translation_phases">translation phase 3</DocLink> by replacing each comment with a single whitespace character.
18+
19+
### C-style
20+
21+
C-style comments are usually used to comment large blocks of text or small fragments of code; however, they can be used to comment single lines. To insert text as a C-style comment, simply surround the text with `/*` and `*/`. C-style comments tell the compiler to ignore all content between `/*` and `*/`. Although it is not part of the C standard, `/**` and `**/` are often used to indicate documentation blocks; this is legal because the second asterisk is simply treated as part of the comment.
22+
23+
Except within a <DocLink src="/c/language/character_constant">character constant</DocLink>, a <DocLink src="/c/language/string_literal">string literal</DocLink>, or a comment, the characters `/*` introduce a comment. The contents of such a comment are examined only to identify multibyte characters and to find the characters `*/` that terminate the comment. C-style comments cannot be nested.
24+
25+
<RevisionBlock since="C99">
26+
27+
### C++-style
28+
29+
C++-style comments are usually used to comment single lines of text or code; however, they can be placed together to form multi-line comments. To insert text as a C++-style comment, simply precede the text with `//` and follow the text with the new line character. C++-style comments tell the compiler to ignore all content between `//` and a new line.
30+
31+
Except within a <DocLink src="/c/language/character_constant">character constant</DocLink>, a <DocLink src="/c/language/string_literal">string literal</DocLink>, or a comment, the characters `//` introduce a comment that includes all multibyte characters up to, but not including, the next new-line character. The contents of such a comment are examined only to identify multibyte characters and to find the new-line character that terminates the comment. C++-style comments can be nested:
32+
33+
```c
34+
// y = f(x); // invoke algorithm
35+
```
36+
37+
A C-style comment may appear within a C++-style comment:
38+
39+
```c
40+
// y = f(x); /* invoke algorithm */
41+
```
42+
43+
A C++-style comment may appear within a C-style comment; this is a mechanism for excluding a small block of source code:
44+
45+
```c
46+
/*
47+
y = f(x); // invoke algorithms
48+
z = g(x);
49+
*/
50+
```
51+
52+
</RevisionBlock>
53+
54+
### Notes
55+
56+
Because comments <DocLink src="/c/language/translation_phases">are removed</DocLink> before the preprocessor stage, a macro cannot be used to form a comment and an unterminated C-style comment doesn't spill over from an #include'd file.
57+
58+
```c
59+
/* An attempt to use a macro to form a comment. */
60+
/* But, a space replaces characters "//". */
61+
#ifndef DEBUG
62+
#define PRINTF //
63+
#else
64+
#define PRINTF printf
65+
#endif
66+
...
67+
PRINTF("Error in file%s at line%i\n", __FILE__, __LINE__);
68+
```
69+
70+
Besides commenting out, other mechanisms used for source code exclusion are:
71+
72+
```c
73+
#if 0
74+
puts("this will not be compiled");
75+
/* no conflict with C-style comments */
76+
// no conflict with C++-style comments
77+
#endif
78+
```
79+
80+
and
81+
82+
```c
83+
if(0) {
84+
puts("this will be compiled but not be executed");
85+
/* no conflict with C-style comments */
86+
// no conflict with C++-style comments
87+
}
88+
```
89+
90+
The introduction of // comments in C99 was a breaking change in some rare circumstances:
91+
92+
```c
93+
a = b //*divisor:*/ c
94+
+ d; /* C89 compiles a = b / c + d;
95+
C99 compiles a = b + d; */
96+
```
97+
98+
### Example
99+
100+
```cpp
101+
#include <stdio.h>
102+
/*
103+
C-style comments can contain
104+
multiple lines.
105+
*/
106+
107+
/* Or, just one line. */
108+
109+
// C++-style comments can comment one line.
110+
111+
// Or, they can
112+
// be strung together.
113+
114+
int main(void)
115+
{
116+
// The below code won't be run
117+
// puts("Hello");
118+
119+
// The below code will be run
120+
puts("World");
121+
122+
// A note regarding backslash + newline.
123+
// Despite belonging to translation phase 2 (vs phase 3 for comments),
124+
// '\' still determines which portion of the source code is considered
125+
// as 'comments':
126+
// This comment will be promoted to the next line \
127+
puts("Won't be run"); // may issue a warning "multi-line comment"
128+
puts("Hello, again");
129+
}
130+
```
131+
132+
Output:
133+
134+
```text
135+
World
136+
Hello, again
137+
```
138+
139+
### References
140+
141+
* C17 standard (ISO/IEC 9899:2018):
142+
* 6.4.9 Comments (p: 54)
143+
* C11 standard (ISO/IEC 9899:2011):
144+
* 6.4.9 Comments (p: 75)
145+
* C99 standard (ISO/IEC 9899:1999):
146+
* 6.4.9 Comments (p: 66)
147+
* C89/C90 standard (ISO/IEC 9899:1990):
148+
* 3.1.9 Comments
149+
150+
### See also
151+
152+
<DescList>
153+
<Desc>
154+
<DocLink slot="item" src="/cpp/comments">C++ documentation</DocLink> for <span>Comments</span>
155+
</Desc>
156+
</DescList>

0 commit comments

Comments
 (0)