Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ electron . --smoke test\shot.png
- 与安卓侧交互一律走 `src/core/adb.js`,不要在各处直接拼 adb 命令。
- 主进程与渲染进程之间只通过 `preload.js` 暴露的白名单通道通信,保持 `contextIsolation` 开启。
- 注释与 UI 文案使用中文,标识符使用英文。
- 界面多语言:UI 文案**照常写中文**,不用改调用点。词典 `src/i18n/en-US.json` 以中文原文为 key,
界面显示时自动翻译(见 `src/i18n/index.js`)。新增或改动文案后跑一次
`npm run i18n`,再按 `npm run i18n -- --missing` 列出的条目补上英文即可;没补的文案在英文界面里会暂时显示中文,不会出错。

## 测试约定

Expand Down
294 changes: 294 additions & 0 deletions docs/ApkStart-User-Manual.html

Large diffs are not rendered by default.

511 changes: 511 additions & 0 deletions docs/USER-MANUAL.en.md

Large diffs are not rendered by default.

267 changes: 144 additions & 123 deletions docs/build-manual-html.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@

HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
SRC = os.path.join(HERE, 'USER-MANUAL.md')
OUT = os.path.join(HERE, 'ApkStart-用户手册.html')
# 每种语言一份:中文是原文;英文译本 USER-MANUAL.en.md 在界面语言为 English 时打开。
# 0.6.2 起手册内嵌进软件:同一份 HTML 也要落到 src/ui,随包分发。
# 主进程打开的就是这一份,绝不依赖 docs/ 或外部文件。
APP_OUT = os.path.join(ROOT, 'src', 'ui', 'manual.html')

with open(SRC, encoding='utf-8') as f:
lines = f.read().split('\n')
BUILDS = [
{
'lang': 'zh-CN',
'src': os.path.join(HERE, 'USER-MANUAL.md'),
'outs': [os.path.join(HERE, 'ApkStart-用户手册.html'), os.path.join(ROOT, 'src', 'ui', 'manual.html')],
'title': 'ApkStart 产品使用手册与问题解决方案',
'toc': '目录',
'search': '筛选目录(Ctrl+F 全文搜索)',
'print': '打印 / 存为 PDF',
},
{
'lang': 'en-US',
'src': os.path.join(HERE, 'USER-MANUAL.en.md'),
'outs': [os.path.join(HERE, 'ApkStart-User-Manual.html'), os.path.join(ROOT, 'src', 'ui', 'manual.en-US.html')],
'title': 'ApkStart User Manual and Troubleshooting Guide',
'toc': 'Contents',
'search': 'Filter (Ctrl+F to search all)',
'print': 'Print / save as PDF',
},
]


def inline(s):
Expand All @@ -37,125 +52,120 @@ def slug(text, used):
return s


out = []
toc = []
used = set()
i = 0
n = len(lines)
in_code = False
code_buf = []

while i < n:
line = lines[i]

# 代码块
if line.startswith('```'):
if not in_code:
in_code = True
code_buf = []
else:
out.append('<pre><code>' + html.escape('\n'.join(code_buf)) + '</code></pre>')
in_code = False
i += 1
continue
if in_code:
code_buf.append(line)
i += 1
continue

# 水平线
if re.match(r'^---+\s*$', line):
out.append('<hr/>')
i += 1
continue

# 标题
m = re.match(r'^(#{1,4})\s+(.*)$', line)
if m:
lvl = len(m.group(1))
text = m.group(2).strip()
anchor = slug(text, used)
if lvl in (2, 3):
toc.append((lvl, anchor, text))
out.append('<h%d id="%s">%s</h%d>' % (lvl, anchor, inline(text), lvl))
i += 1
continue

# 表格
if line.strip().startswith('|') and i + 1 < n and re.match(r'^\s*\|?[\s:\-|]+\|?\s*$', lines[i + 1]):
def cells(row):
return [c.strip() for c in row.strip().strip('|').split('|')]
header = cells(line)
i += 2
rows = []
while i < n and lines[i].strip().startswith('|'):
rows.append(cells(lines[i]))
def render(lines):
out = []
toc = []
used = set()
i = 0
n = len(lines)
in_code = False
code_buf = []

while i < n:
line = lines[i]

# 代码块
if line.startswith('```'):
if not in_code:
in_code = True
code_buf = []
else:
out.append('<pre><code>' + html.escape('\n'.join(code_buf)) + '</code></pre>')
in_code = False
i += 1
t = ['<div class="tw"><table><thead><tr>']
t += ['<th>' + inline(c) + '</th>' for c in header]
t.append('</tr></thead><tbody>')
for r in rows:
t.append('<tr>')
t += ['<td>' + inline(c) + '</td>' for c in r]
t.append('</tr>')
t.append('</tbody></table></div>')
out.append(''.join(t))
continue

