html使用的注释标记为,注释/标记HTML标记的任意部分

本文探讨如何在HTML中有效标记跨越段落的文本,避免生成无效代码并保持DOM结构完整。提出了一种可能的语义方法,同时关注通过DOM/JS API查询数据时的挑战与最佳实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tackling the problem of annotating HTML markup and storing marks in the markup itself, the element came across as a tentative solution. Marking inline:

The fox jumped over the lazy dog.

I want to extend this idea towards marking (highlighting) arbitrary pieces of text in the document. Unfortunately, following this approach to mark, say, across paragraphs, would generate invalid HTML ( expects phrasing content) and possibly break the DOM hierarchy:

Red Green Blue.

Magenta, Cyan,

Black

Although a smart parser might translate the above into:

Red Green Blue.

Magenta, Cyan, Black

it doesn't preserve the fact there was a single mark spanning a paragraph and a fragment of a second paragraph, not two marks!

What is the best, possibly semantic way of doing this without breaking the DOM hierarchy? I seek to query this data through DOM/JS APIs.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值