Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

补充 chinese-remove-space 的副作用 #50

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions docs/FAQ/chinese-remove-space.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,43 @@ tags: [layout, text]
0.12 可以玩 `regex` 魔法了,`regex` 现在可以跨不同的 `text`

```typst
测试一下,效果怎么样。✓

测试一下,
效果怎么样。
效果怎么样。

#show regex("[\p{sc=Hani} 。 ; , : “ ”( ) 、 ? 《 》] [\p{sc=Hani} 。 ; , : “ ”( ) 、 ? 《 》]"): it => {
// https://www.w3.org/TR/clreq/#table_of_punctuation_marks
#let han-or-punct = "[-\p{sc=Hani}。.,、:;!‼?⁇⸺——……⋯⋯~–—·・‧//「」『』“”‘’()《》〈〉【】〖〗〔〕[]{}_﹏●•]"
#show regex(han-or-punct + " " + han-or-punct): it => {
let (a, _, b) = it.text.clusters()
a + b
}

测试一下,
效果怎么样。
效果怎么样。✓
```

::: details 微小副作用

在整个正则表达式匹配的边界,标点宽度会有问题。

```typst
#set page(width: auto, height: auto, margin: 1em)
#set text(font: ((name: "New Computer Modern", covers: "latin-in-cjk"), "Source Han Serif SC"))

“七斤嫂,你‘恨棒打人’。……”✓

“七斤嫂,你‘恨棒打人’。
……”✗

#show regex("[。] [……]"): it => {
let (a, _, b) = it.text.clusters()
a + b
}

“七斤嫂,你‘恨棒打人’。
……”✗
```

相关 issue:[Ignore linebreaks between CJK characters in source code · #792](https://github.com/typst/typst/issues/792)
:::