Repository navigation
feat(project): htmlPreview 命令决定 HTML 文件预览的站点根目录与每个请求服务的内容 - #42
Merged
Merged
Conversation
新增 htmlPreview.site 与 htmlPreview.resolveRequest:站点根目录与 markdown.resolveReference 的范围一致;请求按字面和解析符号链接后都必须留在根目录内,隐藏路径与密钥、证书文件拒绝,文档本身由编辑器文本服务。
# Conflicts: # rust/contracts/rust-core-api.md # rust/crates/core/src/runtime/dispatcher.rs # rust/crates/project/src/lib.rs
…记内嵌 HTML 预览 分发器测试读 rust/fixtures/editor/html-preview-v1.json:工作区里的页面、隐藏目录里的页面、工作区之外的页面三组用例,以及相对路径的 invalid_request。桌面端测试读同一份 fixture。 application-boundary.md 新增 Embedded HTML preview 一节;External HTML preview 改为当前桌面端的行为:先保存未保存的修改再用系统浏览器打开,范围含 .xhtml 和 .svg。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联
桌面端 Viva 开始在编辑器旁预览 HTML 文件(
.html、.htm、.xhtml),桌面端 PR:1lck/Lithe-IDEA#1923(Draft,已把PINNED_CORE_REVISION固定到本 PR 的合入提交 f88bc49)。预览页会运行文件里的脚本,所以它请求的每个路径能不能读、读到什么,都由 Core 决定,前端只照 Core 的回答服务。改动
htmlPreview.site:给出 HTML 文件按静态站点预览时的根目录、文件在站点里的地址和服务时用的内容类型。documentPath和可选的workspaceRoot。根目录的取法和markdown.resolveReference的范围相同:文档在工作区里时是工作区,否则是文档所在目录。{ root, address, mime }。address是文档从根开始的路径,每一段都做百分号编码;mime按扩展名取,比如text/html; charset=utf-8。documentPath不是绝对路径时返回invalid_request。htmlPreview.resolveRequest:判定预览页的一个请求该服务什么。请求在上面两个参数之外再带path,也就是 web 引擎报来的路径:已解码、用/分隔、不带查询串和片段,根目录为空串。Core 不会再解码一次。返回按kind区分:document:路径指向文档本身,不管用的是什么名字。前端服务编辑器里的文本,所以没保存的修改也能看到。file:已存在的普通文件,带规范路径path和mime。directory:目录下的index.html是根里的普通文件时返回这个,前端给一个把浏览器带到该index.html的页面。denied:前端回 403。以下两类路径返回它:.开头的路径。文档所在目录本身经过的那几层隐藏目录除外,所以.github/pages里的页面能加载它的邻居,但读不到.git/config。jks、key、keystore、p12、pem、pfx的密钥或证书。none:前端回 404。\、:或 NUL 的段一律none。mime按扩展名查表:文本类型统一带 UTF-8,未知扩展名是application/octet-stream。markdown_reference.rs里算范围的代码抽成document_scope,join_lexically和within改为 crate 内可见,两个命令和 Markdown 引用判定共用同一套范围规则,Markdown 的行为不变。rust/crates/project/src/html_preview.rs。两个命令在分发器、命令表和请求追踪里同步登记。rust/fixtures/editor/html-preview-v1.json:一组工作区文件,加 3 个用例,共 28 个请求,另有无效的文档路径。3 个用例是工作区里的页面、隐藏目录里的页面(能读自己所在目录,读不到其他隐藏目录)和工作区外的页面。Core 的分发器测试与桌面端TestHTMLPreviewSharedFixture读同一份文件。rust/contracts/application-boundary.md:markdown.resolveReference的链接规则处理;页面打不开时只有 HTML 文件退回纯文本。该节链接到上面的 fixture。.html/.htm、不保存缓冲区,现在改为桌面端、.html/.htm/.xhtml/.svg,打开前先保存未保存的修改。rust/contracts/rust-core-api.md:命令表新增两行;新增“HTML file preview”一节,写明请求、返回的每种kind和判定规则,并写明前端不能信任页面的任何请求:只服务命令给出的内容,不通过站点写文件,页面的顶层导航按markdown.resolveReference的链接规则处理。验证
cargo test -p lithe-project --lib html_preview:4 个测试通过,分别是the_site_is_the_workspace_with_the_document_addressed_from_its_root、requests_serve_the_document_files_and_folders_of_the_site、requests_stay_inside_the_root_and_out_of_hidden_files_and_keys、links_are_resolved_before_the_root_and_hidden_names_are_checked。cargo test -p lithe-project --lib markdown:12 个测试通过,说明抽出document_scope之后 Markdown 引用判定不变。html_preview_commands_match_shared_fixture:逐个跑 fixture 的用例,经分发器调用两个命令,与 fixture 的期望逐项比对。markdown.outline)之后重跑:cargo test -p lithe-project(85 个)、cargo test -p lithe-core(790 个)全部通过。cargo fmt --all -- --check、cargo clippy -p lithe-project -p lithe-core --all-targets -- -D warnings:通过。-race跑完全部 55 个 Go 包,含读取同一份 fixture 的TestHTMLPreviewSharedFixture;之后固定到 f88bc49 又跑了一次 HTML 预览相关测试,结果见 feat(desktop): HTML 文件在编辑器旁预览页面,按工作区静态站点加载并实时更新 1lck/Lithe-IDEA#1923。本 PR 不涉及插件契约、能力版本和插件函数协议,所以不需要更新协议记录。