docs: make bilingual readmes practical and conversational

This commit is contained in:
2026-10-14 17:30:21 +08:00
parent 7ab9fcf8d1
commit ff4bbbf32b
2 changed files with 166 additions and 186 deletions
+73 -84
View File
@@ -1,66 +1,57 @@
# wp-asciiplayer
为 WordPress 提供原生 Asciicast Player 区块,可在编辑器内真实播放终端录屏,
同时兼容原有 `[asciiplayer]` shortcode。
把终端录屏放进 WordPress 文章和页面。添加 **Asciicast Player** 区块,就能一边编辑一边预览录屏;
旧文章里的 `[asciiplayer]` shortcode 也可以继续使用。
[English documentation](README.md)
## 界面语言
插件自己的界面支持英文和简体中文(`zh_CN`)。编辑器跟随「用户 → 个人资料 → 语言」
(未单独设置时跟随站点),前台跟随「设置 → 常规 → 站点语言」。翻译文件随安装包附带,可离线使用。
英文为默认回退语言。不会把 `zh_TW` 等其他中文地区设置自动映射为简体中文。
录屏中的终端内容和作者填写的说明文字不会被翻译。上游播放器自身的播放控件和帮助仍为英文,播放器文件保持原样。
## 安装
1. 将构建得到的 `wp-asciiplayer.zip` 上传到 **插件 → 安装插件 → 上传插件**。
2. 启用插件。
需要 **WordPress 6.3+** 和 **PHP 7.4+**。
GitHub 源码 ZIP 需要先构建,不能直接当发行包安装。构建方法见 [SOURCE.md](SOURCE.md)。
1. 在 **插件 → 安装插件 → 上传插件** 中上传构建好的 `wp-asciiplayer.zip`。
2. 启用 **Asciicast Player**。
**环境要求:** WordPress 6.3+、PHP 7.4+;具体测试版本见[仓库 CI](.github/workflows/ci.yml)。
GitHub 下载的源码 ZIP 需要先构建,不能直接安装,步骤见[构建说明](SOURCE.md)。
[仓库 CI](.github/workflows/ci.yml) 列出了测试的环境组合;使用前也请检查与你的主题是否兼容。
## 区块编辑器
## 添加录屏
1. 插入 **Asciicast Player** 区块。
2. 粘贴录制文件的 HTTP(S) URL,停止输入约半秒后会自动加载预览;
也可以点击 **Apply URL** 立即加载。
3. 之后即可在编辑器内播放、暂停和拖动。
4. **Display** 面板提供展示宽度预设、自定义宽度(例如 `480px`、`65%`)以及左、中、右对齐;
展示宽度会限制在当前页面可用空间内。
5. 点击播放器下方即可添加描述文字。
2. 粘贴录制文件的 URL,或点击 **选择录制文件(Choose recording)**,从媒体库选择或上传 `.cast` 文件。
3. 停止输入约半秒后会自动加载预览。点击 **Apply URL** 可以立即加载,然后就能播放、暂停和拖动进度。
4. 在 **Display** 中设置宽度和对齐方式。可以选择预设,也可以填写 `480px`、`65%` 等 CSS 长度。
播放器下方可以添加说明文字。
5. 在区块设置中调整主题、速度、循环、控制栏、适应方式、起始时间和空闲压缩,然后保存文章或页面。
### 终端尺寸
重新打开文章时,已有有效 URL 的区块会自动加载录屏。编辑预览不会自动播放,即使你给前台启用了自动播放。
空白或无效 URL 不会发起请求。区块插入器里的示例是静态的,也不会请求录制文件。
在区块上方浮动工具栏点击 **Terminal size** 可快速调整终端行列数;侧边栏的同名折叠面板也保留,两处设置实时同步。
### 展示宽度与终端尺寸
- 终端尺寸与展示大小分别控制:**Columns** / **Rows** 留空时,使用 cast 文件记录的终端尺寸,
并跟随录制中的 resize 事件。只有需要改变终端网格时才覆盖行列数,点击 **Use recording size** 可恢复。
- 展示宽度与 `fit: width` 只缩放画面,不会修改终端行列数;覆盖网格可能影响录屏排版或裁切内容。
展示宽度决定播放器在页面里占多大空间,并且不会超出可用宽度。
调整宽度或使用 `fit: width` 只是缩放画面,不会改变终端的行列数。
主题、速度、循环、控制栏、起始时间和空闲压缩等选项仍在区块设置中调整。
**Columns** 和 **Rows** 留空时,会使用录屏本身的尺寸,并跟随录制中的尺寸变化。
需要手动设置时,可以使用区块工具栏或侧栏里的 **Terminal size**,两处设置会同步。
点击 **Use recording size** 可以清空手动设置,恢复录屏原有尺寸。
### 保存与预览行为
加载后,空白字段会显示录屏的原始行列数作为提示。换一个 URL 会刷新提示,但保留你手动填写的值。
提示只读取同一次预览响应的前 **64 KiB**;读取不到时保留通用占位提示,不猜测尺寸。
录制过程中后续的尺寸变化不会改变这组提示。
保存文章或页面后,前台使用同一播放器。重新打开已有区块时,只要已有有效 URL 就自动加载预览。
播放器自带样式,用来保持终端文字对齐和键盘焦点可见。部分主题可能仍需要调整 CSS。
播放操作和录屏隐私说明可以在侧栏的 **帮助(Help)** 面板中找到。
编辑预览不会自动播放,前台自动播放设置仍会保留。
### 录制文件地址
区块插入器使用本地静态示例,不请求录制文件。
URL 要直接指向录制文件,例如 `.cast` 文件,而不是 asciinema 分享页面。
其他域名上的文件需要允许来自你站点的 CORS 请求。HTTPS 页面可能无法加载 HTTP 文件,优先使用同站点的 HTTPS 地址。
插件不会代理请求或复制远程文件。
播放器增加了局部样式隔离,避免常见主题的代码块边框、阴影和字体设置干扰终端;键盘焦点提示仍保留。
## 旧文章与 shortcode
### 录制来源
URL 必须指向录制文件(例如 `.cast`),不能直接使用分享页面地址。跨域文件需要允许
来自你站点的 CORS 请求;HTTPS 页面上的 HTTP 文件可能被浏览器阻止。优先使用同源 HTTPS。
本插件不提供远程文件代理、不扩大用户的上传权限,也不创建额外的录屏管理文章类型。
## 旧文章兼容
原有 shortcode 继续有效,无须批量修改文章:
旧文章可以继续使用原有 shortcode,不需要批量修改:
```text
[asciiplayer]https://example.org/demo.cast[/asciiplayer]
@@ -68,56 +59,54 @@ URL 必须指向录制文件(例如 `.cast`),不能直接使用分享页
[asciiplayer startAt="2" idleTimeLimit="3" style="width: 80%;"]https://example.org/demo.cast[/asciiplayer]
```
布尔值、数值和历史 camelCase 参数会归一化处理;自定义 `style` 经过 WordPress 安全 CSS 过滤。
布尔值、数值和旧的 camelCase 参数会自动处理。自定义 `style` 会经过 WordPress 的安全 CSS 过滤;
不安全的 URL、标记,以及可执行或对象形式的选项不会被接受。
区块提供 shortcode 转换能力,转换后请检查设置再保存,不会自动重写旧文章。
支持的 shortcode 可以转换成区块,保存前请检查设置。插件不会自动重写旧文章。
经典编辑器仍可使用 shortcode,但没有专门的播放器编辑界面。
经典编辑器继续使用 shortcode,暂不增加 TinyMCE 自定义界面。
## 媒体库上传
已有 WordPress `upload_files` 权限的用户可以上传 `.cast` 文件。
多站点还需要网络管理员允许 `cast` 扩展名。插件不会增加用户的上传权限,也不会另建录屏管理文章类型。
上传文件会完整校验,限制如下:
- 每个文件最多 **32 MiB**。
- 最多 **100,000** 个事件或流内行。
- 每条 JSONL 行最多 **256 KiB**。
- 终端任一方向不超过 **1,000** 列或行。
旧的 asciicast v1 格式最多 **2 MiB**,需要格式化 JSON,并让起始 `{` 单独占一行;
内置播放器无法读取压成一行的 v1 文件。Asciicast v2、v3 使用标准 JSONL。
站点或服务器更低的上传限制仍然生效。无效录屏会被拒绝,也不会因此开放普通 JSON、HTML 或 SVG 上传。
## 界面语言
插件界面包含英文和简体中文(`zh_CN`):
- 编辑器跟随 **用户 → 个人资料 → 语言**;未单独设置时使用站点语言。
- 前台跟随 **设置 → 常规 → 站点语言**。
翻译文件随 ZIP 附带,可离线使用。英文是默认回退语言,不需要单独的 `en_US` 翻译文件。
`zh_TW` 等其他中文地区设置不会自动映射成简体中文。
录屏中的终端内容和你填写的说明文字不会被翻译。
内置播放器自身的播放控件和帮助仍为英文,其文件保持上游原样。
## 资源与隐私
播放器 JavaScript、CSS、WebAssembly 全部本地附带,不再请求 jsDelivr,
旧 `ap_use_local_resources` 开关不再使用。没有统计追踪或后台远程 API 请求。
播放器的 JavaScript、CSS 和 WebAssembly 都在插件内,不会从 jsDelivr 加载。
插件没有统计追踪,也不会在后台调用远程 API。旧的 `ap_use_local_resources` 选项不再使用。
你选择的录制文件会由读者浏览器直接请求;外部文件主机可能收到 IP、浏览器请求信息和
依浏览器/站点策略发送的来源信息。编辑器存在有效 URL 时也会自动发起这类请求,包括重新打开已保存的区块。
录屏文件会由浏览器直接请求你填写的 URL。外部主机可能收到读者的 IP 地址、浏览器请求信息,
以及浏览器和站点设置允许发送的来源信息。编辑预览也会发起同样的请求,包括重新打开已有录屏的文章时。
请使用可信主机,发布前检查录屏是否包含终端里的敏感信息。外部主机适用其自身隐私政策。
请使用可信主机,发布前检查终端录屏是否含有敏感信息。
外部主机适用自己的隐私政策,插件无法让外部录屏变成私有文件。
## 媒体库与原始终端尺寸
## 构建与许可
### 选择与上传
构建、测试和 ZIP 打包步骤见 [SOURCE.md](SOURCE.md)。
点击区块中的 **选择录制文件(Choose recording)** 可通过 WordPress 媒体库选择或上传 `.cast` 录制文件。
上传权限沿用 WordPress 的 `upload_files` 能力,不会为低权限用户开放上传。插件仅为经过格式校验的 `.cast` 文件添加支持,不放开任意 JSON、HTML 或 SVG。
### 原始尺寸提示
浮动工具栏和折叠侧栏中的 **Columns** / **Rows** 留空时,会在录制加载后显示原始终端尺寸作为占位提示。
更换 URL 会刷新提示,但保留你明确填写的覆盖值;恢复录制尺寸会清空覆盖值,继续尊重录制中的尺寸变化。未知或加载失败时不猜测尺寸。
原始尺寸提示只检查同一次预览响应的前 **64 KiB**,无法读取时保留通用提示。
### 上传限制
上传文件会完整校验:
- 最多 **32 MiB**。
- 最多 **100,000 个事件或流内行**。
- 每条 JSONL 行最多 **256 KiB**。
- 终端任一方向不超过 **1,000**。
旧版 v1 最多 **2 MiB**,需使用起始 `{` 单独一行的格式化 JSON;内置播放器不支持压成一行的 v1。
v2/v3 使用标准 JSONL。站点和服务器更低的上传限制仍生效,多站点还需网络允许 `cast` 扩展名。
### 区块帮助
区块内常驻的录制/隐私说明和播放操作说明位于侧栏默认折叠的 **帮助(Help)** 面板,保留标题、错误提示和必要控件标签。
## 开发与许可
[构建与测试说明](SOURCE.md) · [第三方许可证](THIRD-PARTY-NOTICES.md)
本插件保持 GPL-3.0-only,播放器及依赖保留各自的兼容许可证。
插件使用 GPL-3.0-only。播放器和依赖保留各自的兼容许可证,详见[第三方许可证](THIRD-PARTY-NOTICES.md)。
+93 -102
View File
@@ -1,90 +1,68 @@
# wp-asciiplayer
An Asciicast Player block for WordPress, with real playback in the editor and
backwards-compatible `[asciiplayer]` shortcodes.
Play terminal recordings in WordPress posts and pages. Add an **Asciicast Player**
block to preview the recording while you edit, or keep using the `[asciiplayer]`
shortcode in existing posts.
[中文说明](README-zh.md)
## Languages
Plugin-owned UI includes English and Simplified Chinese (`zh_CN`). The editor
follows **Users → Profile → Language** (or the site default); public pages follow
**Settings → General → Site Language**. Catalogs ship inside the ZIP and need no
translation server at runtime. English is the source/fallback language, so a
separate `en_US` catalog is unnecessary. `zh_TW` and other locales are not silently
mapped to Simplified Chinese. Recorded terminal output and author captions stay
unchanged. The bundled upstream player's own playback controls and help remain
English; its vendor files are not modified.
## Install
1. Install the built `wp-asciiplayer.zip` through **Plugins → Add New → Upload Plugin**.
Requires **WordPress 6.3+** and **PHP 7.4+**.
1. Upload the built `wp-asciiplayer.zip` through **Plugins → Add New → Upload Plugin**.
2. Activate **Asciicast Player**.
A GitHub source ZIP must be built first; it does not contain generated assets. See [SOURCE.md](SOURCE.md).
A GitHub source ZIP needs to be built before you can install it. See the
[build instructions](SOURCE.md). The [CI workflow](.github/workflows/ci.yml)
lists the combinations we test; check the plugin with your own theme too.
**Requirements:** WordPress 6.3+ and PHP 7.4+.
## Add a recording
Compatibility must be checked against your site and theme; CI tests the versions
listed in the [CI workflow](.github/workflows/ci.yml).
1. Insert an **Asciicast Player** block.
2. Paste a recording-file URL, or click **Choose recording** to select or upload a
`.cast` file from the Media Library.
3. The preview loads about half a second after you stop typing. Click **Apply URL**
to load it immediately, then play, pause or seek through the recording.
4. Use **Display** to set the width and alignment. You can choose a preset or enter
a CSS length such as `480px` or `65%`. Add a caption below the player.
5. Adjust the theme, speed, looping, controls, fit, start time and idle-time limit
in the block settings, then save your post or page.
## Block editor
Saved recordings load again when you reopen the editor. Previews do not autoplay,
even if you enable autoplay for the published page. Empty or invalid URLs do not
start a request. The block inserter uses a static example, so it does not fetch a
recording either.
1. Insert **Asciicast Player**.
2. Paste an HTTP(S) recording-file URL (for example a `.cast` file), or use
**Choose recording** to select/upload a `.cast` file in the WordPress Media
Library. The preview loads after a short pause; **Apply URL** loads it immediately.
3. Play, pause and seek in the editor. **Display** offers width presets or a custom
CSS length (for example `480px` or `65%`), plus left/center/right alignment.
The width stays within the available space. Add a caption below the player.
4. Use **Terminal size** in the floating block toolbar for quick **Columns**/**Rows**
edits, or expand the **Terminal size** sidebar panel. Both edit the same values.
- Empty fields show the recording’s original columns/rows as placeholders after
loading. Changing the URL refreshes these hints without clearing your explicit
overrides; reset clears overrides, so recorded resize events remain active.
- Terminal size is separate from display width: leave **Columns** and **Rows** blank
to use the cast file's dimensions and recorded resize events. Override either
axis only when intentional; use **Use recording size** to clear both.
- Display width and `fit: width` scale the existing grid without changing
terminal columns.
5. Change theme, speed, looping, controls, fit, start time and idle-time limit
from the remaining block settings.
6. Save the post or page; the same locally bundled player is used on the front end.
### Display width and terminal size
### Preview behavior
The display width controls how much space the player takes on the page. It stays
within the available width. Changing it, or using `fit: width`, scales the picture
without changing the terminal's columns and rows.
Existing saved blocks load their valid recording URL automatically on reopening
the editor. Typed URL changes are debounced for 500ms; empty or invalid URLs do
not start a recording request.
Leave **Columns** and **Rows** empty to use the recording's dimensions and resize
events. To override them, use **Terminal size** in the block toolbar or sidebar;
both controls update the same settings. **Use recording size** clears the overrides.
Preview does not autoplay even when front-end autoplay is enabled.
After loading, the empty fields show the recording's original dimensions as hints.
Changing the URL updates those hints but keeps any values you entered. The hints
come from the first 64 KiB of the preview response; if they cannot be read, the
fields keep a generic placeholder. Later resize events do not change the hints.
Recording/privacy and playback explanations are available in the collapsed
**Help** sidebar panel, keeping the block canvas focused on editing.
The player includes styles to keep terminal text aligned and keyboard focus
visible. Some themes may still need CSS adjustments. Playback tips and recording
privacy information are in the sidebar's **Help** panel.
The inserter preview is a local static example and never loads a recording.
### Recording URLs
### Theme compatibility
Terminal typography is scoped against common theme `pre`/`span` styles so
character scaling stays aligned with the player grid. A theme with additional
custom rules may still require compatibility testing; keyboard focus indicators
remain visible.
### Recording source
The source must be a recording-file URL, not an asciinema share-page URL.
A recording on another origin must allow CORS requests from your WordPress site.
HTTP recordings on an HTTPS site may be blocked as mixed content. Use a same-site
HTTPS URL when possible.
The plugin does not proxy or copy remote files, grant new upload capabilities,
or add a recording-management post type.
Use an HTTP(S) URL that points to the recording file, not an asciinema share page.
A file hosted on another domain must allow CORS requests from your site. Browsers
may block HTTP recordings on HTTPS pages; a same-site HTTPS URL is the simplest
option. The plugin does not proxy or copy remote files.
## Existing shortcodes
Old articles remain supported; no content migration is required:
Existing posts keep working without a content migration:
```text
[asciiplayer]https://example.org/demo.cast[/asciiplayer]
@@ -92,54 +70,67 @@ Old articles remain supported; no content migration is required:
[asciiplayer startAt="2" idleTimeLimit="3" style="width: 80%;"]https://example.org/demo.cast[/asciiplayer]
```
Boolean and numeric options are typed, and historical camelCase options are
normalized after WordPress lowercases shortcode attribute names. Inline styles
are filtered through WordPress safe-CSS handling; unsafe protocols and markup
are rejected/escaped. Unsupported executable/object options are not accepted.
Boolean, numeric and older camelCase options are handled automatically. Inline
styles go through WordPress's safe-CSS filter; unsafe URLs, markup and executable
or object-valued options are not accepted.
The Classic Editor continues to support shortcodes; it has no custom visual UI.
You can convert supported shortcodes into blocks. Check the settings before
saving; the plugin never rewrites old posts automatically. The Classic Editor
supports shortcodes, but has no custom player-editing interface.
The block supports a shortcode-to-block transform for supported options. Review
converted settings before saving; articles are never rewritten automatically.
## Media Library uploads
## Local resources and privacy
You can upload `.cast` files if your account already has WordPress's `upload_files`
permission. Multisite networks must also allow the `cast` extension. The plugin
does not grant extra upload permissions or add a separate recording-management
post type.
All player JavaScript, CSS, and WebAssembly are included in the plugin. The old
`ap_use_local_resources` switch is no longer used, and jsDelivr is not contacted.
No analytics or background remote API calls are added.
Uploads are checked against these limits:
A recording URL you choose is fetched directly by the visitor's browser. Its host
can receive the visitor's IP address, browser request metadata and possibly a
referrer, according to browser/site policy. Editor previews have the same effect
automatically when a valid URL is present, including when reopening saved blocks.
- **32 MiB** per file.
- **100,000** events or stream lines.
- **256 KiB** per JSONL line.
- **1,000** columns or rows in either direction.
Choose a trusted host and review recordings for sensitive terminal output before
publishing them. The host's own privacy policy applies; the plugin cannot make an external recording private.
The older asciicast v1 format is limited to **2 MiB**. Its JSON must be
pretty-printed, with the opening `{` on a line of its own; the bundled player
cannot read compact, single-line v1 files. Asciicast v2 and v3 use standard JSONL.
Lower site or server upload limits still apply. Invalid recordings are rejected;
this does not enable general JSON, HTML or SVG uploads.
## Media Library upload limits
## Languages
The plugin adds only `.cast` uploads for users who already have WordPress
`upload_files` permission. On multisite, the network must also allow the `cast`
extension. Existing site/server upload limits still apply.
The plugin's interface includes English and Simplified Chinese (`zh_CN`).
Each upload is fully validated:
- In the editor, choose **Users → Profile → Language**, or use the site default.
- On public pages, the language follows **Settings → General → Site Language**.
- At most **32 MiB**.
- At most **100,000 events/stream lines**.
- At most **256 KiB per JSONL line**.
- Dimensions up to **1,000 columns/rows**.
Translations are included in the ZIP and work offline. English is the fallback;
there is no separate `en_US` catalog. Other Chinese locales, including `zh_TW`, are
not automatically mapped to Simplified Chinese.
Legacy v1 is limited to **2 MiB** and must be pretty-printed
with its opening JSON object on a separate line because the bundled player cannot
read compact single-line v1. v2/v3 use their standard JSONL format. Invalid files
are rejected; generic JSON, HTML and SVG uploads are not enabled.
Recorded terminal output and your captions are unchanged. The bundled player's
own playback controls and help remain in English; its files are kept as supplied
by the upstream project.
Original-size hints inspect at most the first 64 KiB of the same preview response.
If metadata is unavailable, the fields keep a generic placeholder rather than
guessing dimensions. Recorded resize events do not replace the initial-size hint.
## Resources and privacy
## Development
The player’s JavaScript, CSS and WebAssembly are bundled locally. The plugin does
not contact jsDelivr, add analytics or make background remote API calls. The old
`ap_use_local_resources` option is no longer used.
See [SOURCE.md](SOURCE.md) for locked build and ZIP packaging commands. Source
code is GPL-3.0-only. The player and its dependencies retain their own compatible
licenses; see [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md).
Recordings are different: visitors' browsers fetch the URL you choose directly.
An external host may receive their IP address, browser request details and a
referrer, depending on browser and site settings. Editor previews make the same
request whenever a valid URL loads, including when you reopen a saved block.
Use a trusted host and check recordings for sensitive terminal output before
publishing. The host's privacy policy applies; the plugin cannot make an external
recording private.
## Build and license
See [SOURCE.md](SOURCE.md) for build, test and ZIP packaging commands.
The plugin is GPL-3.0-only. The player and its dependencies keep their own
compatible licenses; see [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md).