dom-select.el: 基于 dom.el 实现的 CSS 风格选择器

看起来相当完善啊,为啥我没有早发现它。

完善度比较(:triangular_flag_on_post:表示得分):

Name esxml-query dom-select Syntax
Namespaces No No foo
Commas Yes🚩 No foo,bar
Descendant combinator Yes Yes foo bar
Child combinator Yes Yes foo>bar
Parent combinator No Yes🚩 foo<bar
Adjacent sibling combinator No Yes🚩 foo+bar
General sibling combinator No Yes🚩 foo~bar
Universal selector Yes🚩 No *
Type selector Yes Yes tag
ID selector Yes Yes #foo
Class selector Yes Yes .foo
Attribute selector Yes Yes [foo]
Exact match attribute selector Yes Yes [foo=bar]
Prefix match attribute selector Yes Yes [foo^=bar]
Suffix match attribute selector Yes Yes [foo$=bar]
Substring match attribute selector Yes Yes [foo*=bar]
Include match attribute selector Yes Yes [foo~=bar]
Dash match attribute selector Yes Yes [foo
Attribute selector modifiers No No [foo=bar i]
Pseudo elements No No ::foo
Pseudo classes No No :foo

(其中 Parent combinator 并非标准实现,是借用 jQuery :has 选择器的想法。)

这么一比较,让我感觉到少许安慰:暂时看起来没白写。

另外,我对它 `[foo]` 的实现有疑问,例如以下情况就选不到元素了:
(with-temp-buffer
  (insert "<p disabled>disabled element</p>")
  (let ((dom (libxml-parse-xml-region (point-min) (point-max))))
    (esxml-query "[disabled]" dom)))
;; => nil

因为 libxml-parse-xml-region 直接把没有值的 attribute 删掉了。这也是我纠结了很久,最后决定放弃实现 [attr] 的原因。

1 个赞