Skip to content

Commit 832b43d

Browse files
committed
docs: add info about unicode
1 parent 7e589b6 commit 832b43d

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

docs/versions/v3/functions/guide.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Discover correct syntax for Textwire functions and learn about diff
44
---
55

66
# Functions Guide
7+
78
Each function is attached to a specific data type. For example, the `len` function is used to get the length of an array, and the `trim` function is used to remove characters from both sides of the string. You can call a function on a value by using the dot operator (`.`) followed by the function name.
89

910
```textwire
@@ -16,26 +17,14 @@ You can also chain multiple functions together to perform complex operations.
1617
{{ " Textwire ".trim().len() }} <!-- output: 8 -->
1718
```
1819

19-
:::tip Error Handling
2020
Learn about [error handling](/v3/guides/error-handling) in Textwire when you call a function that doesn't exist, or when you pass incorrect arguments
21-
:::
22-
23-
## Unicode Friendly
24-
Textwire is designed to be Unicode friendly to satisfy the needs of developers from different countries. All built-in functions handle Unicode characters and strings without any issues.
25-
26-
All the built-in functions in Textwire are Unicode friendly, which means they can handle Unicode characters and strings without any issues. You can use these functions to manipulate strings in any language. For example:
2721

28-
```textwire
29-
{{ "我喜欢中国".len() }} <!-- output: 5 -->
30-
```
22+
## Unicode Support
3123

32-
Or:
33-
34-
```textwire
35-
{{ "привет".at(2) }} <!-- output: и -->
36-
```
24+
Textwire's built-in functions fully support Unicode characters and strings. Whether you're working with emojis, accented characters, or non-Latin scripts, all functions work correctly. Learn more in the [Unicode](/v3/#unicode) section.
3725

3826
## Suggest a new function
27+
3928
New functions are added in new version of Textwire when there is a need for them. You can follow the updates in our [Release Notes](https://github.com/textwire/textwire/blob/master/CHANGELOG.md) on GitHub.
4029

4130
If you have a suggestion for a new function that might benefit everybody using Textwire, please open [an issue](https://github.com/textwire/textwire/issues/new) on GitHub if it's an important function to add.

docs/versions/v3/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
title: Introduction - v3
33
description: Get an overview of Textwire, a powerful template evaluator for Go developers, and learn about its features, syntax, and various use cases
4+
outline: deep
45
---
56

67
# Introduction
8+
79
Textwire is a domain-specific language (DSL) tailored for Go projects as a templating language, designed to embed dynamic content into text-based formats like HTML, XML, JSON, or any other format.
810

911
Built specifically for Go, Textwire offers a clean and intuitive syntax that simplifies the injection of variables and logic into any text-based format.
@@ -19,6 +21,7 @@ The syntax is designed to be familiar and easy-to-learn, particularly for develo
1921
## How to Use It
2022

2123
You can use Textwire in three different ways:
24+
2225
1. [As a templating engine for web applications](/v3/guides/template-usage)
2326
2. [To embed dynamic content into strings](/v3/guides/eval-string)
2427
3. [To embed dynamic content into files](/v3/guides/eval-file)
@@ -44,8 +47,42 @@ Below is a simple example of a Textwire template:
4447
@end
4548
```
4649

50+
## Unicode Support
51+
52+
Textwire fully embraces Unicode, making it ideal for international applications and multilingual content. Whether you're building websites in Chinese, Russian, Arabic, or mixing multiple languages, Textwire handles it seamlessly.
53+
54+
### String Functions
55+
56+
All built-in functions properly handle Unicode characters. They count characters correctly (not bytes) and support any language:
57+
58+
```textwire :no-line-numbers
59+
{{ "我喜欢中国".len() }} <!-- output: 5 (characters, not bytes) -->
60+
{{ "привет".at(2) }} <!-- output: и -->
61+
```
62+
63+
Keep in mind that with emojis it could be tricky, because some emojis are represented by multiple Unicode code points. The example below shows that the string "👋🏽🌍" has a length of 3, because the waving hand emoji with medium skin tone (👋🏽) is represented by two code points, while the globe emoji (🌍) is represented by one code point:
64+
65+
```textwire :no-line-numbers
66+
{{ "👋🏽🌍".len() }} <!-- output: 3 -->
67+
```
68+
69+
### File Names
70+
71+
Directives that accept file names—like `@component`, `@use`, `@insert`, `@reserve`, and `@slot`—fully support Unicode paths:
72+
73+
```textwire :no-line-numbers
74+
@component('书', { name })
75+
@use('♥️/главная')
76+
```
77+
78+
:::warning No Unicode for Identifiers
79+
Unicode characters cannot be used in variable names, function names, or object fields. Only ASCII letters (a-z, A-Z), digits (0-9), and underscores are allowed. For example, `user_name` is valid, but `用户名` and `имя` are not.
80+
:::
81+
4782
## Mathematical Expressions
83+
4884
Textwire operates similarly to Go when it comes to mathematical expressions. You can use the following operators in your templates:
85+
4986
- Addition: `+` (`a + b`)
5087
- Subtraction: `-` (`a - b`)
5188
- Multiplication: `*` (`a * b`)
@@ -70,6 +107,8 @@ Type mismatching is not supported when performing mathematical operations. For e
70107
:::
71108

72109
## Reserved Variable Names
110+
73111
Textwire has two reserved variable names that you cannot use:
112+
74113
1. `loop` Object that is used inside loops. [Read more](/v3/guides/loops#loop-variables)
75114
2. `global` Global object available in all Textwire files. [Read more](/v3/guides/configurations#global-data)

0 commit comments

Comments
 (0)