Skip to content

Commit

Permalink
Allow :not() to nest :not(), :has(), and :is() (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser authored Dec 1, 2018
1 parent e10a8d6 commit f69ea39
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.1.1

- **FIX**: CSS4 allows `:not()`, `:has()`, and `:is()` to be nested in `:not()`.

## 2.1.0

- **NEW**: Add support for `div p`, `div>p`, `div+p`, `div~p` in the HTML/XML filter's CSS selectors. (#51)
Expand Down
3 changes: 0 additions & 3 deletions docs/src/markdown/filters/html.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ Selector | Example | Description
!!! warning ":has()"
`:has()` implementation is experimental and may change. There are currently no reference implementation available in any browsers, not to mention the CSS4 specifications have not been finalized, so current implementation is based on our best interpretation.

!!! note ":not()"
While you can nest `:not()` inside of `:is()` or `:has()`, you cannot match `:is()`, `:has()` or `:not()` inside of `:not()`. This is due to a limitation imposed by the CSS4 specification, not a limitation in our implementation.

## Options

Options | Type | Default | Description
Expand Down
3 changes: 0 additions & 3 deletions docs/src/markdown/filters/xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ Selector | Example | Description
!!! warning ":has()"
`:has()` implementation is experimental and may change. There are currently no reference implementation available in any browsers, so current implementation is based on our best interpretation.

!!! note ":not()"
While you can nest `:not()` inside of `:is()`, you cannot match `:is()` or `:not()` inside of `:not()`. This is due to a limitation imposed by the CSS4 specification, not a limitation in our implementation.

## Options

Options | Type | Default | Description
Expand Down
2 changes: 1 addition & 1 deletion pyspelling/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(2, 1, 0, "final")
__version_info__ = Version(2, 1, 1, "final")
__version__ = __version_info__._get_canonical()
2 changes: 0 additions & 2 deletions pyspelling/util/css_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ def parse_pseudo(self, sel, m, has_selector):
def parse_pseudo_open(self, sel, m, has_selector, iselector, is_pseudo):
"""Parse pseudo with opening bracket."""

if is_pseudo and sel.is_not:
raise ValueError("Pseudo-elements cannot be represented by the negation pseudo-class")
sel.selectors.extend(
self.parse_selectors(
iselector,
Expand Down
55 changes: 55 additions & 0 deletions tests/filters/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def setup_fs(self):
</div>
<div class="iiii">iiii
<p class="jjjj">jjjj</p>
<span></span>
</div>
</body>
</body>
Expand Down Expand Up @@ -526,12 +527,66 @@ def test_not_has_list(self):
"""
).format(self.tempdir)
self.mktemp('.html5.yml', config, 'utf-8')
self.assert_spellcheck(
'.html5.yml', [
'aaaa', 'bbbb', 'eeee', 'ffff'
]
)

def test_not_has_list2(self):
"""Test HTML."""

config = self.dedent(
"""
matrix:
- name: html_css
sources:
- '{}/**/*.txt'
aspell:
lang: en
hunspell:
d: en_US
pipeline:
- pyspelling.filters.html:
mode: html5
ignores:
- 'div:not(:has(> .bbbb, .ffff, .jjjj))'
"""
).format(self.tempdir)
self.mktemp('.html5.yml', config, 'utf-8')
self.assert_spellcheck(
'.html5.yml', [
'aaaa', 'bbbb', 'eeee', 'ffff', 'iiii', 'jjjj'
]
)

def test_not_not(self):
"""Test HTML."""

config = self.dedent(
"""
matrix:
- name: html_css
sources:
- '{}/**/*.txt'
aspell:
lang: en
hunspell:
d: en_US
pipeline:
- pyspelling.filters.html:
mode: html5
ignores:
- 'div:not(:not(.aaaa))'
"""
).format(self.tempdir)
self.mktemp('.html5.yml', config, 'utf-8')
self.assert_spellcheck(
'.html5.yml', [
'cccc', 'dddd', 'eeee', 'ffff', 'gggg', 'hhhh', 'iiii', 'jjjj'
]
)


class TestHTML5LIB(util.PluginTestCase):
"""Test HTML plugin with `html5lib`."""
Expand Down

0 comments on commit f69ea39

Please sign in to comment.