Skip to content

Commit ec0d212

Browse files
committed
Implemented prettier check
1 parent 2566406 commit ec0d212

File tree

1 file changed

+73
-67
lines changed

1 file changed

+73
-67
lines changed

sites/cheerpj/src/content/docs/11-guides/library-mode.md

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,33 @@ const points = await new ArrayList();
3232

3333
// Create 4 point objects
3434
for (let i = 0; i < 4; i++) {
35-
// Allocate the point
36-
const p = await new Point(i, 0);
35+
// Allocate the point
36+
const p = await new Point(i, 0);
3737

38-
// Add the point to the list
39-
await points.add(p);
38+
// Add the point to the list
39+
await points.add(p);
4040
}
4141

4242
// Convert to list to an Object[] array
4343
const a = await points.toArray();
4444

4545
// Iterate on the array and set y = x
4646
for (let i = 0; i < a.length; i++) {
47-
// Fields can be read and written directly
48-
a[i].y = a[i].x;
47+
// Fields can be read and written directly
48+
a[i].y = a[i].x;
4949
}
5050

5151
// Convert all the elements to Strings
5252
for (let i = 0; i < a.length; i++) {
53-
// Java arrays can be read and written directly
54-
a[i] = await a[i].toString();
53+
// Java arrays can be read and written directly
54+
a[i] = await a[i].toString();
5555
}
5656

5757
// Print them out
5858
for (let i = 0; i < a.length; i++) {
59-
// Static fields can be accessed too
60-
await System.out.println(a[i]);
59+
// Static fields can be accessed too
60+
await System.out.println(a[i]);
6161
}
62-
6362
```
6463

6564
Then, we’ll include that script from a minimal HTML page and run it in the browser. The output will be printed to the browser console.
@@ -76,7 +75,7 @@ Then, we’ll include that script from a minimal HTML page and run it in the bro
7675
</head>
7776

7877
<body>
79-
<h1>Library mode – Standard library</h1>
78+
<h1>Library mode – Standard library</h1>
8079
<p>Open the browser console to view the output.</p>
8180

8281
<script type="module" src="./script.js"></script>
@@ -101,41 +100,41 @@ const statusEl = document.getElementById("status");
101100
const pdfDisplay = document.getElementById("pdfDisplay");
102101

103102
document.getElementById("makePdf").addEventListener("click", async () => {
104-
statusEl.textContent = "Initializing CheerpJ…";
105-
await cheerpjInit();
106-
107-
statusEl.textContent = "Loading iText library…";
108-
const lib = await cheerpjRunLibrary("/app/itextpdf-5.5.13.jar");
109-
110-
try {
111-
const Document = await lib.com.itextpdf.text.Document;
112-
const Paragraph = await lib.com.itextpdf.text.Paragraph;
113-
const PdfWriter = await lib.com.itextpdf.text.pdf.PdfWriter;
114-
const FileOutputStream = await lib.java.io.FileOutputStream;
115-
116-
const document = await new Document();
117-
const writer = await PdfWriter.getInstance(
118-
document,
119-
await new FileOutputStream("/files/HelloIText.pdf")
120-
);
121-
122-
await document.open();
123-
await document.add(await new Paragraph("Hello World!"));
124-
await document.close();
125-
await writer.close();
126-
127-
const blob = await cjFileBlob("/files/HelloIText.pdf");
128-
const url = URL.createObjectURL(blob);
129-
pdfDisplay.src = url;
130-
statusEl.textContent = "Done";
131-
} catch (e) {
132-
const IOException = await lib.java.io.IOException;
133-
if (e instanceof IOException) {
134-
statusEl.textContent = "I/O error while writing PDF";
135-
} else {
136-
statusEl.textContent = "Error: " + (await e.getMessage?.() ?? e);
137-
}
138-
}
103+
statusEl.textContent = "Initializing CheerpJ…";
104+
await cheerpjInit();
105+
106+
statusEl.textContent = "Loading iText library…";
107+
const lib = await cheerpjRunLibrary("/app/itextpdf-5.5.13.jar");
108+
109+
try {
110+
const Document = await lib.com.itextpdf.text.Document;
111+
const Paragraph = await lib.com.itextpdf.text.Paragraph;
112+
const PdfWriter = await lib.com.itextpdf.text.pdf.PdfWriter;
113+
const FileOutputStream = await lib.java.io.FileOutputStream;
114+
115+
const document = await new Document();
116+
const writer = await PdfWriter.getInstance(
117+
document,
118+
await new FileOutputStream("/files/HelloIText.pdf")
119+
);
120+
121+
await document.open();
122+
await document.add(await new Paragraph("Hello World!"));
123+
await document.close();
124+
await writer.close();
125+
126+
const blob = await cjFileBlob("/files/HelloIText.pdf");
127+
const url = URL.createObjectURL(blob);
128+
pdfDisplay.src = url;
129+
statusEl.textContent = "Done";
130+
} catch (e) {
131+
const IOException = await lib.java.io.IOException;
132+
if (e instanceof IOException) {
133+
statusEl.textContent = "I/O error while writing PDF";
134+
} else {
135+
statusEl.textContent = "Error: " + ((await e.getMessage?.()) ?? e);
136+
}
137+
}
139138
});
140139
```
141140
@@ -144,26 +143,33 @@ Next, in `index.html`, we include CheerpJ and `script.js`, provide a “Generate
144143
```html title="index.html"
145144
<!doctype html>
146145
<html lang="en">
147-
<head>
148-
<meta charset="utf-8" />
149-
<meta name="viewport" content="width=device-width, initial-scale=1" />
150-
<title>CheerpJ Library Mode – PDF demo</title>
151-
152-
<script src="https://cjrtnc.leaningtech.com/4.2/loader.js"></script>
153-
154-
<style>
155-
body { font: 14px, sans-serif; margin: 2rem; }
156-
iframe { width: 100%; height: 70vh; border: 1px solid #ccc; }
157-
</style>
158-
</head>
159-
160-
<body>
161-
<button id="makePdf">Generate PDF</button>
162-
<p id="status"></p>
163-
<iframe id="pdfDisplay"></iframe>
164-
165-
<script type="module" src="./script.js"></script>
166-
</body>
146+
<head>
147+
<meta charset="utf-8" />
148+
<meta name="viewport" content="width=device-width, initial-scale=1" />
149+
<title>CheerpJ Library Mode – PDF demo</title>
150+
151+
<script src="https://cjrtnc.leaningtech.com/4.2/loader.js"></script>
152+
153+
<style>
154+
body {
155+
font: 14px, sans-serif;
156+
margin: 2rem;
157+
}
158+
iframe {
159+
width: 100%;
160+
height: 70vh;
161+
border: 1px solid #ccc;
162+
}
163+
</style>
164+
</head>
165+
166+
<body>
167+
<button id="makePdf">Generate PDF</button>
168+
<p id="status"></p>
169+
<iframe id="pdfDisplay"></iframe>
170+
171+
<script type="module" src="./script.js"></script>
172+
</body>
167173
</html>
168174
```
169175

0 commit comments

Comments
 (0)