# 引用
if line.startswith('> '):
q = []
while i < n and lines[i].startswith('>'):
q.append(lines[i].lstrip('>').strip())
continue
if in_code:
code_buf.append(line)
i += 1
out.append('<blockquote>' + inline(' '.join(q)) + '</blockquote>')
continue

# 有序列表
if re.match(r'^\d+\.\s+', line):
items = []
while i < n and re.match(r'^\d+\.\s+', lines[i]):
items.append(re.sub(r'^\d+\.\s+', '', lines[i]))
continue

# 水平线
if re.match(r'^---+\s*$', line):
out.append('<hr/>')
i += 1
out.append('<ol>' + ''.join('<li>' + inline(x) + '</li>' for x in items) + '</ol>')
continue

# 无序列表
if re.match(r'^\s*[-*]\s+', line):
items = []
while i < n and re.match(r'^\s*[-*]\s+', lines[i]):
items.append(re.sub(r'^\s*[-*]\s+', '', lines[i]))
continue

# 标题
m = re.match(r'^(#{1,4})\s+(.*)$', line)
if m:
lvl = len(m.group(1))
text = m.group(2).strip()
anchor = slug(text, used)
if lvl in (2, 3):
toc.append((lvl, anchor, text))
out.append('<h%d id="%s">%s</h%d>' % (lvl, anchor, inline(text), lvl))
i += 1
out.append('<ul>' + ''.join('<li>' + inline(x) + '</li>' for x in items) + '</ul>')
continue

# 空行
if not line.strip():
i += 1
continue
continue

# 表格
if line.strip().startswith('|') and i + 1 < n and re.match(r'^\s*\|?[\s:\-|]+\|?\s*$', lines[i + 1]):
def cells(row):
return [c.strip() for c in row.strip().strip('|').split('|')]
header = cells(line)
i += 2
rows = []
while i < n and lines[i].strip().startswith('|'):
rows.append(cells(lines[i]))
i += 1
t = ['<div class="tw"><table><thead><tr>']
t += ['<th>' + inline(c) + '</th>' for c in header]
t.append('</tr></thead><tbody>')
for r in rows:
t.append('<tr>')
t += ['<td>' + inline(c) + '</td>' for c in r]
t.append('</tr>')
t.append('</tbody></table></div>')
out.append(''.join(t))
continue

# 引用
if line.startswith('> '):
q = []
while i < n and lines[i].startswith('>'):
q.append(lines[i].lstrip('>').strip())
i += 1
out.append('<blockquote>' + inline(' '.join(q)) + '</blockquote>')
continue

# 有序列表
if re.match(r'^\d+\.\s+', line):
items = []
while i < n and re.match(r'^\d+\.\s+', lines[i]):
items.append(re.sub(r'^\d+\.\s+', '', lines[i]))
i += 1
out.append('<ol>' + ''.join('<li>' + inline(x) + '</li>' for x in items) + '</ol>')
continue

# 无序列表
if re.match(r'^\s*[-*]\s+', line):
items = []
while i < n and re.match(r'^\s*[-*]\s+', lines[i]):
items.append(re.sub(r'^\s*[-*]\s+', '', lines[i]))
i += 1
out.append('<ul>' + ''.join('<li>' + inline(x) + '</li>' for x in items) + '</ul>')
continue

# 空行
if not line.strip():
i += 1
continue

# 段落(合并连续普通行)
para = [line.strip()]
i += 1
while i < n and lines[i].strip() and not re.match(r'^(#{1,4})\s|^\s*[-*]\s+|^\d+\.\s+|^>|^\s*\||^```|^---+\s*$', lines[i]):
para.append(lines[i].strip())
# 段落(合并连续普通行)
para = [line.strip()]
i += 1
out.append('<p>' + inline(' '.join(para)) + '</p>')

body = '\n'.join(out)
while i < n and lines[i].strip() and not re.match(r'^(#{1,4})\s|^\s*[-*]\s+|^\d+\.\s+|^>|^\s*\||^```|^---+\s*$', lines[i]):
para.append(lines[i].strip())
i += 1
out.append('<p>' + inline(' '.join(para)) + '</p>')
return '\n'.join(out), toc

