8

如何分辨页面上的一段 HTML 是富文本编辑器生成的还是直接用 html 的语法书写的?

 2 years ago
source link: https://www.v2ex.com/t/804216
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
如何分辨页面上的一段 HTML 是富文本编辑器生成的还是直接用 html 的语法书写的?

V2EX  ›  JavaScript

如何分辨页面上的一段 HTML 是富文本编辑器生成的还是直接用 html 的语法书写的?

  manyfreebug · 1 天前 · 996 次点击

富文本编辑器能将一段普通文本形成对应的 HTML 标签,有什么特征可以分辨出这段 html 是富文本编辑器生成还是直接用 html 的语法书写的?

例如这张页面框中的这部分,是如何形成的呢: https://developer.mozilla.org/zh-CN/docs/Learn

10 条回复    2021-09-26 13:55:55 +08:00

wzzzx

wzzzx   1 天前   ❤️ 1

为什么要分辨这个?

xiaoming1992

xiaoming1992   1 天前   ❤️ 1

富文本编辑器生成的 `<p>hello</p>` 和 直接用 html 语法书写的 `<p>hello</p>` 有什么区别吗?

shapl

shapl   1 天前   ❤️ 1

看 class 算不?富文本一般没这个。

DoveAz

DoveAz   1 天前 via Android   ❤️ 1

几乎无法分辨

Pastsong

Pastsong   1 天前   ❤️ 1

你点一下最下面的 Edit on GitHub 那就知道是怎么生成的了

manyfreebug

manyfreebug   1 天前

@shapl 有的可以靠 class="markdown_body" class="richtext_body"识别出来,但大部分 html 好像没法分辨

manyfreebug

manyfreebug   1 天前

@Pastsong 这个方法可能可以针对 mdn 的页面,但有没有什么通用的方法可以用在别的网站上呢

Pipecraft

Pipecraft   1 天前   ❤️ 1

富文本编辑器生成的网页代码一般会包含 inline style 代码。有的设置字体大小,颜色的会用到 <font size=` ,<font color=` 这种标签。直接用 html 的语法书写的一般会用 class 设置字体和颜色。

2i2Re2PLMaDnghL

2i2Re2PLMaDnghL   21 小时 24 分钟前   ❤️ 1

你只能通过一些启发式的方法去判断,比如你 #6 说的 class,或者 #8 说的 font,或者 span style (毕竟 html5 好像移除了 font )
至于通用的方法,应当是无解。

rodrick

rodrick   17 小时 12 分钟前

先说说看为啥要分辨 感觉这个需求很特别

关于   ·   帮助文档   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   1158 人在线   最高记录 5497   ·  

创意工作者们的社区

World is powered by solitude

VERSION: 3.9.8.5 · 17ms · UTC 23:08 · PVG 07:08 · LAX 16:08 · JFK 19:08
♥ Do have faith in what you're doing.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK