Skip to content

Commit f01b043

Browse files
authored
add C syntax highlighting to code samples in README.md
1 parent e159ecd commit f01b043

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

README.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,42 @@ Usage
77

88
Quick example (docs coming soon):
99

10-
json_value * arr = json_array_new(0);
11-
json_array_push(arr, json_string_new("Hello world!"));
12-
json_array_push(arr, json_integer_new(128));
10+
```c
11+
json_value * arr = json_array_new(0);
12+
json_array_push(arr, json_string_new("Hello world!"));
13+
json_array_push(arr, json_integer_new(128));
1314

14-
char * buf = malloc(json_measure(arr));
15-
json_serialize(buf, arr);
15+
char * buf = malloc(json_measure(arr));
16+
json_serialize(buf, arr);
1617

17-
printf("%s\n", buf);
18+
printf("%s\n", buf);
19+
```
1820
21+
```
1922
> [ "Hello world!", 128 ]
23+
```
2024
2125
json-builder is fully interoperable with json-parser:
2226
23-
char json[] = "[ 1, 2, 3 ]";
27+
```c
28+
char json[] = "[ 1, 2, 3 ]";
2429
25-
json_settings settings = {};
26-
settings.value_extra = json_builder_extra; /* space for json-builder state */
30+
json_settings settings = {};
31+
settings.value_extra = json_builder_extra; /* space for json-builder state */
2732
28-
char error[128];
29-
json_value * arr = json_parse_ex(&settings, json, strlen(json), error);
33+
char error[128];
34+
json_value * arr = json_parse_ex(&settings, json, strlen(json), error);
3035
31-
/* Now serialize it again.
32-
*/
33-
char * buf = malloc(json_measure(arr));
34-
json_serialize(buf, arr);
36+
/* Now serialize it again. */
37+
char * buf = malloc(json_measure(arr));
38+
json_serialize(buf, arr);
3539
36-
printf("%s\n", buf);
40+
printf("%s\n", buf);
41+
```
3742

43+
```
3844
> [ 1, 2, 3 ]
45+
```
3946

4047
Note that values created by or modified by json-builder must be freed with
4148
`json_builder_free` instead of `json_value_free`, otherwise the memory of the

0 commit comments

Comments
 (0)