Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 0

长路/awesome-openclaw-tutorial

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
main
Branches (1)
main
main
Branches (1)
main
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
main
Branches (1)
main
awesome-openclaw-tutorial
/
scripts
/
add_code_language.py
awesome-openclaw-tutorial
/
scripts
/
add_code_language.py
add_code_language.py 4.03 KB
Copy Edit Raw Blame History
Maynor996 authored 2026年02月15日 00:48 +08:00 . docs: 为代码块添加语言标注(72%完成)
#!/usr/bin/env python3
"""
为代码块自动添加语言标注
根据代码块内容智能判断语言类型
"""
import re
import os
from pathlib import Path
def detect_language(content):
"""根据代码块内容检测语言类型"""
if not content.strip():
return 'text'
first_line = content.strip().split('\n')[0].strip()
# 检测 Bash/Shell 命令
bash_patterns = [
r'^(openclaw|clawhub|npm|pnpm|yarn|bun|git|docker|curl|wget|ssh)\s',
r'^(cd|ls|mkdir|rm|cp|mv|cat|echo|export|source|chmod|chown)\s',
r'^\$\s',
r'^#\s*!/bin/(bash|sh)',
]
for pattern in bash_patterns:
if re.search(pattern, first_line):
return 'bash'
# 检测 JSON
if content.strip().startswith('{') or content.strip().startswith('['):
if '"' in content and ':' in content:
return 'json'
# 检测 YAML
if re.search(r'^[a-zA-Z_][\w-]*:\s*\S', content, re.MULTILINE):
if '{' not in content[:50]: # 不是 JSON
return 'yaml'
# 检测 Python
python_patterns = [
r'^(def|class|import|from|if __name__|print\(|return)\s',
r'^\s*(def|class)\s+\w+',
]
for pattern in python_patterns:
if re.search(pattern, content, re.MULTILINE):
return 'python'
# 检测 JavaScript/TypeScript
js_patterns = [
r'^(const|let|var|function|class|import|export|require\(|module\.exports)\s',
]
ts_patterns = [
r'^(interface|type|enum|namespace|declare)\s',
r':\s*(string|number|boolean|any|void|never)\s*[;=]',
]
for pattern in ts_patterns:
if re.search(pattern, content, re.MULTILINE):
return 'typescript'
for pattern in js_patterns:
if re.search(pattern, content, re.MULTILINE):
return 'javascript'
# 检测输出内容
output_patterns = [
r'(Output:|Error:|Success:|Warning:|INFO|DEBUG)',
r'[✅❌⚠️]',
r'Exit Code:',
]
for pattern in output_patterns:
if re.search(pattern, content):
return 'text'
# 默认返回 text
return 'text'
def process_file(filepath):
"""处理单个 Markdown 文件"""
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 查找所有未标注语言的代码块
pattern = r'```\s*\n(.*?)\n```'
modified = False
stats = {'bash': 0, 'json': 0, 'text': 0, 'yaml': 0, 'python': 0, 'javascript': 0, 'typescript': 0}
def replace_code_block(match):
nonlocal modified, stats
code_content = match.group(1)
lang = detect_language(code_content)
if lang:
modified = True
stats[lang] = stats.get(lang, 0) + 1
return f'```{lang}\n{code_content}\n```'
return match.group(0)
new_content = re.sub(pattern, replace_code_block, content, flags=re.DOTALL)
if modified:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
return True, stats
return False, stats
def main():
docs_dir = Path('docs')
print("🔍 开始为代码块添加语言标注...")
print()
total_files = 0
total_stats = {'bash': 0, 'json': 0, 'text': 0, 'yaml': 0, 'python': 0, 'javascript': 0, 'typescript': 0}
# 遍历所有 Markdown 文件
for md_file in docs_dir.rglob('*.md'):
modified, stats = process_file(md_file)
if modified:
total_files += 1
print(f"✅ {md_file}")
for lang, count in stats.items():
if count > 0:
total_stats[lang] += count
print()
print("✅ 处理完成!")
print()
print("📊 统计信息:")
print(f" - 修改文件数: {total_files}")
print(" - 添加语言标注:")
for lang, count in sorted(total_stats.items(), key=lambda x: x[1], reverse=True):
if count > 0:
print(f" - {lang}: {count}")
print()
if __name__ == '__main__':
main()
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/changluJava/awesome-openclaw-tutorial.git
git@gitee.com:changluJava/awesome-openclaw-tutorial.git
changluJava
awesome-openclaw-tutorial
awesome-openclaw-tutorial
main
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /