Skip to content

Commit 929a75a

Browse files
authored
apply formatting for code block names, reduce variations (#5097)
* apply formatting for code block names, reduce variations * few more code block language corrections * few more corrections
1 parent c1939e7 commit 929a75a

40 files changed

Lines changed: 136 additions & 110 deletions

docs/debugging-native-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
5050

5151
In your native module, use `NSLog` for custom logs:
5252

53-
```objective-c
53+
```objectivec
5454
NSLog(@"YourModuleName: %@", message);
5555
```
5656

docs/network.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ React Native provides the [Fetch API](https://developer.mozilla.org/en-US/docs/W
1515

1616
In order to fetch content from an arbitrary URL, you can pass the URL to fetch:
1717

18-
```tsx
18+
```ts
1919
fetch('https://mywebsite.com/mydata.json');
2020
```
2121

2222
Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:
2323

24-
```tsx
24+
```ts
2525
fetch('https://mywebsite.com/endpoint/', {
2626
method: 'POST',
2727
headers: {
@@ -43,7 +43,7 @@ The above examples show how you can make a request. In many cases, you will want
4343

4444
Networking is an inherently asynchronous operation. Fetch method will return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that makes it straightforward to write code that works in an asynchronous manner:
4545

46-
```tsx
46+
```ts
4747
const getMoviesFromApi = () => {
4848
return fetch('https://reactnative.dev/movies.json')
4949
.then(response => response.json())
@@ -58,7 +58,7 @@ const getMoviesFromApi = () => {
5858

5959
You can also use the `async` / `await` syntax in a React Native app:
6060

61-
```tsx
61+
```ts
6262
const getMoviesFromApiAsync = async () => {
6363
try {
6464
const response = await fetch(
@@ -199,7 +199,7 @@ On Android, as of API Level 28, clear text traffic is also blocked by default. T
199199

200200
The [XMLHttpRequest API](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) is built into React Native. This means that you can use third party libraries such as [frisbee](https://github.com/niftylettuce/frisbee) or [axios](https://github.com/axios/axios) that depend on it, or you can use the XMLHttpRequest API directly if you prefer.
201201

202-
```tsx
202+
```ts
203203
const request = new XMLHttpRequest();
204204
request.onreadystatechange = e => {
205205
if (request.readyState !== 4) {
@@ -225,7 +225,7 @@ The security model for XMLHttpRequest is different than on web as there is no co
225225

226226
React Native also supports [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket), a protocol which provides full-duplex communication channels over a single TCP connection.
227227

228-
```tsx
228+
```ts
229229
const ws = new WebSocket('ws://host.com/path');
230230

231231
ws.onopen = () => {

docs/timers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ One reason why well-built native apps feel so smooth is by avoiding expensive op
3333

3434
Applications can schedule tasks to run after interactions with the following:
3535

36-
```tsx
36+
```ts
3737
InteractionManager.runAfterInteractions(() => {
3838
// ...long-running synchronous task...
3939
});
@@ -49,7 +49,7 @@ The touch handling system considers one or more active touches to be an 'interac
4949

5050
`InteractionManager` also allows applications to register animations by creating an interaction 'handle' on animation start, and clearing it upon completion:
5151

52-
```tsx
52+
```ts
5353
const handle = InteractionManager.createInteractionHandle();
5454
// run animation... (`runAfterInteractions` tasks are queued)
5555
// later, on animation completion:

plugins/remark-codeblock-language-as-title/src/index.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,44 @@
77

88
import {Root} from 'mdast';
99

10+
const LANGUAGES_MAP: Record<string, string> = {
11+
js: 'JavaScript',
12+
javascript: 'JavaScript',
13+
ts: 'TypeScript',
14+
typescript: 'TypeScript',
15+
jsx: 'React JSX',
16+
tsx: 'React TSX',
17+
json: 'JSON',
18+
objc: 'Objective-C',
19+
objectivec: 'Objective-C',
20+
xml: 'XML',
21+
css: 'CSS',
22+
cpp: 'C++',
23+
};
24+
25+
const HIDDEN_TITLES = ['zsh', 'sh', 'shell', 'bash', 'powershell'];
26+
27+
function capitalizeFirstLetter(str: string | null) {
28+
if (!str) {
29+
return str;
30+
}
31+
return str[0].toUpperCase() + str.slice(1);
32+
}
33+
1034
export default function codeblockLanguageAsTitleRemarkPlugin() {
1135
return async (root: Root) => {
1236
const {visit} = await import('unist-util-visit');
1337
visit(root, 'code', node => {
14-
if (node.lang && !['shell', 'bash'].includes(node.lang)) {
38+
if (node.lang && !HIDDEN_TITLES.includes(node.lang)) {
39+
const formattedTitle =
40+
LANGUAGES_MAP[node.lang] ?? capitalizeFirstLetter(node.lang);
1541
if (node.meta) {
1642
if (node.meta.includes('title=')) {
1743
return;
1844
}
19-
node.meta = `title="${node.lang}" ${node.meta}`;
45+
node.meta = `title="${formattedTitle}" ${node.meta}`;
2046
} else {
21-
node.meta = `title="${node.lang}"`;
47+
node.meta = `title="${formattedTitle}"`;
2248
}
2349
}
2450
});

website/architecture/bundled-hermes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ To implement this on Android, we've added a new build inside the `/ReactAndroid/
119119
You can now trigger a build of Hermes engine by invoking:
120120

121121
```bash
122-
// Build a debug version of Hermes
122+
# Build a debug version of Hermes
123123
./gradlew :ReactAndroid:hermes-engine:assembleDebug
124-
// Build a release version of Hermes
124+
# Build a release version of Hermes
125125
./gradlew :ReactAndroid:hermes-engine:assembleRelease
126126
```
127127

@@ -133,7 +133,7 @@ On the Gradle consumer side, we also shipped a small improvement on the consumer
133133

134134
However, this made this line necessary in the template:
135135

136-
```
136+
```groovy
137137
exclude group:'com.facebook.fbjni'
138138
```
139139

website/versioned_docs/version-0.77/debugging-native-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
5050

5151
In your native module, use `NSLog` for custom logs:
5252

53-
```objective-c
53+
```objectivec
5454
NSLog(@"YourModuleName: %@", message);
5555
```
5656

website/versioned_docs/version-0.77/network.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ React Native provides the [Fetch API](https://developer.mozilla.org/en-US/docs/W
1515

1616
In order to fetch content from an arbitrary URL, you can pass the URL to fetch:
1717

18-
```tsx
18+
```ts
1919
fetch('https://mywebsite.com/mydata.json');
2020
```
2121

2222
Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:
2323

24-
```tsx
24+
```ts
2525
fetch('https://mywebsite.com/endpoint/', {
2626
method: 'POST',
2727
headers: {
@@ -43,7 +43,7 @@ The above examples show how you can make a request. In many cases, you will want
4343

4444
Networking is an inherently asynchronous operation. Fetch method will return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that makes it straightforward to write code that works in an asynchronous manner:
4545

46-
```tsx
46+
```ts
4747
const getMoviesFromApi = () => {
4848
return fetch('https://reactnative.dev/movies.json')
4949
.then(response => response.json())
@@ -58,7 +58,7 @@ const getMoviesFromApi = () => {
5858

5959
You can also use the `async` / `await` syntax in a React Native app:
6060

61-
```tsx
61+
```ts
6262
const getMoviesFromApiAsync = async () => {
6363
try {
6464
const response = await fetch(
@@ -189,7 +189,7 @@ export default App;
189189

190190
The [XMLHttpRequest API](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) is built into React Native. This means that you can use third party libraries such as [frisbee](https://github.com/niftylettuce/frisbee) or [axios](https://github.com/axios/axios) that depend on it, or you can use the XMLHttpRequest API directly if you prefer.
191191

192-
```tsx
192+
```ts
193193
const request = new XMLHttpRequest();
194194
request.onreadystatechange = e => {
195195
if (request.readyState !== 4) {
@@ -213,7 +213,7 @@ request.send();
213213

214214
React Native also supports [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket), a protocol which provides full-duplex communication channels over a single TCP connection.
215215

216-
```tsx
216+
```ts
217217
const ws = new WebSocket('ws://host.com/path');
218218

219219
ws.onopen = () => {

website/versioned_docs/version-0.77/the-new-architecture/custom-cxx-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Now, we need to implement the `validateAddress` function in C++. First, we need
336336
337337
2. Open the `shared/NativeSampleModule.cpp` file and add the function implementation
338338
339-
```c++ title="NativeSampleModule.cpp (validateAddress implementation)"
339+
```cpp title="NativeSampleModule.cpp (validateAddress implementation)"
340340
bool NativeSampleModule::validateAddress(jsi::Runtime &rt, jsi::Object input) {
341341
std::string street = input.getProperty(rt, "street").asString(rt).utf8(rt);
342342
int32_t number = input.getProperty(rt, "num").asNumber();

website/versioned_docs/version-0.77/timers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ One reason why well-built native apps feel so smooth is by avoiding expensive op
2929

3030
Applications can schedule tasks to run after interactions with the following:
3131

32-
```tsx
32+
```ts
3333
InteractionManager.runAfterInteractions(() => {
3434
// ...long-running synchronous task...
3535
});
@@ -45,7 +45,7 @@ The touch handling system considers one or more active touches to be an 'interac
4545

4646
InteractionManager also allows applications to register animations by creating an interaction 'handle' on animation start, and clearing it upon completion:
4747

48-
```tsx
48+
```ts
4949
const handle = InteractionManager.createInteractionHandle();
5050
// run animation... (`runAfterInteractions` tasks are queued)
5151
// later, on animation completion:

website/versioned_docs/version-0.78/debugging-native-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
5050

5151
In your native module, use `NSLog` for custom logs:
5252

53-
```objective-c
53+
```objectivec
5454
NSLog(@"YourModuleName: %@", message);
5555
```
5656

0 commit comments

Comments
 (0)