Skip to content

Commit

Permalink
Merge branch 'typst:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pauladam94 authored Jan 19, 2024
2 parents 4aa78fd + 2958213 commit 1419f95
Show file tree
Hide file tree
Showing 488 changed files with 95,127 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Package-specific issue
url: https://typst.app/docs/packages
about: Please report issues with a specific package on that package's repository. You can find it by clicking the chain icon in the package list.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/packaging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 📦 Packaging issue
description: Issue with the package system itself. Not for issues with packages!
title: Write a short and descriptive title!
body:
- type: markdown
attributes:
value: Thanks for reporting an issue with Typst's package system. Please only open an issue here if you want to report or discuss something related to the packaging itself. For issues with individual packages, please open an issue on the package's repository instead. You can find it by clicking on the chain link in the [package list](https://typst.app/docs/packages).
- type: textarea
id: description
attributes:
label: Description
description: Please describe your issue.
validations:
required: true
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ Optional:
otherwise unnecessarily increase the bundle size. Don't exclude the README or
the LICENSE.

Third-party tools can add their own entry under the `[tool]` section to attach
their own Typst-specific configuration to the manifest.

```toml
[package]
# ...

[tool.mytool]
foo = "bar"
```

Packages always live in folders named as `{name}/{version}`. The name and
version in the folder name and manifest must match. Paths in a package are local
to that package. Absolute paths start in the package root while relative paths
Expand Down
10 changes: 9 additions & 1 deletion bundler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() -> anyhow::Result<()> {
/// Create an archive for a package.
fn process_package(path: &Path) -> anyhow::Result<PackageInfo> {
println!("Bundling {}.", path.display());
let PackageManifest { package } =
let PackageManifest { package, .. } =
parse_manifest(path).context("failed to parse package manifest")?;
let buf = build_archive(path, &package.exclude).context("failed to build archive")?;
validate_archive(&buf).context("failed to validate archive")?;
Expand Down Expand Up @@ -140,12 +140,16 @@ fn write_archive(info: &PackageInfo, buf: &[u8]) -> anyhow::Result<()> {

/// A parsed package manifest.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct PackageManifest {
package: PackageInfo,
#[serde(skip_serializing_if = "Option::is_none")]
tool: Option<Tool>,
}

/// The `package` key in the manifest.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct PackageInfo {
name: String,
version: Version,
Expand All @@ -166,3 +170,7 @@ struct PackageInfo {
#[serde(default)]
exclude: Vec<String>,
}

/// The `tool` key in the manifest.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
struct Tool {}
22 changes: 22 additions & 0 deletions packages/preview/a2c-nums/0.0.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License
===========

Copyright (c) 2024 Zhuo Nengwen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions packages/preview/a2c-nums/0.0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# a2c-nums

Convert Arabic numbers to Chinese characters.

## usage

```typst
#import "@preview/a2c-nums:0.0.1": int-to-cn-num, int-to-cn-ancient-num, int-to-cn-simple-num, num-to-cn-currency
#int-to-cn-num(1234567890)
#int-to-cn-ancient-num(1234567890)
#int-to-cn-simple-num(2024)
#num-to-cn-currency(1234567890.12)
```

## Functions

### int-to-cn-num

Convert an integer to Chinese number. ex: `#int-to-cn-num(123)` will be `一百二十三`

### int-to-cn-ancient-num

Convert an integer to ancient Chinese number. ex: `#int-to-cn-ancient-num(123)` will be `壹佰贰拾叁`

### int-to-cn-simple-num

Convert an integer to simpple Chinese number. ex: `#int-to-cn-simple-num(2024)` will be `二〇二四`

### num-to-cn-currency

Convert a number to Chinese currency. ex: `#int-to-cn-simple-num(1234.56)` will be `壹仟贰佰叁拾肆元伍角陆分`

### more details

Reference [demo.typ](demo.typ) for more details please.
Binary file added packages/preview/a2c-nums/0.0.1/demo.pdf
Binary file not shown.
127 changes: 127 additions & 0 deletions packages/preview/a2c-nums/0.0.1/demo.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#import "@preview/a2c-nums:0.0.1": int-to-cn-num, int-to-cn-ancient-num, int-to-cn-simple-num, num-to-cn-currency

#set heading(numbering: "1.1")

= a2c-nums 示例

== int-to-cn-simple-num

#int-to-cn-simple-num(2024)

== int-to-cn-num 0-999

#{
let i = 0;
while i < 1000 {
int-to-cn-num(i) + " "
i += 1
}
}

== others

#int-to-cn-num(2024)

#int-to-cn-num(987654321)

=== 一个0:

#int-to-cn-num(907654321)

#int-to-cn-num(907054321)

#int-to-cn-num(907050321)

#int-to-cn-num(907050301)

=== 两个0:

#int-to-cn-num(900654321)

#int-to-cn-num(980054321)

#int-to-cn-num(987004321)

#int-to-cn-num(987600321)

#int-to-cn-num(987650021)

#int-to-cn-num(987654001)

#int-to-cn-num(987654300)

=== 三个0:

#int-to-cn-num(900054321)

#int-to-cn-num(980004321)

#int-to-cn-num(987000321)

#int-to-cn-num(987600021)

#int-to-cn-num(987650001)

#int-to-cn-num(987654000)

=== 四个0:

#int-to-cn-num(900004321)

#int-to-cn-num(980000321)

#int-to-cn-num(987000021)

#int-to-cn-num(987600001)

#int-to-cn-num(987650000)

=== 五个0:

#int-to-cn-num(900000321)

#int-to-cn-num(980000021)

#int-to-cn-num(987000001)

#int-to-cn-num(987600000)

=== 六个0:

#int-to-cn-num(900000021)

#int-to-cn-num(980000001)

#int-to-cn-num(987000000)

=== 七个0:

#int-to-cn-num(900000001)

#int-to-cn-num(980000000)

=== 八个0:

#int-to-cn-num(900000000)

== int-to-cn-ancient-num

#int-to-cn-ancient-num(2024)

#{
let i = 0;
while i < 1000 {
int-to-cn-ancient-num(i) + " "
i += 1
}
}

== num-to-cn-currency

#num-to-cn-currency(1234.56)

#num-to-cn-currency(0.5678)

#num-to-cn-currency(1203405602.5678)

#num-to-cn-currency(234)
106 changes: 106 additions & 0 deletions packages/preview/a2c-nums/0.0.1/src/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Convert an int to Chinese number, for ex: 2024 become "二〇二四"
#let int-to-cn-simple-num(n) = {
let digits = ("", "", "", "", "", "", "", "", "", "")
let s = str(n)
let result = ""
for c in s.codepoints() {
result += digits.at(int(c))
}
return result
}

