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
55
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.6k
WYSIWYG ルビ入力の概要と Chromium のバグを修正した話
karintou8710
0
390
RTE ライブラリの仕組みとそれを支えるブラウザ機能
karintou8710
0
890
Sample
karintou8710
0
340
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Skip the Path - Find Your Career Trail
mkilby
1
290
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
48k
GraphQLとの向き合い方2022年版
quramy
50
15k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
430
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Product Roadmaps are Hard
iamctodd
55
13k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
We Have a Design System, Now What?
morganepeng
55
8.4k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
670
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