toc_html = []
for lvl, anchor, text in toc:
cls = 'toc-l2' if lvl == 2 else 'toc-l3'
toc_html.append('<a class="%s" href="#%s">%s</a>' % (cls, anchor, html.escape(text)))
toc_html = '\n'.join(toc_html)

doc = '''<!DOCTYPE html>
<html lang="zh-CN">
TEMPLATE = '''<!DOCTYPE html>
<html lang="__LANG__">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ApkStart 产品使用手册与问题解决方案</title>
<title>__TITLE__</title>
<style>
:root{--bg:#ffffff;--fg:#1f2328;--mut:#57606a;--line:#d0d7de;--code:#eff1f3;--accent:#0969da;--accent-soft:#ddf4ff;--warn:#9a6700;--warn-bg:#fff8c5;--head:#f6f8fa;--tbl:#f6f8fa}
*{box-sizing:border-box}
Expand Down Expand Up @@ -197,15 +207,15 @@ def cells(row):
</head>
<body>
<div class="wrap">
<aside><h2>目录</h2>
<input id="tocSearch" type="search" placeholder="筛选目录(Ctrl+F 全文搜索)" autocomplete="off" />
<aside><h2>__TOCTITLE__</h2>
<input id="tocSearch" type="search" placeholder="__SEARCH__" autocomplete="off" />
<div id="tocList">__TOC__</div>
</aside>
<main>
__BODY__
</main>
</div>
<div class="btnbar"><button onclick="window.print()">打印 / 存为 PDF</button></div>
<div class="btnbar"><button onclick="window.print()">__PRINT__</button></div>
<script>
(function () {
var input = document.getElementById('tocSearch');
Expand All @@ -226,9 +236,20 @@ def cells(row):
</html>
'''

doc = doc.replace('__TOC__', toc_html).replace('__BODY__', body)
for target in (OUT, APP_OUT):
with open(target, 'w', encoding='utf-8') as f:
f.write(doc)
print('生成:', target)
print('大小: %d KB' % (os.path.getsize(target) // 1024))
for b in BUILDS:
with open(b['src'], encoding='utf-8') as f:
body, toc = render(f.read().split('\n'))
toc_html = []
for lvl, anchor, text in toc:
cls = 'toc-l2' if lvl == 2 else 'toc-l3'
toc_html.append('<a class="%s" href="#%s">%s</a>' % (cls, anchor, html.escape(text)))
doc = (TEMPLATE.replace('__LANG__', b['lang']).replace('__TITLE__', b['title'])
.replace('__TOCTITLE__', b['toc']).replace('__SEARCH__', b['search'])
.replace('__PRINT__', b['print'])
.replace('__TOC__', '\n'.join(toc_html)).replace('__BODY__', body))
for target in b['outs']:
# newline='\n':仓库按 LF 存,Windows 上默认写 CRLF 会让整份 HTML 显示为改动
with open(target, 'w', encoding='utf-8', newline='\n') as f:
f.write(doc)
print('生成:', target)
print('大小: %d KB' % (os.path.getsize(target) // 1024))
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"scripts": {
"start": "electron .",
"dev": "electron . --dev",
"test": "node test/run-tests.js && node test/android-test.js && node test/range-validation-test.js && node test/display-scale-test.js && node test/resources-test.js && node test/drivers-test.js && node test/preflight-test.js && node test/standalone-test.js && node test/boot-auth-test.js && node test/issue-hardening-test.js && node test/autodebug-test.js && node test/settings-categories-test.js && node test/engine-test.js && node test/manual-test.js && node test/incremental-test.js && node test/auto-test.js",
"test": "node test/run-tests.js && node test/android-test.js && node test/range-validation-test.js && node test/display-scale-test.js && node test/resources-test.js && node test/drivers-test.js && node test/preflight-test.js && node test/standalone-test.js && node test/boot-auth-test.js && node test/issue-hardening-test.js && node test/autodebug-test.js && node test/settings-categories-test.js && node test/engine-test.js && node test/manual-test.js && node test/incremental-test.js && node test/i18n-test.js && node test/auto-test.js",
"test:ui": "electron test/settings-ui-test.js",
"build:manual": "python docs/build-manual-html.py",
"pack": "node build/pack.js",
Expand All @@ -44,6 +44,7 @@
"build:appx": "node build/prepare-runtime.js && electron-builder --win appx --x64 --config electron-builder.yml",
"build:msix": "node build/msix.js",
"selftest": "node scripts/selftest.js",
"i18n": "node scripts/i18n-extract.js",
"assoc:on": "node scripts/assoc.js on",
"assoc:off": "node scripts/assoc.js off",
"test:boot": "node test/boot-test.js",
Expand Down
Loading