// Convert an int string to Chinese number, for ex: "2024" become "二千零二十四"
#let str-to-cn-num(s) = {
let digits = ("", "", "", "", "", "", "", "", "", "")
let units = ("", "", "", "", "", "", "", "", "亿", "", "", "")
let result = ""
let len = s.len() - 1
let i = len
while i >= 0 {
result = digits.at(int(s.at(i))) + units.at(len - i) + result;
i -= 1
}

for i in (0, 1, 2, 3) {
result = result.replace("零亿", "亿")
result = result.replace("零万", "")
result = result.replace("零千", "")
result = result.replace("零百", "")
result = result.replace("零十", "")
result = result.replace("零零", "")
result = result.replace("亿万", "亿")
}
if result.len() > 3 and result.ends-with("") {
result = result.trim("")
}
if result.len() == 9 or result.len() == 6 {
result = result.replace("一十", "")
}
return result
}

// Convert an int to Chinese number, for ex: 2024 become "二千零二十四"
#let int-to-cn-num(n) = {
let s = str(n)
return str-to-cn-num(s)
}

// Convert an int string to Chinese ancient number, for ex: "2024" become "贰仟零贰拾肆"
#let str-to-cn-ancient-num(s) = {
let digits = ("", "", "", "", "", "", "", "", "", "")
let units = ("", "", "", "", "", "", "", "", "亿", "", "", "")
let result = ""
let len = s.len() - 1
let i = len
while i >= 0 {
result = digits.at(int(s.at(i))) + units.at(len - i) + result;
i -= 1
}

for i in (0, 1, 2, 3) {
result = result.replace("零亿", "亿")
result = result.replace("零万", "")
result = result.replace("零仟", "")
result = result.replace("零佰", "")
result = result.replace("零拾", "")
result = result.replace("零零", "")
result = result.replace("亿万", "亿")
}
if result.len() > 3 and result.ends-with("") {
result = result.trim("")
}
if result.len() == 9 or result.len() == 6 {
result = result.replace("壹拾", "")
}
return result
}

// Convert an int to Chinese ancient number, for ex: 2024 become "贰仟零贰拾肆"
#let int-to-cn-ancient-num(n) = {
let s = str(n)
return str-to-cn-ancient-num(s)
}

// Convert a number to Chinese currency, for ex: 1234.56 become "壹仟贰佰叁拾肆元伍角陆分"
#let num-to-cn-currency(n) = {
let digits = ("", "", "", "", "", "", "", "", "", "")
let units = ("", "")
let intpart = ""
let decimal = ""
let value = str(calc.round(n, digits: 2))
let splits = value.split(".")
intpart = splits.at(0)
if splits.len() > 1 {
decimal = splits.at(1)
}
let result = ""
if decimal != none {
for (i, c) in decimal.codepoints().enumerate() {
if i <= 1 {
result += digits.at(int(c)) + units.at(i)
}
}
}
result = str-to-cn-ancient-num(intpart) + "" + result
return result
}
13 changes: 13 additions & 0 deletions packages/preview/a2c-nums/0.0.1/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "a2c-nums"
version = "0.0.1"
authors = ["Zhuo Nengwen <soarowl@yeah.net>"]
license = "MIT"
description = "Convert a number to Chinese"
repository = "https://github.com/soarowl/a2c-nums.git"

keywords = ["Converter", "number", "Chinese", "Currency"]

entrypoint = "src/lib.typ"
compiler = "0.10.0"
exclude = ["demo.pdf"]
Loading

0 comments on commit 1419f95

Please sign in to comment.