[ BUG ] TOC links break when a path with a space is one of several inputs

Đang mở Phù hợp với người mới
#100 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
cli

Hướng nghiên cứu

Tiền tố đường dẫn được thêm trong internal/core/toc/renderer.go, tại Renderer.Render. Trước tiên, hãy đọc hàm đó và các bài kiểm thử renderer hiện có. Mã hóa khoảng trắng trong tiền tố liên kết thành %20, sau đó xác nhận rằng đầu vào không có khoảng trắng và thông báo lỗi vẫn giữ nguyên đầu ra hiện tại; ví dụ tái hiện trong issue cho biết TOC mong đợi.

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

Mô tả

bug

Describe the bug

With several inputs, every TOC entry links to <input>#<anchor>, with the input as given
on the command line. When the input has a space, the link is not valid Markdown, and
GitHub renders the entry as plain text. The names of GitHub wiki pages can have spaces.
The Bash version had the same bug (ekalinin/github-markdown-toc#76) and fixed it in
ekalinin/github-markdown-toc#190.

To Reproduce

mkdir "test directory"
printf '# Title one\n\n## Section\n' > "test directory/a.md"
printf '# Title two\n' > "test directory/b.md"
gh-md-toc --hide-footer "test directory/a.md" "test directory/b.md"

Actual:

* [Title one](test directory/a.md#title-one)
  * [Section](test directory/a.md#section)

* [Title two](test directory/b.md#title-two)

The GitHub Markdown API renders the first entry as
<li>[Title one](test directory/a.md#title-one)</li>, without a link.

Expected behavior

As in the Bash version, every space in the link prefix is replaced with %20, and no
other character changes:

* [Title one](test%20directory/a.md#title-one)
  * [Section](test%20directory/a.md#section)

* [Title two](test%20directory/b.md#title-two)

Inputs without a space give the same output as now. Messages that show the input, such
as errors, keep it as given.

Environment (please complete the following information):

  • OS: macOS (darwin/arm64)
  • Version: 2.0.1, current master (dd680f7)

Additional context

  • The prefix is added in Renderer.Render (internal/core/toc/renderer.go):
    link = path + link.
  • With --insert, local files get bare anchors, so the TOC written into them is not
    affected.
Ngôn ngữ chính
Go
Star
525
Fork
89
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
1

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

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

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 ekalinin/github-markdown-toc.go

Tất cả issue của ekalinin/github-markdown-toc.go

Issue tương tự

Thêm issue về Go

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.