COPY ボタンまわりの pre の扱いを統一する#229
Merged
Merged
Conversation
rurema#221 で素の pre にも COPY ボタンが付くようになったのを踏まえた一貫性の 改善をまとめて行う。 - pre の上 padding を highlight の有無によらず 0 に統一。素の pre で COPY ボタンの上に padding 分(1.1em)の隙間が見えていたのを解消し、 pre.highlight の重複プロパティも整理する - RUN の実行結果(highlight__run-output)にも COPY ボタンを付ける。 script.js に公開フック window.ruremaAddCopyButton を切り出し、 run.js が出力 pre の生成時に呼ぶ。出力は実行のたびに変わるので コピーするテキストはクリック時に取得する - caption を pre 内の absolute 配置から「pre の上に密着したタブ」に変更 (rd/md 両コンパイラの出力順を caption→pre に)。pre 内配置のままだと RUN で編集可能にしたときに貼り付けた先頭行と caption が重なる - RUN で編集可能にする時点でハイライトの span をプレーンテキスト化する。 編集・貼り付けで span に文字が食い込み、その場の色を引き継いで 中途半端に色が崩れるため Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
解決したい問題
#221 で素の
<pre>にも COPY ボタンが付くようになったことを踏まえた一貫性の改善4点です。
<pre>では COPY ボタンの上に隙間が見える(例: https://docs.ruby-lang.org/ja/3.2/class/ARGF=2eclass.html 。
preは上 padding 1.1em、pre.highlightは 0 のため)変更内容
<pre>の先頭行に入る前提の見た目に一本化。
pre.highlightの重複プロパティ(line-height / background /padding / font-weight)も整理
window.ruremaAddCopyButton(elem, getText)を切り出し、run.js が出力<pre>の生成時に呼びます。出力は実行のたびに変わるため、コピーするテキストはクリック時に取得します(出力本文は専用のテキストノードに
持たせ、ボタンを消さずに書き換え)
<span class="caption">を pre 内の absolute 配置から「pre の上に密着したタブ」に変更(rd/md 両コンパイラの出力順を
caption→pre に)。pre 内配置のままだと編集時に貼り付けた先頭行と重なります。
caption 用だった
pre.highlight { position: relative }も不要になり削除code.textContent = code.textContentで span を落とし、貼り付け時の色崩れを防ぎます(「とりあえず色を消す」方式。動的な再ハイライトは将来の課題)
互換性
残しているため、キャッシュ等で新旧の HTML/JS が混在しても動作します
プレーンテキストとして pre の前に表示されます
テスト
test/js/test_script.mjsに公開フックのテストを追加(動的コンテンツはクリック時の内容がコピーされること)
等価性テストで担保)
bundle exec rake test:js/ruby test/run_test.rb(17589 tests)全パス🤖 Generated with Claude Code