Skip to content

Commit b7dd68e

Browse files
committed
ref: 去除多余代码
1 parent b2ef256 commit b7dd68e

File tree

6 files changed

+78
-62
lines changed

6 files changed

+78
-62
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ node_modules/
77
dist/
88
/web/assets/
99

10-
/readme_sync/
1110
/readme_snatcher/python-cheatsheet.md
11+
/readme_sync/

README-zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python Standard Libraries Cheatsheet
22

3-
Depend on Python v3.10.11
3+
Depend on Python v3.13.7
44

55
All code snippets have been tested to ensure they work properly.
66

readme_sync/README_S.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Python Standard Libraries Cheatsheet
2+
3+
Depend on Python v3.9.8
4+
5+
All code snippets have been tested to ensure they work properly.
6+
7+
Fork me on [GitHub](https://github.com/pynickle/python-cheatsheet-redefined).
8+
9+
- [中文](README-zh-cn.md)
10+
- [English](README.md)
11+
12+
**Notes**:
13+
14+
- **Every code snippet here can run independently (some need the files provided by this repo)**
15+
- **You can use readme_snatcher.py to download README.md from the repository (Chinese or English, with or not with command line prefixes is up to you!)**
16+
17+
## Contents

readme_sync/README_zh_cn_S.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Python 标准库速查表
2+
3+
依赖 Python v3.9.8
4+
5+
所有代码片段都经过测试确保可以正常运行
6+
7+
[GitHub](https://github.com/pynickle/python-cheatsheet-redefined)上fork这个仓库吧
8+
9+
- [中文](README-zh-cn.md)
10+
- [English](README.md)
11+
12+
**注意**:
13+
- **这里的每个代码片段都可以独立运行 (一些需要这个仓库提供的文件)**
14+
- **你可以使用 readme_snatcher.py 来从仓库中下载 README.md (中英文,命令行前缀的有无皆可选择)**
15+
16+
## 目录

readme_sync/sync_readme.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
replace_contents = [
2+
('Text Processing', '文本处理'),
3+
('Binary Data', '二进制数据'),
4+
('Data Type', '数据类型'),
5+
('Mathematical Modules', '数学模块'),
6+
('Functional Programming', '函数式编程'),
7+
('Directory Access', '目录访问'),
8+
('Data Persistence', '数据持久化'),
9+
('Data Compression', '数据压缩'),
10+
('File Formats', '文件格式'),
11+
('Cryptographic Services', '加密服务'),
12+
('Operating System', '操作系统'),
13+
('Networking Communication', '网络通信'),
14+
('Internet Data', '互联网数据'),
15+
('Structured Markup', '结构化标记'),
16+
('Internet Protocols', '互联网协议'),
17+
('Multimedia Services', '多媒体服务'),
18+
('Program Frameworks', '程序框架'),
19+
('Graphical Interfaces', '图形化用户界面'),
20+
('Development Tools', '开发工具'),
21+
('Debugging Profiling', '调试和分析'),
22+
('Software Packaging', '软件打包与分发'),
23+
('Runtime Services', '运行时服务'),
24+
('Importing Modules', '导入模块'),
25+
('Language Services', 'Python 语言服务'),
26+
('Bonus Scene', '彩蛋')
27+
]
28+
29+
if __name__ == "__main__":
30+
with open("../README.md", "r", encoding="utf-8") as f:
31+
text = f.read()
32+
33+
with open("README_S.md", "r", encoding="utf-8") as en_us_s:
34+
readme_s = en_us_s.read()
35+
with open("README_zh_cn_S.md", "r", encoding="utf-8") as zh_cn_s:
36+
readme_zh_cn_s = zh_cn_s.read()
37+
38+
text = text.replace(readme_s, readme_zh_cn_s)
39+
for replace_content in replace_contents:
40+
text = text.replace(replace_content[0], replace_content[1], 1)
41+
42+
with open("../README-zh-cn.md", "w", encoding="utf-8") as res:
43+
res.write(text)

web/src/main.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@ type StyleType = 'atom-one-dark' | 'base16/edge-dark' | 'base16/tomorrow-night'
1111
// 定义语言类型
1212
type LanguageType = 'english' | 'chinese';
1313

14-
// 定义代码前缀显示状态
15-
type PrefixMode = 'with-prefix' | 'without-prefix';
16-
1714
// 存储原始代码(带前缀)
1815
const originalCodeCache = new Map<string, string>();
1916

20-
// 存储当前前缀模式
21-
let currentPrefixMode: PrefixMode = 'with-prefix';
22-
2317
// 从代码中移除Python交互式前缀(保留前缀后的缩进,去除行首多余空格)
2418
function removePythonPrefixes(code: string): string {
2519
// 分割代码为行
@@ -123,9 +117,6 @@ function setupCodeBlocks(): void {
123117
}
124118
}
125119
});
126-
127-
// 应用当前前缀模式
128-
applyPrefixMode(currentPrefixMode);
129120
}
130121

131122
// 切换单个代码块的前缀显示
@@ -158,44 +149,6 @@ function toggleCodePrefix(blockId: string): void {
158149
}
159150
}
160151

161-
// 应用全局前缀模式
162-
function applyPrefixMode(mode: PrefixMode): void {
163-
currentPrefixMode = mode;
164-
165-
document.querySelectorAll('pre code[id^="code-block-"]').forEach(block => {
166-
const blockId = block.id;
167-
if (originalCodeCache.has(blockId)) {
168-
const originalCode = originalCodeCache.get(blockId)!;
169-
170-
if (mode === 'without-prefix') {
171-
block.textContent = removePythonPrefixes(originalCode);
172-
} else {
173-
block.textContent = originalCode;
174-
}
175-
}
176-
177-
// 移除已高亮标记,以便重新高亮
178-
if (block instanceof HTMLElement) {
179-
delete block.dataset.highlighted;
180-
}
181-
});
182-
183-
// 重新高亮所有代码
184-
if ((window as any).hljs && typeof (window as any).hljs.highlightAll === 'function') {
185-
try {
186-
(window as any).hljs.highlightAll();
187-
} catch (error) {
188-
console.error('Error highlighting code:', error);
189-
}
190-
}
191-
192-
// 更新全局切换按钮的文本
193-
const prefixToggleButton = document.getElementById('prefix-toggle-button');
194-
if (prefixToggleButton) {
195-
prefixToggleButton.textContent = mode === 'with-prefix' ? 'Show without prefix' : 'Show with prefix';
196-
}
197-
}
198-
199152
// 动态加载HTML内容的函数
200153
function loadContent(language: LanguageType): void {
201154
// 设置当前语言显示
@@ -369,22 +322,9 @@ document.addEventListener('DOMContentLoaded', function() {
369322
});
370323
}
371324

372-
// 下载PDF
373-
(window as any).download = function() {
374-
const language: LanguageType = (getURLParameter('lang') as LanguageType) || 'english';
375-
if (language === 'english') {
376-
window.open('https://raw.githubusercontent.com/pynickle/python-cheatsheet-redefined/master/README.pdf', '_blank');
377-
} else {
378-
window.open('https://raw.githubusercontent.com/pynickle/python-cheatsheet-redefined/master/README-zh-cn.pdf', '_blank');
379-
}
380-
};
381-
382-
383-
384325
// 初始加载内容
385326
loadContent(languageParam);
386327
});
387328

388329
// 暴露全局函数供外部调用
389-
(window as any).applyPrefixMode = applyPrefixMode;
390330
(window as any).toggleCodePrefix = toggleCodePrefix;

0 commit comments

Comments
 (0)