Skip to content

Commit 39bbed2

Browse files
committed
Completed Utilities section
1 parent 031e00e commit 39bbed2

6 files changed

Lines changed: 714 additions & 52 deletions

File tree

docs/utilities/ace-modes.md

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,88 @@
11
# Ace Modes
22

3-
:::warning
4-
**Note:** Work is in progress 🚧
3+
The Ace Modes is a utility method in Acode allows you to manage the language modes supported by the Ace editor. This includes adding new modes, removing existing ones, and configuring how the editor handles different file types.
4+
5+
## Importing Ace Modes
6+
7+
To use the Ace Modes utilities, you need to import them using the `acode.require` method:
8+
9+
```javascript
10+
const aceModes = acode.require('aceModes');
11+
```
12+
13+
## Methods
14+
15+
### `addMode(name: string, extensions: string | string[], caption: string)`
16+
17+
The `addMode` method adds a new mode to the Ace editor. This is useful when you want to support a custom language or file type.
18+
19+
- **name**: The name of the mode.
20+
- **extensions**: The file extensions associated with this mode. This can be a string or an array of strings.
21+
- **caption**: The display name of the mode.
22+
23+
#### Example
24+
25+
```javascript
26+
const { addMode } = acode.require('aceModes');
27+
28+
addMode('myMode', ['mymode', 'mym'], 'My Custom Mode');
29+
```
30+
31+
:::info
32+
The `extensions` parameter can be a single string or an array of strings, making it flexible to accommodate multiple file types.
533
:::
634

7-
We are currently working on this section to provide you with detailed and comprehensive information about how Acode plugins work. Please check back soon for updates!
35+
### `removeMode(name: string)`
36+
37+
The `removeMode` method removes a mode from the Ace editor. This is useful if you need to clean up or no longer need support for a particular mode.
38+
39+
- **name**: The name of the mode to be removed.
840

9-
## Contribute to the Documentation
41+
#### Example
1042

11-
We welcome contributions from the community! If you would like to help improve this documentation, please visit our [GitHub repository](https://github.com/bajrangCoder/acode-plugin-docs) and follow the contribution guidelines.
43+
```javascript
44+
const { removeMode } = acode.require('aceModes');
1245

46+
removeMode('myMode');
47+
```
1348
:::tip
14-
You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗
49+
Removing a mode that is no longer needed can help keep editor environment clean and efficient.
1550
:::
1651

17-
For more information, see official [Guide](https://acode.app/plugin-docs).
52+
## Example
53+
54+
Here’s a more detailed example that demonstrates how to add and remove a custom mode, and how to utilize these modes within the Ace editor.
55+
56+
### Adding a Custom Mode
57+
58+
Let's say you have a custom language with the extension `.mymode` and you want it to be recognized by the Ace editor.
59+
60+
```javascript:line-numbers
61+
const aceModes = acode.require('aceModes');
62+
63+
const onClick = () => {
64+
// Action to perform when the menu item is clicked
65+
console.log('Custom Mode Menu Item Clicked!');
66+
};
67+
68+
// Adding the custom mode
69+
aceModes.addMode('myMode', ['mymode'], 'My Custom Mode');
70+
71+
// Assuming you have the necessary mode definitions loaded for 'myMode'
72+
// Example of using the custom mode in the editor
73+
const editor = editorManager.editor;
74+
editor.session.setMode('ace/mode/myMode');
75+
```
76+
77+
### Removing a Custom Mode
78+
79+
If you decide to remove the custom mode from the Ace editor:
80+
81+
```javascript:line-numbers
82+
const aceModes = acode.require('aceModes');
83+
84+
// Removing the custom mode
85+
aceModes.removeMode('myMode');
86+
87+
// The mode will no longer be available for use
88+
```

docs/utilities/encoding.md

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,103 @@
11
# Encoding
22

3-
:::warning
4-
**Note:** Work is in progress 🚧
5-
:::
3+
This allow to **encode** and **decode** strings with different character sets. This is especially useful when working with **files** that require specific encodings or when handling international text.
4+
5+
## Importing Encodings
6+
7+
To use the Encoding utilities, you need to import them using the `acode.require` method:
8+
9+
```javascript
10+
const encodings = acode.require('encodings');
11+
```
12+
13+
## Usage
14+
15+
### Encoding a String
16+
17+
The `encode` method converts a string into an ArrayBuffer using the specified character set.
18+
19+
```javascript
20+
const text = 'Hello World!';
21+
const charset = 'utf-8';
22+
23+
const encoded = await encodings.encode(text, charset);
24+
console.log(encoded); // Output: ArrayBuffer
25+
```
26+
27+
### Decoding an ArrayBuffer
28+
29+
The `decode` method converts an ArrayBuffer back into a string using the specified character set.
30+
31+
```javascript
32+
const buffer = await encodings.encode(text, charset);
33+
const decoded = await encodings.decode(buffer, charset);
34+
console.log(decoded); // Output: 'Hello World!'
35+
```
36+
37+
## Methods
38+
39+
### `encode(text: string, charset: string): Promise<ArrayBuffer>`
40+
41+
Encodes a string with the specified character set.
42+
43+
- **text**: The text to encode.
44+
- **charset**: The character set name (e.g., UTF-8, GBK).
645

7-
We are currently working on this section to provide you with detailed and comprehensive information about how Acode plugins work. Please check back soon for updates!
46+
### `decode(buffer: ArrayBuffer, charset: string): Promise<string>`
847

9-
## Contribute to the Documentation
48+
Decodes an ArrayBuffer into a string using the specified character set.
1049

11-
We welcome contributions from the community! If you would like to help improve this documentation, please visit our [GitHub repository](https://github.com/bajrangCoder/acode-plugin-docs) and follow the contribution guidelines.
50+
- **buffer**: The ArrayBuffer to decode.
51+
- **charset**: The character set name (e.g., UTF-8, GBK).
1252

13-
:::tip
14-
You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗
53+
## Properties
54+
55+
### `encodings: Array<Encoding>`
56+
57+
An array of all the supported encodings. Each `Encoding` object contains:
58+
59+
- **name**: The name of the encoding.
60+
- **labels**: The labels of the encoding.
61+
- **aliases**: The aliases of the encoding.
62+
63+
## Example
64+
65+
Here is a comprehensive example demonstrating how to encode and decode text using different character sets.
66+
67+
```javascript
68+
const encodings = acode.require('encodings');
69+
70+
async function example() {
71+
const text = 'Hello World!';
72+
const charset = 'utf-8';
73+
74+
try {
75+
// Encoding text
76+
const encoded = await encodings.encode(text, charset);
77+
console.log('Encoded:', encoded);
78+
79+
// Decoding text
80+
const decoded = await encodings.decode(encoded, charset);
81+
console.log('Decoded:', decoded);
82+
83+
} catch (error) {
84+
console.error('Encoding/Decoding error:', error);
85+
}
86+
}
87+
88+
example();
89+
```
90+
91+
:::info
92+
Always handle encoding and decoding within a try-catch block to manage potential errors, such as unsupported character sets.
1593
:::
1694

17-
For more information, see official [Guide](https://acode.app/plugin-docs).
95+
### Checking Available Encodings
96+
97+
You can check all the available encodings supported by Acode:
98+
99+
```javascript
100+
console.log(encodings.encodings);
101+
```
102+
103+
This will print an array of `Encoding` objects, each containing details about the encoding.

0 commit comments

Comments
 (0)