xhtml2pdf icon indicating copy to clipboard operation
xhtml2pdf copied to clipboard

Add support for `:not()` CSS selector

Open VamsidharMuggulla opened this issue 7 years ago • 2 comments

Example:

:not(p) {
    background: #ff0000;
}

CSSParseError: Selector Pseudo Function closing ')' not found:: (u':not(', u'[controls]){display:') It looks like it is unable to parse "not" css selector.

VamsidharMuggulla avatar Aug 28 '17 09:08 VamsidharMuggulla

I receive this error when trying to convert an RMarkdown HTML file to PDF.

Steps to Reproduce

test.Rmd:

This is an RMarkdown file.

Convert to HTML with RMarkdown version 2.3 in R:

library(rmarkdown)
render("test.Rmd", output_file = "test.html")

Then run xhtml2pdf3 test.html in the Bash and I get this error:

Converting test.html to /workspace/test.pdf...
Traceback (most recent call last):
  File "/usr/bin/xhtml2pdf3", line 11, in <module>
    load_entry_point('xhtml2pdf==0.2.2', 'console_scripts', 'xhtml2pdf')()
  File "/usr/lib/python3/dist-packages/xhtml2pdf/pisa.py", line 167, in command
    execute()
  File "/usr/lib/python3/dist-packages/xhtml2pdf/pisa.py", line 392, in execute
    xml_output=xml_output
  File "/usr/lib/python3/dist-packages/xhtml2pdf/document.py", line 97, in pisaDocument
    encoding, context=context, xml_output=xml_output)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/document.py", line 59, in pisaStory
    pisaParser(src, context, default_css, xhtml, encoding, xml_output)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/parser.py", line 753, in pisaParser
    context.parseCSS()
  File "/usr/lib/python3/dist-packages/xhtml2pdf/context.py", line 500, in parseCSS
    self.css = self.cssParser.parse(self.cssText)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 450, in parse
    src, stylesheet = self._parseStylesheet(src)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 557, in _parseStylesheet
    src, ruleset = self._parseRuleset(src)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 852, in _parseRuleset
    src, selectors = self._parseSelectorGroup(src)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 863, in _parseSelectorGroup
    src, selector = self._parseSelector(src)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 877, in _parseSelector
    src, selector = self._parseSimpleSelector(src)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 931, in _parseSimpleSelector
    src, selector = self._parseSelectorPseudo(src, selector)
  File "/usr/lib/python3/dist-packages/xhtml2pdf/w3c/cssParser.py", line 1006, in _parseSelectorPseudo
    raise self.ParseError('Selector Pseudo Function closing \')\' not found', src, ctxsrc)
xhtml2pdf.w3c.cssParser.CSSParseError: Selector Pseudo Function closing ')' not found:: (':not(', '[controls]){display:')
  • xhtml2pdf3 version = 0.2.2
  • Operating system: Debian Buster in Docker (debian:buster-20201012-slim)

wtraylor avatar Nov 19 '20 15:11 wtraylor

Issue appears to be in w3c/cssParser.py at line 1078:

 if not src.startswith(")"):
            msg = "Selector Pseudo Function closing ')' not found"

Shouldn't it beif not src.endswith(")"):?

cpilko avatar Jun 27 '24 23:06 cpilko