Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
pタグを跨いだテキストコピーは 改行が2つになる!?
Search
kosakin
August 01, 2026
53
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
Web で実用的な縦書きエディタは可能か?──現在地と普及に向けて
karintou8710
0
1.5k
WYSIWYG ルビ入力の概要と Chromium のバグを修正した話
karintou8710
0
370
RTE ライブラリの仕組みとそれを支えるブラウザ機能
karintou8710
0
850
Sample
karintou8710
0
340
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
How STYLIGHT went responsive
nonsquared
100
6.3k
First, design no harm
axbom
PRO
2
1.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Fireside Chat
paigeccino
43
4.1k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
We Have a Design System, Now What?
morganepeng
55
8.4k
The browser strikes back
jonoalderson
0
1.8k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
540
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