Skip to content

Commit 9380a7a

Browse files
committed
Fix side by side code boxes
1 parent 0caab70 commit 9380a7a

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed

docs/advanced/compiler-annotations.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This decorator removes an enumeration's name after compilation and only leaves i
1717

1818
<SideBySide>
1919

20-
```typescript
20+
```typescript title=input.ts
2121
declare enum MyEnum {
2222
MY_ENUM_MEMBER_A,
2323
MY_ENUM_MEMBER_B,
@@ -26,15 +26,15 @@ declare enum MyEnum {
2626
print(MyEnum.MY_ENUM_MEMBER_A);
2727
```
2828

29-
```lua
29+
```lua title=output.lua
3030
print(MyEnum.MY_ENUM_MEMBER_A)
3131
```
3232

3333
</SideBySide>
3434

3535
<SideBySide>
3636

37-
```typescript
37+
```typescript title=input.ts
3838
/** @compileMembersOnly */
3939
declare enum MyEnum {
4040
MY_ENUM_MEMBER_A,
@@ -44,7 +44,7 @@ declare enum MyEnum {
4444
print(MyEnum.MY_ENUM_MEMBER_A);
4545
```
4646

47-
```lua
47+
```lua title=output.lua
4848
print(MY_ENUM_MEMBER_A)
4949
```
5050

@@ -54,7 +54,7 @@ print(MY_ENUM_MEMBER_A)
5454

5555
<SideBySide>
5656

57-
```typescript
57+
```typescript title=input.ts
5858
enum MyEnum {
5959
MY_ENUM_MEMBER_A,
6060
MY_ENUM_MEMBER_B,
@@ -64,7 +64,7 @@ enum MyEnum {
6464
print(MyEnum.MY_ENUM_MEMBER_A);
6565
```
6666

67-
```lua
67+
```lua title=output.lua
6868
MyEnum = {}
6969
MyEnum.MY_ENUM_MEMBER_A = 0
7070
MyEnum.MY_ENUM_MEMBER_B = 1
@@ -77,7 +77,7 @@ print(MyEnum.MY_ENUM_MEMBER_A)
7777

7878
<SideBySide>
7979

80-
```typescript
80+
```typescript title=input.ts
8181
/** @compileMembersOnly */
8282
enum MyEnum {
8383
MY_ENUM_MEMBER_A,
@@ -88,7 +88,7 @@ enum MyEnum {
8888
print(MyEnum.MY_ENUM_MEMBER_A);
8989
```
9090

91-
```lua
91+
```lua title=output.lua
9292
MY_ENUM_MEMBER_A = 0
9393
MY_ENUM_MEMBER_B = 1
9494
MY_ENUM_MEMBER_C = "c"
@@ -108,30 +108,30 @@ Changes the way new instances of this class are made. Takes exactly one argument
108108

109109
<SideBySide>
110110

111-
```typescript
111+
```typescript title=input.ts
112112
declare class MyClass {
113113
constructor(x: number);
114114
}
115115
const inst = new MyClass(3);
116116
```
117117

118-
```lua
118+
```lua title=output.lua
119119
local inst = __TS__New(MyClass, 3)
120120
```
121121

122122
</SideBySide>
123123

124124
<SideBySide>
125125

126-
```typescript
126+
```typescript title=input.ts
127127
/** @customConstructor MyConstructor */
128128
declare class MyClass {
129129
constructor(x: number);
130130
}
131131
const inst = new MyClass(3);
132132
```
133133

134-
```lua
134+
```lua title=output.lua
135135
local inst = MyConstructor(3)
136136
```
137137

@@ -147,12 +147,12 @@ Prevents tstl from trying to resolve the module path. When importing this module
147147

148148
<SideBySide>
149149

150-
```typescript
150+
```typescript title=input.ts
151151
declare module "mymodule" {}
152152
import module from "mymodule";
153153
```
154154

155-
```lua
155+
```lua title=output.lua
156156
...
157157
local module = require("src.mymodule");
158158
```
@@ -161,13 +161,13 @@ local module = require("src.mymodule");
161161

162162
<SideBySide>
163163

164-
```typescript
164+
```typescript title=input.ts
165165
/** @noResolution */
166166
declare module "mymodule" {}
167167
import module from "mymodule";
168168
```
169169

170-
```lua
170+
```lua title=output.lua
171171
...
172172
local module = require("mymodule");
173173
```
@@ -186,7 +186,7 @@ When applied to a class or interface, this only affects the type's declared meth
186186

187187
<SideBySide>
188188

189-
```typescript
189+
```typescript title=input.ts
190190
declare interface NormalInterface {
191191
normalMethod(s: string): void;
192192
}
@@ -202,7 +202,7 @@ x.normalMethod("foo");
202202
y.noSelfMethod("bar");
203203
```
204204

205-
```lua
205+
```lua title=output.lua
206206
x:normalMethod("foo")
207207
y.noSelfMethod("bar")
208208
```
@@ -215,7 +215,7 @@ When applied to a namespace, all functions declared within the namespace will tr
215215

216216
<SideBySide>
217217

218-
```typescript
218+
```typescript title=input.ts
219219
declare namespace NormalNS {
220220
function normalFunc(s: string): string;
221221
}
@@ -229,7 +229,7 @@ NormalNS.normalFunc("foo");
229229
NoSelfNS.noSelfFunc("bar");
230230
```
231231

232-
```lua
232+
```lua title=output.lua
233233
NormalNS:normalFunc("foo")
234234
NoSelfNS.noSelfFunc("bar")
235235
```

docs/advanced/language-extensions.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ Example:
7070
<SideBySide>
7171

7272
<!-- prettier-ignore -->
73-
```ts
73+
```ts title=input.ts
7474
for (const i of $range(1, 5)) {}
7575
for (const i of $range(1, 10, 2)) {}
7676
for (const i of $range(5, 1, -1)) {}
7777
```
7878

79-
```lua
79+
```lua title=output.lua
8080
for i = 1, 5 do end
8181
for i = 1, 10, 2 do end
8282
for i = 5, 1, -1 do end
@@ -92,15 +92,15 @@ For example, to declare and use a Lua function that returns an iterator for a se
9292

9393
<SideBySide>
9494

95-
```ts
95+
```ts title=input.ts
9696
declare function myIterator(): LuaIterable<string>;
9797

9898
for (const s of myIterator()) {
9999
console.log(s);
100100
}
101101
```
102102

103-
```lua
103+
```lua title=output.lua
104104
for s in myIterator() do
105105
print(s)
106106
end
@@ -112,15 +112,15 @@ Some iterators return multiple values each iteration. To declare these, combine
112112

113113
<SideBySide>
114114

115-
```ts
115+
```ts title=input.ts
116116
declare function myIterator(): LuaIterable<LuaMultiReturn<[string, string]>>;
117117

118118
for (const [a, b] of myIterator()) {
119119
console.log(a, b);
120120
}
121121
```
122122

123-
```lua
123+
```lua title=output.lua
124124
for a, b in myIterator() do
125125
print(a, b)
126126
end
@@ -154,7 +154,7 @@ Some types can be iterated with `pairs()` (for example, if the `__pairs` method
154154

155155
<SideBySide>
156156

157-
```ts
157+
```ts title=input.ts
158158
interface MyType extends LuaPairsIterable<number, string> {}
159159
declare const obj: MyType;
160160

@@ -163,7 +163,7 @@ for (const [key, value] of obj) {
163163
}
164164
```
165165

166-
```lua
166+
```lua title=output.lua
167167
for key, value in pairs(obj) do
168168
print(key, value)
169169
end
@@ -175,7 +175,7 @@ Or, if you only care about the key values, you can use `LuaPairsKeyIterable`:
175175

176176
<SideBySide>
177177

178-
```ts
178+
```ts title=input.ts
179179
interface MyType extends LuaPairsKeyIterable<number> {}
180180
declare const obj: MyType;
181181

@@ -184,7 +184,7 @@ for (const key of obj) {
184184
}
185185
```
186186

187-
```lua
187+
```lua title=output.lua
188188
for key in pairs(obj) do
189189
print(key)
190190
end
@@ -298,7 +298,7 @@ Example:
298298

299299
<SideBySide>
300300

301-
```ts
301+
```ts title=input.ts
302302
const tbl = new LuaTable();
303303

304304
tbl.set("foo", "bar");
@@ -312,7 +312,7 @@ tbl.set(1, "bah");
312312
console.log(tbl.length());
313313
```
314314

315-
```lua
315+
```lua title=output.lua
316316
tbl = {}
317317

318318
tbl.foo = "bar"
@@ -334,7 +334,7 @@ To iterate over a `LuaTable`, use `for...of`. This will generate a `for...in` st
334334

335335
<SideBySide>
336336

337-
```ts
337+
```ts title=input.ts
338338
const tbl = new LuaTable<number, string>();
339339

340340
tbl.set(3, "bar");
@@ -347,7 +347,7 @@ for (const [key, value] of tbl) {
347347
}
348348
```
349349

350-
```lua
350+
```lua title=output.lua
351351
tbl = {}
352352

353353
tbl[3] = "bar"
@@ -406,7 +406,7 @@ Example:
406406

407407
<SideBySide>
408408

409-
```ts
409+
```ts title=input.ts
410410
interface Id {
411411
idStr: string;
412412
}
@@ -422,7 +422,7 @@ dict.set(id, "bar");
422422
console.log(dict.get(id));
423423
```
424424

425-
```lua
425+
```lua title=output.lua
426426
id = {idStr = "foo"}
427427
dict[id] = "bar"
428428
print(dict[id])
@@ -473,25 +473,25 @@ Example:
473473

474474
<SideBySide>
475475

476-
```ts
476+
```typescript title=input.ts
477477
console.log(...$vararg);
478478
```
479479

480-
```lua
480+
```lua title=output.lua
481481
print(...)
482482
```
483483

484484
</SideBySide>
485485

486-
When run:
486+
When executing the above output lua with CLI arguments:
487487

488488
<SideBySide>
489489

490-
```
490+
```plaintext title=cli
491491
> lua myscript.lua foo bar
492492
```
493493

494-
```
494+
```plaintext title=stdout
495495
foo bar
496496
```
497497

0 commit comments

Comments
 (0)