脚注参照のホバー/フォーカスで内容をツールチップ表示する機能を追加#676
Open
cm-igarashi-ryosuke wants to merge 15 commits into
Open
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
047d2ad to
c7fbb26
Compare
There was a problem hiding this comment.
Pull request overview
本文中の脚注参照リンク(sup.footnote-ref > a)に対して、ホバー/キーボードフォーカス時に脚注内容を共有ツールチップ要素で表示する機能を追加するPRです。zenn-markdown-html のHTML出力を変えずに、JS/CSS更新のみで既存記事にも適用できる構成になっています。
Changes:
zenn-embed-elementsにイベントデリゲーション方式の脚注ツールチップ実装を追加し、index.tsから初期化zenn-content-cssにツールチップのスタイルを追加し、既存.zncのスタイル継承前提で適用zenn-embed-elementsに Vitest + JSDOM のテスト基盤とユニットテストを追加(サンプル記事も追加)
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | jsdom/vitest 追加に伴う依存関係ロック更新 |
| packages/zenn-embed-elements/vitest.config.ts | Vitest 設定(jsdom環境・テスト探索範囲)を追加 |
| packages/zenn-embed-elements/tsconfig.json | tsc の include を src/ 配下に限定し、テスト等をビルド対象外に |
| packages/zenn-embed-elements/src/index.ts | 脚注ツールチップ初期化を追加 |
| packages/zenn-embed-elements/src/classes/footnote-tooltip.ts | ツールチップ本体(表示/非表示・フォーカス対応・埋め込み置換・位置決め)を新規追加 |
| packages/zenn-embed-elements/package.json | vitest run のテストスクリプトと devDependencies(vitest/jsdom)を追加 |
| packages/zenn-embed-elements/tests/footnote-tooltip.test.ts | ツールチップ挙動のユニットテストを追加 |
| packages/zenn-content-css/src/index.scss | ツールチップスタイルの mixin を読み込み・適用 |
| packages/zenn-content-css/src/_footnote-tooltip.scss | ツールチップの見た目(最大幅/高さ、スクロール、色変数など)を追加 |
| packages/zenn-cli/articles/102-example-footnotes.md | 動作確認用のサンプル記事を追加 |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+90
to
+93
| const id = decodeURIComponent(ref.hash.slice(1)); | ||
| if (!id) return null; | ||
| const item = document.getElementById(id); | ||
| if (!item || !item.classList.contains('footnote-item')) return null; |
Comment on lines
+119
to
+123
| let top = refRect.top - tipRect.height - margin; | ||
| if (top < margin) { | ||
| top = refRect.bottom + margin; | ||
| } | ||
|
|
レビュー指摘対応: - decodeURIComponent が不正なパーセントエンコードで throw しないよう try/catch を追加 - 上下どちらにも収まらない場合にビューポート下端からはみ出さないよう top をクランプ Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment on lines
+30
to
+33
| // znc クラスを付けることで CSS 変数とコンテンツスタイルを継承する | ||
| tooltip.className = 'znc zenn-footnote-tooltip'; | ||
| tooltip.setAttribute('role', 'tooltip'); | ||
| tooltip.hidden = true; |
Comment on lines
33
to
+39
| "eslint": "^10.0.0", | ||
| "eslint-config-prettier": "^10.1.8", | ||
| "jsdom": "^29.1.1", | ||
| "rimraf": "^6.0.1", | ||
| "typescript": "^5.9.3", | ||
| "typescript-eslint": "^8.46.2" | ||
| "typescript-eslint": "^8.46.2", | ||
| "vitest": "^4.0.6" |
Comment on lines
15
to
29
| "scripts": { | ||
| "clean": "rimraf lib", | ||
| "build": "pnpm clean && run-p build:*", | ||
| "build:tsc": "tsc -p .", | ||
| "lint": "run-s lint:*", | ||
| "lint:eslint": "eslint .", | ||
| "lint:prettier": "prettier .", | ||
| "lint-strict": "run-s lint-strict:*", | ||
| "lint-strict:eslint": "eslint . --max-warnings 0", | ||
| "lint-strict:prettier": "prettier --check .", | ||
| "fix": "run-s fix:*", | ||
| "fix:eslint": "eslint . --fix", | ||
| "fix:prettier": "prettier -w .", | ||
| "test": "echo 'no test yet'" | ||
| "test": "vitest run" | ||
| }, |
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.
概要
本文中の脚注参照リンク(
[1]など)にホバーまたはキーボードフォーカスすると、脚注の内容をポップアップ(ツールチップ)で表示します。読者がページ末尾へジャンプせずに脚注を確認できるようにするものです(Wikipedia / GitHub と同等の UX)。実装方式
documentへのイベントデリゲーション + ページに 1 つの共有ツールチップ要素(遅延生成)。zenn-markdown-html の HTML 出力は変更しないため、変換済み・保存済みの既存記事にも JS の更新だけで適用されます(プログレッシブエンハンスメント)。変更内容
zenn-embed-elements
src/classes/footnote-tooltip.ts(新規): ツールチップ本体aria-describedby付与(WAI-ARIA tooltip パターン)matchMedia('(hover: hover)')判定により無効(従来のジャンプ動作を維持).embed-block)はクローンでは機能しない(iframe の高さ設定が listen-embed-event.js の id 照合に依存)ため、リンクに置換:data-contentが URL のもの(linkcard / tweet / github / gist)は元 URL のテキストリンク、それ以外(YouTube / mermaid 等)は脚注へのアンカーtsconfig.jsonの include をsrc/に限定(テストが tsc ビルドに混入しないように)zenn-content-css
src/_footnote-tooltip.scss(新規): ツールチップのスタイル。ルート要素にzncクラスを併用するため、CSS 変数によるダークモード追従と既存コンテンツスタイルの継承が自動で効きますzenn-cli
articles/102-example-footnotes.md(新規): 動作確認用のサンプル記事(各種脚注パターン)テスト
lint-strict・build通過、zenn-markdown-html のスナップショットテスト 217 件に影響なし(HTML 出力不変)動作確認方法
記事「脚注のテスト」(
102-example-footnotes.md)を開き、各[n]にホバー / Tab フォーカスしてください。zenn.dev へ取り込む際の注意
z-index: 9999と zenn.dev 本体のヘッダー等との重なりは本体側で要確認🤖 Generated with Claude Code
2026-06-12.10.50.07.mov