Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (13)
Tags (29)
master
dev
cefpython66
cefpython49-winxp
cefpython58
cefpython57
cefpython56
cefpython55
cefpython54
cefpython53
cefpython52
cefpython51
cefpython31
v66.1
v49.0
v49-upstream
v66.0
v66-upstream
v57.1
v58.0-win32
v57.0
v57-upstream
v56.2
v56.1
v56.0-win
v56-upstream
v56.0
v55.4
v55.3
v55.2
v54.1
v55-upstream
v55.1
master
Branches (13)
Tags (29)
master
dev
cefpython66
cefpython49-winxp
cefpython58
cefpython57
cefpython56
cefpython55
cefpython54
cefpython53
cefpython52
cefpython51
cefpython31
v66.1
v49.0
v49-upstream
v66.0
v66-upstream
v57.1
v58.0-win32
v57.0
v57-upstream
v56.2
v56.1
v56.0-win
v56-upstream
v56.0
v55.4
v55.3
v55.2
v54.1
v55-upstream
v55.1
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
master
Branches (13)
Tags (29)
master
dev
cefpython66
cefpython49-winxp
cefpython58
cefpython57
cefpython56
cefpython55
cefpython54
cefpython53
cefpython52
cefpython51
cefpython31
v66.1
v49.0
v49-upstream
v66.0
v66-upstream
v57.1
v58.0-win32
v57.0
v57-upstream
v56.2
v56.1
v56.0-win
v56-upstream
v56.0
v55.4
v55.3
v55.2
v54.1
v55-upstream
v55.1
cefpython
/
tools
/
toc.py
cefpython
/
tools
/
toc.py
toc.py 6.13 KB
Copy Edit Raw Blame History
cztomczak authored 2017年04月14日 14:41 +08:00 . Update toc.py
# Copyright (c) 2016 CEF Python, see the Authors file.
# All rights reserved. Licensed under BSD 3-clause license.
# Project website: https://github.com/cztomczak/cefpython
"""Create Table of contents (TOC) for a single .md file or for a directory.
Usage:
toc.py FILE
toc.py DIR
To ignore file when generating TOC, put an empty line just before H1.
"""
import os
import sys
import re
import glob
API_DIR = os.path.join(os.path.dirname(__file__), "..", "api")
def main():
"""Main entry point."""
if len(sys.argv) == 1:
sys.argv.append(API_DIR)
if (len(sys.argv) == 1 or
"-h" in sys.argv or
"--help" in sys.argv or
"/?" in sys.argv):
print(__doc__.strip())
sys.exit(0)
arg1 = sys.argv[1]
if os.path.isdir(arg1):
(modified, warnings) = toc_dir(arg1)
if modified:
print("Done")
else:
print("No changes to TOCs. Files not modified.")
else:
(modified, warnings) = toc_file(arg1)
if modified:
print("Done")
else:
print("No changes to TOC. File not modified.")
if warnings:
print("Warnings: "+str(warnings))
def toc_file(file_):
"""A single file was passed to doctoc. Return bool whether modified
and the number of warnings."""
with open(file_, "rb") as fo:
orig_contents = fo.read().decode("utf-8", "ignore")
# Fix new lines just in case. Not using Python's "rU",
# it is causing strange issues.
orig_contents = re.sub(r"(\r\n|\r|\n)", os.linesep, orig_contents)
(tocsize, contents, warnings) = create_toc(orig_contents, file_)
if contents != orig_contents:
with open(file_, "wb") as fo:
fo.write(contents.encode("utf-8"))
tocsize_str = ("TOC size: "+str(tocsize) if tocsize
else "TOC removed")
print("Modified: "+file_+" ("+tocsize_str+")")
return True, warnings
else:
return False, warnings
def toc_dir(dir_):
"""A directory was passed to doctoc. Return bool whether any file was
modified and the number of warnings."""
files = glob.glob(os.path.join(dir_, "*.md"))
modified_any = False
warnings = 0
for file_ in files:
if "API-categories.md" in file_ or "API-index.md" in file_:
continue
(modified, warnings) = toc_file(file_)
if not modified_any:
modified_any = True if modified else False
return modified_any, warnings
def create_toc(contents, file_):
"""Create or modify TOC for the document contents."""
match = re.search(r"Table of contents:%s(\s*\* \[[^\]]+\]\([^)]+\)%s){2,}"
% (os.linesep, os.linesep), contents)
oldtoc = match.group(0) if match else None
(tocsize, toc, warnings) = parse_headings(contents, file_)
if oldtoc:
if not toc:
# If toc removed need to remove an additional new lines
# that was inserted after toc.
contents = contents.replace(oldtoc+os.linesep, toc)
else:
contents = contents.replace(oldtoc, toc)
elif tocsize:
# Insert after H1, but if there is text directly after H1
# then insert after that text.
first_line = False
if not re.search(r"^#\s+", contents):
print("WARNING: missing H1 on first line. Ignoring file: "+file_)
return 0, contents, warnings+1
lines = contents.splitlines()
contents = ""
toc_inserted = False
for line in lines:
if not first_line:
first_line = True
else:
if not toc_inserted and re.search(r"^(##|###)", line):
contents = contents[0:-len(os.linesep)]
contents += os.linesep + toc + os.linesep + os.linesep
toc_inserted = True
contents += line + os.linesep
# Special case for README.md - remove Quick Links toc for subheadings
re_find = (r" \* \[Docs\]\(#docs\)[\r\n]+"
r" \* \[API categories\]\(#api-categories\)[\r\n]+"
r" \* \[API index\]\(#api-index\)\r?\n?")
contents = re.sub(re_find, "", contents)
return tocsize, contents, warnings
def parse_headings(raw_contents, file_):
"""Parse contents looking for headings. Return a tuple with number
of TOC elements, the TOC fragment and the number of warnings."""
# Remove code blocks
parsable_contents = re.sub(r"```[\s\S]+?```", "", raw_contents)
# Parse H1,H2,H3
headings = re.findall(r"^(#|##|###)\s+(.*)", parsable_contents,
re.MULTILINE)
toc = "Table of contents:" + os.linesep
tocsize = 0
warnings = 0
count_h1 = 0
count_h2 = 0
for heading in headings:
level = heading[0]
level = (1 if level == "#" else
2 if level == "##" else
3 if level == "###" else None)
assert level is not None
title = heading[1].strip()
if level == 1:
count_h1 += 1
if count_h1 > 1:
warnings += 1
print("WARNING: found more than one H1 in "+file_)
continue
if level == 2:
count_h2 += 1
hash_ = headinghash(title)
indent = ""
if level == 3:
if count_h2:
# If there was no H2 yet then H3 shouldn't have indent.
indent = " " * 2
toc += indent + "* [%s](#%s)" % (title, hash_) + os.linesep
tocsize += 1
if tocsize <= 1:
# If there is only one H2/H3 heading do not create TOC.
toc = ""
tocsize = 0
return tocsize, toc, warnings
def headinghash(title):
"""Get a link hash for a heading H1,H2,H3."""
hash_ = title.lower()
hash_ = hash_.replace(" - ", "specialcase1")
hash_ = hash_.replace(" / ", "specialcase2")
hash_ = re.sub(r"[^a-z0-9_\- ]+", r"", hash_)
hash_ = hash_.replace(" ", "-")
hash_ = re.sub(r"[-]+", r"-", hash_)
hash_ = re.sub(r"-$", r"", hash_)
hash_ = hash_.replace("specialcase1", "---")
hash_ = hash_.replace("specialcase2", "--")
return hash_
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

ddsdsd
No labels
unknown license
unknown open source license
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aoplxml/cefpython.git
git@gitee.com:aoplxml/cefpython.git
aoplxml
cefpython
cefpython
master
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 によって変換されたページ (->オリジナル) /