Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
pタグを跨いだテキストコピーは 改行が2つになる!?
Search
kosakin
August 01, 2026
39
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
pタグを跨いだテキストコピーは 改行が2つになる!?
kosakin
August 01, 2026
More Decks by kosakin
See All by kosakin
WYSIWYG ルビ入力の概要と Chromium のバグを修正した話
karintou8710
0
270
RTE ライブラリの仕組みとそれを支えるブラウザ機能
karintou8710
0
650
Sample
karintou8710
0
310
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
52k
Designing for Timeless Needs
cassininazir
1
440
Darren the Foodie - Storyboard
khoart
PRO
3
3.6k
ラッコキーワード サービス紹介資料
rakko
1
4.3M
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Ruling the World: When Life Gets Gamed
codingconduct
0
300
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
430
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
260
A designer walks into a library…
pauljervisheath
211
24k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Transcript
pタグを跨いだテキストコピーは 改行が2つになる!? 2026.07.27 #雑LT_study 1
自己紹介 所属 サイボウズ株式会社 (26卒) コサキン @kosakin8710 --- 出身:札幌 最近の話:ご飯作るのが面倒で nosh
を試す 開発領域:フロントエンド リッチテキストエディター触ってる 2
コピーと貼り付けをざっくり解説 • ブラウザやアプリで Cmd-C で、テキストをコピーするのは日常的だと思います! • コピーはクリップボードへの書き込みをしている • text/plain, text/html,
image/png など複数種類のデータを同時に持つことが可能 • 例えばブラウザでコピーすると、text/html と text/plain は最低限コピーされる • 貼り付け時はクリップボードから適切なデータ種類を選び、エディタへ挿入される • 例えば <textarea /> は text/plain を優先的にみる 3
divタグを跨ぐタイプの文章をコピペすると。。。 <textarea /> に貼り付ける Cmd-C 4
pタグを跨ぐタイプの文章をコピペすると。。。 <textarea /> に貼り付ける Cmd-C 謎の空行が出力される!! 5
なんで? • まずコピーアルゴリズムの仕様はなく、ブラウザによって実装が異なる • DOM をテキストに出力するアルゴリズムの一つとして、WHATWG が定める innerText がある •
ここで p タグは改行2つであることが明記!!!!!!! • Blink 実装だと、p タグは innerText の仕様に従うとコメントにある • ちなみにコピーアルゴリズム自体は innerText と異なる(????) • 最終的なDOM とレイアウトのハイブリットアルゴリズムを採用している • Gecko ⇨ p タグは改行2つ出力、Webkit ⇨ マージンによって改行を判断 そもそもこの仕様 is 何? ⇨ 段落 = 空行という慣習があり、margin: 1em 0; が UA のスタイルシートに記載 ( 上下 margin を消したのがややこしい要因。。?) 6
p タグの改行を一つにしたい ⇨ 辛い!!!! • ブラウザ側は改行の数を変える API を用意していない • copy
イベントをハックすると、text/html と text/plain の両方を自前実装する必要がある • innerText は見た目通りのテキストを出さない。<br /> や空タグなど、改行周りがややこしい • text/html はスタイルのインライン展開など複雑 • 全てを div にすれば幸せ(本当。。?) 7
ご清聴ありがとうございました 8