Click-to-source (reverse search) between HTML preview and .qmd source

Đang mở
#1,130 1 bình luận 2 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
42/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, typescript, vscode

Hướng nghiên cứu

Start with the reload script injected by quarto preview, then inspect the quarto-source-map crate and Codebraid Preview as reference points for tracking static Markdown positions. Define a first version for headings, paragraphs, and lists only; done means a preview double-click sends a position over the existing WebSocket and opens the .qmd source in the editor, while computed chunk output remains excluded.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

vscode

Feature request

Provide click-to-source (a.k.a. reverse search) between the quarto preview HTML output and the .qmd source, similar to the forward/inverse search Overleaf/SyncTeX provide for LaTeX: double-click an element in the preview and jump to the corresponding line in the editor.

This has sort of come up a few times already: #37 (two-way scroll sync), #492 (open source file for the current preview page), and in quarto-cli discussions #2163 and #12927. Opening this as a single, scoped proposal to consolidate those.

Proposed approach

  • Inject source-position metadata into rendered HTML block elements (e.g. data-sourcepos="file:line:col").
  • Extend the reload script that quarto preview already injects into the page to listen for a dblclick and send the captured position back over the existing WebSocket connection.
  • On the extension side, open the editor at that location — code --goto file:line:col, or the equivalent vscode://file/... URI, which works the same way for Positron.

On feasibility

Pandoc has a native sourcepos extension that adds data-pos attributes to the AST, but per Pandoc's changelog it's limited to the CommonMark-family readers (commonmark, gfm, commonmark_x), not the extended markdown reader that .qmd uses by default. So I don't think this wouldn't be a matter of flipping an existing flag for the current engine.

That said, the underlying problem, bidirectional scroll sync for Pandoc documents, including non-CommonMark markdown and documents with executed code, seems to me to be already been solved in an adjacent tool: Codebraid Preview. It maintains its own source-position tracking when Pandoc's native sourcepos isn't available, and stays in sync through code execution via Jupyter kernels. Worth a look as a reference implementation maybe?

Also relevant: the newer Rust parser work in quarto-dev/quarto-markdown already has a quarto-source-map crate for byte-range source tracking, currently used for diagnostics. That could plausibly be the right long-term foundation, even though I didn't see it wired into quarto preview yet.

Suggested scope for a first version

Given the complications around chunk-executed output, I'd suggest starting with static Markdown content (headings, paragraphs, lists) and explicitly excluding computed chunk output rather than aiming for full fidelity on dynamic content immediately. That alone would cover most of the "find where I need to edit" workflow.

Ngôn ngữ chính
TypeScript
Star
665
Fork
69
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quarto-dev/quarto

Tất cả issue của quarto-dev/quarto

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.