Repository navigation
feat(project): markdown.resolveReference 决定预览可跟随的链接与可加载的图片 - #37
Merged
Merged
Conversation
预览点链接、加载图片时由 Core 判定目标:http/https/mailto 链接交给系统, #锚点留在文档内,相对或 /path 文件按工作区(文档在工作区外时为文档目录)解析; 图片只放行范围内、解析符号链接后仍在范围内的现有图片文件,以及 http/https 地址。 契约同步写明请求、返回的 kind 和判定规则,并更新已过时的 Windows 客户端描述。
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.
关联
桌面端 Markdown 预览改用 web view(1lck/Lithe-IDEA#1903)。web 页面点链接、加载图片时,要由 Core 决定目标是什么、能不能读,页面自己不能碰工作区文件。#32 已合入内嵌 SVG 的过滤;这个提交当时在 #32 的分支上但没赶上合并,这里基于最新 main 单独提交。
改动
markdown.resolveReference,判定渲染后文档里的一个链接目标或图片src指向什么。请求带documentPath、可选的workspaceRoot、原样的reference和purpose(link是点击,resource是页面要加载的图片)。返回按kind区分:external:http、https、mailto 链接,交给系统浏览器或邮件客户端。remote:带主机名的 http、https 图片,由前端按自己的代理策略下载。anchor:文档内的#锚点,去掉#并做百分号解码。file:本机文件;图片还带mime。none:不跟随、不加载。workspaceRoot里时范围是工作区,否则是文档所在目录。/path从范围根开始,其他相对路径从文档目录开始;去掉查询串和片段,百分号解码,按字面解析.和..。file是按字面算出的路径,不要求文件存在。file必须按字面和解析符号链接后都在范围内,是已存在的普通文件,扩展名是apng、avif、bmp、gif、ico、jpeg、jpg、png、svg、webp之一;返回规范路径。不满足就是none。file:、data:、javascript:、单字母的 Windows 盘符等其他 scheme 一律none;//host补成https:。rust/crates/project/src/markdown_reference.rs,分发器、命令表和请求追踪同步登记。rust/contracts/rust-core-api.md:命令表新增一行;“Markdown rendering”一节写明请求、返回的kind和判定规则,并把已过时的“Windows 异步请求”描述改成对所有前端成立的说法。顺手修正命令表里markdown.render的语法错误(Render → Renders)。验证
cargo test -p lithe-project --lib markdown:12 个测试通过,含links_follow_addresses_anchors_and_files、resources_are_images_inside_the_workspace、resources_do_not_leave_the_workspace_through_a_link、a_document_outside_the_workspace_reaches_only_its_folder。cargo test -p lithe-core --lib project:72 个测试通过,含分发器对新命令的往返测试。cargo fmt --all -- --check、cargo clippy -p lithe-project -p lithe-core --all-targets -- -D warnings:通过。./internal/webpreview和./internal/workbench的全部测试。不涉及插件契约、能力版本或插件函数协议,所以不需要更新协议记录。