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

オープン 初心者向け
#100 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
cli

調査の方向性

パスのプレフィックスは internal/core/toc/renderer.go の Renderer.Render で追加されます。まずその関数と既存のレンダラーテストを読んでください。リンクのプレフィックス内の空白を %20 としてエンコードし、その後、空白のない入力とエラーメッセージの出力が現在のままであることを確認してください。issue の再現例が期待される TOC を示しています。

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
Go
スター
525
フォーク
89
平均マージ
6分
マージ済み PR(30日)
1

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ekalinin/github-markdown-toc.go のほかの issue

ekalinin/github-markdown-toc.go の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。