Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting css contents from a local file produces error #25

Open
rushiagr opened this issue Jun 19, 2013 · 2 comments
Open

Extracting css contents from a local file produces error #25

rushiagr opened this issue Jun 19, 2013 · 2 comments

Comments

@rushiagr
Copy link

When I tried to parse an HTML which has a local css file, it generated this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pynliner/__init__.py", line 112, in run
    self._get_styles()
  File "/usr/local/lib/python2.7/dist-packages/pynliner/__init__.py", line 141, in _get_styles
    self._get_external_styles()
  File "/usr/local/lib/python2.7/dist-packages/pynliner/__init__.py", line 164, in _get_external_styles
    url = self.relative_url + url
AttributeError: 'Pynliner' object has no attribute 'relative_url'

Looks like the variable 'relative_url' is not defined when a call from function other than from_url() is made. To be more clear, when one tries to do a Pynliner().from_string(html_string).with_cssString(css_string).run() where the html_string already contains a 'link' to a local stylesheet, it generates this error.

For starters, it might be confusing to see this error. A newbie, in the absence of guiding documentation, might want to pass the stringified css file to the stringified html file, where the html file already contained a link to that css file locally

@rushiagr
Copy link
Author

OK. Now its erring when I do this too:
Pynliner().from_string(all_lines).run()
where all_lines is contains strings of an html file which has links to local stylesheets.

Looks like a minor issue, but an issue nevertheless.

The log:

>>> Pynliner().from_string(all_lines).run()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pynliner/__init__.py", line 112, in run
    self._get_styles()
  File "/usr/local/lib/python2.7/dist-packages/pynliner/__init__.py", line 141, in _get_styles
    self._get_external_styles()
  File "/usr/local/lib/python2.7/dist-packages/pynliner/__init__.py", line 164, in _get_external_styles
    url = self.relative_url + url
AttributeError: 'Pynliner' object has no attribute 'relative_url'

@rennat
Copy link
Owner

rennat commented Jun 19, 2013

You're right. Pynliner doesn't support loading stylesheets from relative urls when the html is passed as a string. This is because it needs to know how to look them up when starting with the relative url.

This issue could be solved by specifying a filesystem root for where to look for referenced files or by registering filenames and file content strings with Pynliner.

I personally don't have time to go after either of those at the moment but I'll accept pull requests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants