Skip to content

Commit 11d1996

Browse files
authored
Merge pull request #249 from vinta/fix/spacing-rules-v6.1-new
Fix/spacing rules v6.1
2 parents ccaa2f2 + 84849e7 commit 11d1996

File tree

23 files changed

+1088
-564
lines changed

23 files changed

+1088
-564
lines changed

.claude/TODO.md

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
# Development Progress
22

3-
## Project Overview
4-
5-
pangu.js is a mature text spacing library that automatically inserts whitespace between CJK and half-width characters, with zero runtime dependencies. The project includes both a JavaScript library (npm package) and a Chrome extension (Manifest V3).
6-
73
## Completed
84

9-
### New Features
10-
11-
- [x] Blacklist/whitelist with Chrome match pattern validation (files: service-worker.ts, options.ts, popup.ts)
12-
- [x] Chrome's `excludeMatches` API for efficient blacklist handling (files: service-worker.ts)
13-
- [x] "Blacklist this" button in popup (files: popup.ts, popup.html)
14-
15-
### Regex Pattern Fixes
16-
17-
- [x] Fixed `AN_LEFT_BRACKET` for function calls like `a.getB()` (files: shared/index.ts)
18-
- [x] Fixed pipe character `|` handling (#194) (files: shared/index.ts)
19-
- [x] Fixed filesystem paths with special chars (#209, #218, #219) (files: shared/index.ts)
20-
- [x] Fixed HTML tag spacing (#164) (files: shared/index.ts)
21-
- [x] Fixed input field auto-spacing (#158) (files: browser/pangu.ts)
22-
- [x] Fixed slash pattern conflicts (files: shared/index.ts)
23-
- [x] Improved filesystem path pattern (files: shared/index.ts)
24-
- [x] Fixed HTML comment spacing to handle `<!--content-->` properly (files: shared/index.ts)
25-
- Updated `FIX_LEFT_BRACKET_ANY_RIGHT_BRACKET` pattern to support compound brackets
26-
- Ensures no spaces after `<!--` or before `-->`
27-
- [x] Major algorithm update: Paranoid Text Spacing v6 (files: shared/index.ts)
28-
- Special handling for all bracket types: `()` `[]` `{}` `<>`
29-
- Improved slash `/` pattern handling
5+
### Paranoid Text Spacing Algorithm v6
6+
7+
- [x] **Context-Aware Symbol Handling**
8+
- Operators (`=` `+` `-` `*` `/` `<` `>` `&` `^`): ALWAYS add spaces when CJK is present
9+
- Separators (`_` `|`): NEVER add spaces regardless of context
10+
- Dual-behavior slash `/`: Single occurrence = operator, multiple = separator
11+
- [x] **Smart Pattern Recognition**
12+
- Compound words: `state-of-the-art`, `GPT-5`, `claude-4-opus` preserved
13+
- Programming terms: `C++`, `A+`, `i++`, `D-`, `C#`, `F#` handled correctly
14+
- File paths: Unix (`/usr/bin`, `src/main.py`) and Windows (`C:\Users\`) protected
15+
- Special brackets: `()` `[]` `{}` `<>` with content-aware spacing
16+
- [x] Function call spacing: `a.getB()` no longer becomes `a.getB ()`
17+
- [x] HTML tag attributes: Proper spacing around `=` in attributes
18+
- [x] Input field auto-spacing: Fixed to prevent breaking form functionality (#158)
19+
- [x] Pipe character `|`: Now correctly treated as separator (#194)
20+
- [x] Filesystem paths: Special characters in paths preserved (#209, #218, #219)
3021

3122
## In Progress
3223

33-
- [ ] None
24+
No task in progress
3425

3526
## Upcoming Tasks
3627

@@ -41,22 +32,16 @@ pangu.js is a mature text spacing library that automatically inserts whitespace
4132
### Medium Priority
4233

4334
- [ ] Fix issue #201 - Spaces between image-separated text
44-
- [ ] Fix issue #173 - Full-width quotes spacing (「」『』)
35+
- [ ] Fix issue #173 - Full-width quotes spacing, `「」` and `『』`
4536
- [ ] Fix issue #169 - YouTube title persistence
4637
- [ ] Fix issue #207 - Bilibili upload page layout breaking
4738

4839
### Low Priority
4940

50-
- [ ] Fix issue #216 - Markdown syntax protection
51-
- [ ] Fix issue #161 - Comprehensive Markdown support
52-
53-
## Known Issues & Limitations
54-
55-
- [x] Investigated adjacent sibling spacing (YouTube hashtags) (files: tests/browser/pangu.playwright.ts)
56-
- What's done: Multiple approach attempts (sibling checking, post-processing, XPath mods)
57-
- Result: Fundamental XPath algorithm limitation
41+
- [ ] Handle HTML comment spacing: `<!-- content -->`
42+
- [ ] Fix issue #161 #216 - Comprehensive Markdown support
5843

59-
## Survey
44+
## Researches
6045

6146
- Survey `createTreeWalker()`
6247
- https://developer.mozilla.org/en-US/docs/Web/API/Document/createTreeWalker

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ interface Settings {
188188
- Keep regex patterns readable with comments
189189
- Always use `node:` prefix for Node.js built-in modules
190190

191+
### Implementation Details
192+
193+
- Core spacing logic: @src/shared/index.ts
194+
- Core test cases: @tests/shared/index.test.ts
195+
191196
## Future Improvements
192197

193198
See @.claude/TODO.md for planned improvements and technical debt.

GEMINI.md

Lines changed: 2 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,3 @@
1-
## Pangu.js
1+
# GEMINI.md
22

3-
Pangu.js is a TypeScript library that automatically adds spacing between Chinese, Japanese, and Korean (CJK) characters and half-width characters (English letters, numbers, and symbols). This improves readability on web pages and in text files.
4-
5-
The project is structured into a shared core, a browser-specific implementation, and a Node.js-specific implementation. It also includes a command-line interface (CLI) and a Chrome extension.
6-
7-
### Project Structure
8-
9-
- **`src/shared`**: The core logic of the library, which is platform-agnostic.
10-
- **`src/node`**: The Node.js-specific implementation, which provides a CLI and can be used to space text files.
11-
- **`src/browser`**: The browser-specific implementation, which uses `MutationObserver` to automatically space web pages.
12-
- **`browser_extensions/chrome`**: The source code for the Chrome extension.
13-
- **`tests`**: The test suite for the project, which includes unit tests and end-to-end tests.
14-
15-
### How to Build
16-
17-
The project is built using `vite`. To build the project, run the following command:
18-
19-
```bash
20-
npm run build
21-
```
22-
23-
This will build the library and the Chrome extension.
24-
25-
### How to Test
26-
27-
The project uses `vitest` and `playwright` for testing. To run the tests, run the following command:
28-
29-
```bash
30-
npm run test
31-
```
32-
33-
### How to Use
34-
35-
The library can be used in the browser, in Node.js, or as a CLI.
36-
37-
**Browser**
38-
39-
```html
40-
<script src="pangu/dist/browser/pangu.umd.js"></script>
41-
<script>
42-
const text = pangu.spacingText('當你凝視著bug,bug也凝視著你');
43-
// text = '當你凝視著 bug,bug 也凝視著你'
44-
45-
pangu.spacingElementById('main');
46-
pangu.spacingElementByClassName('comment');
47-
pangu.spacingElementByTagName('p');
48-
49-
document.addEventListener('DOMContentLoaded', () => {
50-
// listen to any DOM change and automatically perform spacing via MutationObserver()
51-
pangu.autoSpacingPage();
52-
});
53-
</script>
54-
```
55-
56-
**Node.js**
57-
58-
```javascript
59-
import pangu from 'pangu';
60-
// or
61-
const pangu = require('pangu');
62-
63-
const text = pangu.spacingText('不能信任那些Terminal或Editor用白底的人');
64-
// text = '不能信任那些 Terminal 或 Editor 用白底的人'
65-
66-
const content = await pangu.spacingFile('/path/to/text.txt');
67-
```
68-
69-
**CLI**
70-
71-
```bash
72-
pangu "與PM戰鬥的人,應當小心自己不要成為PM"
73-
```
74-
75-
### Commit Guidelines
76-
77-
Strive for atomic commits. Each commit should represent a single, logical change. If your work involves multiple unrelated changes (e.g., a bug fix and a documentation update), please separate them into individual commits. This practice helps maintain a clean and understandable project history.
78-
79-
## Gemini Code Instructions
80-
81-
### Core Workflow
82-
83-
Always follow: **Understand → Plan → Implement → Verify**
84-
85-
1. **Understand**: Analyze the request, understand context, identify constraints, and validate assumptions. Use available tools to gather information.
86-
2. **Plan**: Design a clear approach, anticipate edge cases, and choose the most efficient path.
87-
3. **Implement**: Apply changes using available tools, adhering to project conventions and best practices.
88-
4. **Verify**: Confirm changes by running tests, linters, or build commands as appropriate.
89-
90-
### Response Guidelines
91-
92-
- **Concise & Direct**: Aim for minimal output, focusing strictly on the user's query. Avoid conversational filler.
93-
- **No Emojis**: Never use emojis in code, comments, commits, or responses.
94-
- **Clarity over Brevity (When Needed)**: Prioritize clarity for essential explanations or when seeking necessary clarification.
95-
- **Action over Theory**: Show code or tool usage instead of just describing them.
96-
- **Model Selection**: Always use the most powerful available model, even if it means longer response times.
97-
98-
### Critical Analysis
99-
100-
- **Challenge Premise**: Question if the proposed problem is the right one to solve.
101-
- **Question Assumptions**: Identify and clarify any underlying assumptions.
102-
- **Propose Alternatives**: Suggest simpler or more effective approaches when applicable.
103-
- **Direct Feedback**: Provide clear and specific feedback on approaches or issues.
104-
105-
### Implementation Rules
106-
107-
- **Start Minimal**: Implement the smallest working code that validates the approach.
108-
- **One File Preference**: Prefer modifying existing files over creating new ones unless necessary.
109-
- **Self-Documenting Code**: Prioritize clear naming; add comments sparingly, focusing on *why* rather than *what*.
110-
- **Fast Failure**: Validate inputs early and provide descriptive errors.
111-
- **No Premature Optimization**: Focus on correctness and clarity before optimizing.
112-
113-
### Automation Guidelines
114-
115-
- **Reversible Actions**: For actions that are easily reversible (e.g., git commits, file modifications that can be rolled back by git), proceed without explicit confirmation.
3+
Read @CLAUDE.md

HISTORY.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# History
22

3+
## v6.1.0 / 2025-06-30
4+
5+
- 各位強迫症患者,Paranoid Text Spacing 演算法 v6.1
6+
- 好啦好啦,我要去玩死亡擱淺 2 了
7+
38
## v6.0.0 / 2025-06-28
49

5-
- 各位觀眾,Paranoid Text Spacing 演算法 v6
10+
- 各位強迫症患者,Paranoid Text Spacing 演算法 v6
611
- 特別處理了各種括號 `()` `[]` `{}` `<>``/` 的問題,仁至義盡了
712

813
## v5.3.2 / 2025-06-27
@@ -11,7 +16,7 @@
1116

1217
## v5.2.0 / 2025-06-26
1318

14-
- 各位觀眾,Paranoid Text Spacing 演算法 v5
19+
- 各位強迫症患者,Paranoid Text Spacing 演算法 v5
1520

1621
## v5.1.1 / 2025-06-24
1722

@@ -52,7 +57,7 @@
5257

5358
## v4.0.0 / 2019-01-27
5459

55-
- 各位觀眾,Paranoid Text Spacing 演算法 v4
60+
- 各位強迫症患者,Paranoid Text Spacing 演算法 v4
5661
- 大幅地改進 Chrome extension 的效能,使用 `MutationObserver``debounce`
5762
- 忍痛拿掉「空格之神顯靈了」
5863
- 修正 `Pangu.spacingText()` 的 error callback

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![](https://img.shields.io/npm/v/pangu.svg?style=flat-square)](https://www.npmjs.com/package/pangu)
55
[![](https://img.shields.io/badge/made%20with-%e2%9d%a4-ff69b4.svg?style=flat-square)](https://vinta.ws/code/)
66

7-
如果你跟我一樣,每次看到網頁上的中文字和英文、數字、符號擠在一塊,就會坐立難安,忍不住想在它們之間加個空格。這個 Chrome 外掛正是你在網路世界走跳所需要的東西,它會自動替你在網頁中所有的中文字和半形的英文、數字、符號之間插入空白。
7+
如果你跟我一樣,每次看到網頁上的中文字和英文、數字、符號擠在一塊,就會坐立難安,忍不住想在它們之間加個空格。這個 Google Chrome 外掛正是你在網路世界走跳所需要的東西,它會自動替你在網頁中所有的中文字和半形的英文、數字、符號之間插入空白。
88

99
漢學家稱這個空白字元為「盤古之白」,因為它劈開了全形字和半形字之間的混沌。另有研究顯示,打字的時候不喜歡在中文和英文之間加空格的人,感情路都走得很辛苦,有七成的比例會在 34 歲的時候跟自己不愛的人結婚,而其餘三成的人最後只能把遺產留給自己的貓。畢竟愛情跟書寫都需要適時地留白。
1010

@@ -75,8 +75,8 @@ Learn more on [npm](https://www.npmjs.com/package/pangu).
7575
`pangu.js` is also available on some popular npm CDNs:
7676

7777
```html
78-
<script src="https://cdn.jsdelivr.net/npm/pangu@6.0.0/dist/browser/pangu.umd.js"></script>
79-
<script src="https://unpkg.com/pangu@6.0.0/dist/browser/pangu.umd.js"></script>
78+
<script src="https://cdn.jsdelivr.net/npm/pangu@6.1.0/dist/browser/pangu.umd.js"></script>
79+
<script src="https://unpkg.com/pangu@6.1.0/dist/browser/pangu.umd.js"></script>
8080
```
8181

8282
### Node.js

browser_extensions/chrome/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "__MSG_extension_name__",
44
"description": "__MSG_extension_description__",
55
"short_name": "__MSG_god_of_spacing__",
6-
"version": "6.0.0",
6+
"version": "6.1.0",
77
"author": "Vinta",
88
"default_locale": "zh_TW",
99
"icons": {

0 commit comments

Comments
 (0)